* config/tc-m68k.c (md_apply_fix): Show value of out of range
[binutils.git] / gold / archive.h
blob193a9e2de8203e00a9e94bc0457a62e13685cb43
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 General_options;
15 class Input_file;
16 class Input_objects;
17 class Input_group;
18 class Layout;
19 class Symbol_table;
21 // This class represents an archive--generally a libNAME.a file.
22 // Archives have a symbol table and a list of objects.
24 class Archive
26 public:
27 Archive(const std::string& name, Input_file* input_file)
28 : name_(name), input_file_(input_file), armap_(), extended_names_()
29 { }
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.
41 const std::string&
42 name() const
43 { return this->name_; }
45 // Set up the archive: read the symbol map.
46 void
47 setup();
49 // Get a reference to the underlying file.
50 File_read&
51 file()
52 { return this->input_file_->file(); }
54 // Lock the underlying file.
55 void
56 lock()
57 { this->input_file_->file().lock(); }
59 // Unlock the underlying file.
60 void
61 unlock()
62 { this->input_file_->file().unlock(); }
64 // Return whether the underlying file is locked.
65 bool
66 is_locked() const
67 { return this->input_file_->file().is_locked(); }
69 // Select members from the archive as needed and add them to the
70 // link.
71 void
72 add_symbols(const General_options&, Symbol_table*, Layout*, Input_objects*);
74 private:
75 Archive(const Archive&);
76 Archive& operator=(const Archive&);
78 struct Archive_header;
80 // Get a view into the underlying file.
81 const unsigned char*
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.
87 off_t
88 read_header(off_t off, std::string* pname);
90 // Include an archive member in the link.
91 void
92 include_member(const General_options&, Symbol_table*, Layout*,
93 Input_objects*, off_t off);
95 // An entry in the archive map of symbols to object files.
96 struct Armap_entry
98 // The symbol name.
99 const char* name;
100 // The offset to the file.
101 off_t offset;
104 // Name of object as printed to user.
105 std::string name_;
106 // For reading the file.
107 Input_file* input_file_;
108 // The archive map.
109 std::vector<Armap_entry> armap_;
110 // The extended name table.
111 std::string extended_names_;
112 // Track which symbols in the archive map are for elements which
113 // have already been included in the link.
114 std::vector<bool> seen_;
117 // This class is used to read an archive and pick out the desired
118 // elements and add them to the link.
120 class Add_archive_symbols : public Task
122 public:
123 Add_archive_symbols(const General_options& options, Symbol_table* symtab,
124 Layout* layout, Input_objects* input_objects,
125 Archive* archive, Input_group* input_group,
126 Task_token* this_blocker,
127 Task_token* next_blocker)
128 : options_(options), symtab_(symtab), layout_(layout),
129 input_objects_(input_objects), archive_(archive),
130 input_group_(input_group), this_blocker_(this_blocker),
131 next_blocker_(next_blocker)
134 ~Add_archive_symbols();
136 // The standard Task methods.
138 Is_runnable_type
139 is_runnable(Workqueue*);
141 Task_locker*
142 locks(Workqueue*);
144 void
145 run(Workqueue*);
147 private:
148 class Add_archive_symbols_locker;
150 const General_options& options_;
151 Symbol_table* symtab_;
152 Layout* layout_;
153 Input_objects* input_objects_;
154 Archive* archive_;
155 Input_group* input_group_;
156 Task_token* this_blocker_;
157 Task_token* next_blocker_;
160 } // End namespace gold.
162 #endif // !defined(GOLD_ARCHIVE_H)