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
;
79 // Get a view into the underlying file.
81 get_view(off_t start
, off_t size
, off_t
* pbytes
= NULL
)
82 { return this->input_file_
->file().get_view(start
, size
, pbytes
); }
84 // Read the archive symbol map.
86 read_armap(off_t start
, off_t size
);
88 // Read an archive member header at OFF. Return the size of the
89 // member, and set *PNAME to the name.
91 read_header(off_t off
, std::string
* pname
);
93 // Interpret an archive header HDR at OFF. Return the size of the
94 // member, and set *PNAME to the name.
96 interpret_header(const Archive_header
* hdr
, off_t off
, std::string
* pname
);
98 // Include all the archive members in the link.
100 include_all_members(Symbol_table
*, Layout
*, Input_objects
*);
102 // Include an archive member in the link.
104 include_member(Symbol_table
*, Layout
*, Input_objects
*, off_t off
);
106 // An entry in the archive map of symbols to object files.
111 // The offset to the file.
115 // A simple hash code for off_t values.
119 size_t operator()(off_t val
) const
120 { return static_cast<size_t>(val
); }
123 // Name of object as printed to user.
125 // For reading the file.
126 Input_file
* input_file_
;
128 std::vector
<Armap_entry
> armap_
;
129 // The extended name table.
130 std::string extended_names_
;
131 // Track which symbols in the archive map are for elements which are
132 // defined or which have already been included in the link.
133 std::vector
<bool> armap_checked_
;
134 // Track which elements have been included by offset.
135 Unordered_set
<off_t
, Seen_hash
> seen_offsets_
;
138 // This class is used to read an archive and pick out the desired
139 // elements and add them to the link.
141 class Add_archive_symbols
: public Task
144 Add_archive_symbols(Symbol_table
* symtab
, Layout
* layout
,
145 Input_objects
* input_objects
,
146 Archive
* archive
, Input_group
* input_group
,
147 Task_token
* this_blocker
,
148 Task_token
* next_blocker
)
149 : symtab_(symtab
), layout_(layout
), input_objects_(input_objects
),
150 archive_(archive
), input_group_(input_group
),
151 this_blocker_(this_blocker
), next_blocker_(next_blocker
)
154 ~Add_archive_symbols();
156 // The standard Task methods.
159 is_runnable(Workqueue
*);
168 class Add_archive_symbols_locker
;
170 Symbol_table
* symtab_
;
172 Input_objects
* input_objects_
;
174 Input_group
* input_group_
;
175 Task_token
* this_blocker_
;
176 Task_token
* next_blocker_
;
179 } // End namespace gold.
181 #endif // !defined(GOLD_ARCHIVE_H)