1 // archive.h -- archive support for gold -*- C++ -*-
20 // This class represents an archive--generally a libNAME.a file.
21 // Archives have a symbol table and a list of objects.
26 Archive(const std::string
& name
, Input_file
* input_file
)
27 : name_(name
), input_file_(input_file
), armap_(), extended_names_()
30 // The length of the magic string at the start of an archive.
31 static const int sarmag
= 8;
33 // The magic string at the start of an archive.
34 static const char armag
[sarmag
];
36 // The string expected at the end of an archive member header.
37 static const char arfmag
[2];
39 // The name of the object.
42 { return this->name_
; }
44 // Set up the archive: read the symbol map.
48 // Get a reference to the underlying file.
51 { return this->input_file_
->file(); }
53 // Lock the underlying file.
56 { this->input_file_
->file().lock(); }
58 // Unlock the underlying file.
61 { this->input_file_
->file().unlock(); }
63 // Return whether the underlying file is locked.
66 { return this->input_file_
->file().is_locked(); }
68 // Select members from the archive as needed and add them to the
71 add_symbols(Symbol_table
*, Layout
*, Input_objects
*);
74 Archive(const Archive
&);
75 Archive
& operator=(const Archive
&);
77 struct Archive_header
;
78 class Add_archive_symbols_locker
;
80 // Get a view into the underlying file.
82 get_view(off_t start
, off_t size
)
83 { return this->input_file_
->file().get_view(start
, size
); }
85 // Read an archive member header at OFF. Return the size of the
86 // member, and set *PNAME to the name.
88 read_header(off_t off
, std::string
* pname
);
90 // Include an archive member in the link.
92 include_member(Symbol_table
*, Layout
*, Input_objects
*, off_t off
);
94 // An entry in the archive map of symbols to object files.
99 // The offset to the file.
103 // Name of object as printed to user.
105 // For reading the file.
106 Input_file
* input_file_
;
108 std::vector
<Armap_entry
> armap_
;
109 // The extended name table.
110 std::string extended_names_
;
111 // Track which symbols in the archive map are for elements which
112 // have already been included in the link.
113 std::vector
<bool> seen_
;
116 // This class is used to read an archive and pick out the desired
117 // elements and add them to the link.
119 class Add_archive_symbols
: public Task
122 Add_archive_symbols(Symbol_table
* symtab
, Layout
* layout
,
123 Input_objects
* input_objects
,
124 Archive
* archive
, Input_group
* input_group
,
125 Task_token
* this_blocker
,
126 Task_token
* next_blocker
)
127 : symtab_(symtab
), layout_(layout
), input_objects_(input_objects
),
128 archive_(archive
), input_group_(input_group
),
129 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
132 ~Add_archive_symbols();
134 // The standard Task methods.
137 is_runnable(Workqueue
*);
146 class Add_archive_symbols_locker
;
148 Symbol_table
* symtab_
;
150 Input_objects
* input_objects_
;
152 Input_group
* input_group_
;
153 Task_token
* this_blocker_
;
154 Task_token
* next_blocker_
;
157 } // End namespace gold.
159 #endif // !defined(GOLD_ARCHIVE_H)