1 // object.h -- support for an object file for linking in gold -*- C++ -*-
16 // Data to pass from read_symbols() to add_symbols().
18 struct Read_symbols_data
22 // Size of symbol data in bytes.
25 File_view
* symbol_names
;
26 // Size of symbol name data in bytes.
27 off_t symbol_names_size
;
30 // Object is an interface which represents either a 32-bit or a 64-bit
31 // input object. This can be a regular object file (ET_REL) or a
32 // shared object (ET_DYN). The actual instantiations are
33 // Sized_object<32> and Sized_object<64>
38 // NAME is the name of the object as we would report it to the user
39 // (e.g., libfoo.a(bar.o) if this is in an archive. INPUT_FILE is
40 // used to read the file. OFFSET is the offset within the input
41 // file--0 for a .o or .so file, something else for a .a file.
42 Object(const std::string
& name
, Input_file
* input_file
, bool is_dynamic
,
44 : name_(name
), input_file_(input_file
), offset_(offset
),
45 is_dynamic_(is_dynamic
), target_(NULL
)
51 // Return the name of the object as we would report it to the tuser.
54 { return this->name_
; }
56 // Return whether this is a dynamic object.
59 { return this->is_dynamic_
; }
61 // Read the symbol and relocation information.
64 { return this->do_read_symbols(); }
66 // Add symbol information to the global symbol table.
68 add_symbols(Symbol_table
* symtab
, Read_symbols_data rd
)
69 { this->do_add_symbols(symtab
, rd
); }
71 // Return the target structure associated with this object.
74 { return this->target_
; }
76 // Return the sized target structure associated with this object.
77 // This is like the target method but it returns a pointer of
78 // appropriate checked type.
79 template<int size
, bool big_endian
>
80 Sized_target
<size
, big_endian
>*
84 // Read the symbols--implemented by child class.
85 virtual Read_symbols_data
86 do_read_symbols() = 0;
88 // Add symbol information to the global symbol table--implemented by
91 do_add_symbols(Symbol_table
*, Read_symbols_data
) = 0;
96 { return this->input_file_
; }
98 // Get the offset into the file.
101 { return this->offset_
; }
103 // Get a view into the underlying file.
105 get_view(off_t start
, off_t size
);
109 set_target(Target
* target
)
110 { this->target_
= target
; }
112 // Read data from the underlying file.
114 read(off_t start
, off_t size
, void* p
);
116 // Get a lasting view into the underlying file.
118 get_lasting_view(off_t start
, off_t size
);
121 // This class may not be copied.
122 Object(const Object
&);
123 Object
& operator=(const Object
&);
125 // Name of object as printed to use.
127 // For reading the file.
128 Input_file
* input_file_
;
129 // Offset within the file--0 for an object file, non-0 for an
132 // Whether this is a dynamic object.
134 // Target functions--may be NULL if the target is not known.
138 // Implement sized_target inline for efficiency. This approach breaks
139 // static type checking, but is made safe using asserts.
141 template<int size
, bool big_endian
>
142 inline Sized_target
<size
, big_endian
>*
143 Object::sized_target()
145 assert(this->target_
->get_size() == size
);
146 assert(this->target_
->is_big_endian() ? big_endian
: !big_endian
);
147 return static_cast<Sized_target
<size
, big_endian
>*>(this->target_
);
150 // A regular object file. This is size and endian specific.
152 template<int size
, bool big_endian
>
153 class Sized_object
: public Object
156 Sized_object(const std::string
& name
, Input_file
* input_file
, off_t offset
,
157 const typename
elfcpp::Ehdr
<size
, big_endian
>&);
162 setup(const typename
elfcpp::Ehdr
<size
, big_endian
>&);
168 do_add_symbols(Symbol_table
*, Read_symbols_data
);
170 Sized_target
<size
, big_endian
>*
172 { return this->Object::sized_target
<size
, big_endian
>(); }
175 // This object may not be copied.
176 Sized_object(const Sized_object
&);
177 Sized_object
& operator=(const Sized_object
&);
179 // ELF file header EI_OSABI field.
180 unsigned char osabi_
;
181 // ELF file header EI_ABIVERSION field.
182 unsigned char abiversion_
;
183 // ELF file header e_machine field.
184 elfcpp::Elf_Half machine_
;
185 // ELF file header e_flags field.
187 // File offset of section header table.
189 // Number of input sections.
191 // Offset of SHT_STRTAB section holding section names.
192 unsigned int shstrndx_
;
193 // Index of SHT_SYMTAB section.
194 unsigned int symtab_shnum_
;
195 // The entries in the symbol table for the external symbols.
199 // Return an Object appropriate for the input file. P is BYTES long,
200 // and holds the ELF header.
202 extern Object
* make_elf_object(const std::string
& name
, Input_file
*,
203 off_t offset
, const unsigned char* p
,
206 } // end namespace gold
208 #endif // !defined(GOLD_OBJECT_H)