2006-10-26 Joseph S. Myers <joseph@codesourcery.com>
[binutils.git] / gold / archive.h
blobb2d4c46550fad135667abf0a5ccfc58be4760212
1 // archive.h -- archive support for gold -*- C++ -*-
3 #ifndef GOLD_ARCHIVE_H
4 #define GOLD_ARCHIVE_H
6 #include <string>
7 #include <vector>
9 #include "workqueue.h"
11 namespace gold
14 class Input_file;
15 class Input_objects;
16 class Layout;
17 class Symbol_table;
19 // This class represents an archive--generally a libNAME.a file.
20 // Archives have a symbol table and a list of objects.
22 class Archive
24 public:
25 Archive(const std::string& name, Input_file* input_file)
26 : name_(name), input_file_(input_file), armap_(), extended_names_()
27 { }
29 // The length of the magic string at the start of an archive.
30 static const int sarmag = 8;
32 // The magic string at the start of an archive.
33 static const char armag[sarmag];
35 // The string expected at the end of an archive member header.
36 static const char arfmag[2];
38 // The name of the object.
39 const std::string&
40 name() const
41 { return this->name_; }
43 // Set up the archive: read the symbol map.
44 void
45 setup();
47 // Lock the underlying file.
48 void
49 lock()
50 { this->input_file_->file().lock(); }
52 // Unlock the underlying file.
53 void
54 unlock()
55 { this->input_file_->file().unlock(); }
57 // Return whether the underlying file is locked.
58 bool
59 is_locked() const
60 { return this->input_file_->file().is_locked(); }
62 // Select members from the archive as needed and add them to the
63 // link.
64 void
65 add_symbols(Symbol_table*, Layout*, Input_objects*);
67 private:
68 Archive(const Archive&);
69 Archive& operator=(const Archive&);
71 struct Archive_header;
72 class Add_archive_symbols_locker;
74 // Get a view into the underlying file.
75 const unsigned char*
76 get_view(off_t start, off_t size);
78 // Read an archive member header at OFF. Return the size of the
79 // member, and set *PNAME to the name.
80 off_t
81 read_header(off_t off, std::string* pname);
83 // Include an archive member in the link.
84 void
85 include_member(Symbol_table*, Layout*, Input_objects*, off_t off);
87 // An entry in the archive map of symbols to object files.
88 struct Armap_entry
90 // The symbol name.
91 const char* name;
92 // The offset to the file.
93 off_t offset;
96 // Name of object as printed to user.
97 std::string name_;
98 // For reading the file.
99 Input_file* input_file_;
100 // The archive map.
101 std::vector<Armap_entry> armap_;
102 // The extended name table.
103 std::string extended_names_;
106 // This class is used to read an archive and pick out the desired
107 // elements and add them to the link.
109 class Add_archive_symbols : public Task
111 public:
112 Add_archive_symbols(Symbol_table* symtab, Layout* layout,
113 Input_objects* input_objects,
114 Archive* archive, Task_token* this_blocker,
115 Task_token* next_blocker)
116 : symtab_(symtab), layout_(layout), input_objects_(input_objects),
117 archive_(archive), this_blocker_(this_blocker),
118 next_blocker_(next_blocker)
121 ~Add_archive_symbols();
123 // The standard Task methods.
125 Is_runnable_type
126 is_runnable(Workqueue*);
128 Task_locker*
129 locks(Workqueue*);
131 void
132 run(Workqueue*);
134 private:
135 class Add_archive_symbols_locker;
137 Symbol_table* symtab_;
138 Layout* layout_;
139 Input_objects* input_objects_;
140 Archive* archive_;
141 Task_token* this_blocker_;
142 Task_token* next_blocker_;
145 } // End namespace gold.
147 #endif // !defined(GOLD_ARCHIVE_H)