1 // archive.h -- archive support for gold -*- C++ -*-
14 class General_options
;
21 // This class represents an archive--generally a libNAME.a file.
22 // Archives have a symbol table and a list of objects.
27 Archive(const std::string
& name
, Input_file
* input_file
)
28 : name_(name
), input_file_(input_file
), armap_(), extended_names_()
31 // The length of the magic string at the start of an archive.
32 static const int sarmag
= 8;
34 // The magic string at the start of an archive.
35 static const char armag
[sarmag
];
37 // The string expected at the end of an archive member header.
38 static const char arfmag
[2];
40 // The name of the object.
43 { return this->name_
; }
45 // Set up the archive: read the symbol map.
49 // Get a reference to the underlying file.
52 { return this->input_file_
->file(); }
54 // Lock the underlying file.
57 { this->input_file_
->file().lock(); }
59 // Unlock the underlying file.
62 { this->input_file_
->file().unlock(); }
64 // Return whether the underlying file is locked.
67 { return this->input_file_
->file().is_locked(); }
69 // Select members from the archive as needed and add them to the
72 add_symbols(const General_options
&, Symbol_table
*, Layout
*, Input_objects
*);
75 Archive(const Archive
&);
76 Archive
& operator=(const Archive
&);
78 struct Archive_header
;
80 // Get a view into the underlying file.
82 get_view(off_t start
, off_t size
, off_t
* pbytes
= NULL
)
83 { return this->input_file_
->file().get_view(start
, size
, pbytes
); }
85 // Read the archive symbol map.
87 read_armap(off_t start
, off_t size
);
89 // Read an archive member header at OFF. Return the size of the
90 // member, and set *PNAME to the name.
92 read_header(off_t off
, std::string
* pname
);
94 // Interpret an archive header HDR at OFF. Return the size of the
95 // member, and set *PNAME to the name.
97 interpret_header(const Archive_header
* hdr
, off_t off
, std::string
* pname
);
99 // Include all the archive members in the link.
101 include_all_members(const General_options
&, Symbol_table
*, Layout
*,
104 // Include an archive member in the link.
106 include_member(const General_options
&, Symbol_table
*, Layout
*,
107 Input_objects
*, off_t off
);
109 // An entry in the archive map of symbols to object files.
114 // The offset to the file.
118 // Name of object as printed to user.
120 // For reading the file.
121 Input_file
* input_file_
;
123 std::vector
<Armap_entry
> armap_
;
124 // The extended name table.
125 std::string extended_names_
;
126 // Track which symbols in the archive map are for elements which
127 // have already been included in the link.
128 std::vector
<bool> seen_
;
131 // This class is used to read an archive and pick out the desired
132 // elements and add them to the link.
134 class Add_archive_symbols
: public Task
137 Add_archive_symbols(const General_options
& options
, Symbol_table
* symtab
,
138 Layout
* layout
, Input_objects
* input_objects
,
139 Archive
* archive
, Input_group
* input_group
,
140 Task_token
* this_blocker
,
141 Task_token
* next_blocker
)
142 : options_(options
), symtab_(symtab
), layout_(layout
),
143 input_objects_(input_objects
), archive_(archive
),
144 input_group_(input_group
), this_blocker_(this_blocker
),
145 next_blocker_(next_blocker
)
148 ~Add_archive_symbols();
150 // The standard Task methods.
153 is_runnable(Workqueue
*);
162 class Add_archive_symbols_locker
;
164 const General_options
& options_
;
165 Symbol_table
* symtab_
;
167 Input_objects
* input_objects_
;
169 Input_group
* input_group_
;
170 Task_token
* this_blocker_
;
171 Task_token
* next_blocker_
;
174 } // End namespace gold.
176 #endif // !defined(GOLD_ARCHIVE_H)