public:
Output_section_headers(int size,
bool big_endian,
- const Layout::Segment_list&,
- const Layout::Section_list&,
+ const Layout*,
+ const Layout::Segment_list*,
+ const Layout::Section_list*,
const Stringpool*);
// Write the data to the file.
int size_;
bool big_endian_;
- const Layout::Segment_list& segment_list_;
- const Layout::Section_list& unattached_section_list_;
+ const Layout* layout_;
+ const Layout::Segment_list* segment_list_;
+ const Layout::Section_list* unattached_section_list_;
const Stringpool* secnamepool_;
};
: Output_data(0), output_section_(NULL), addralign_(addralign)
{ }
+ // Return the output section.
+ const Output_section*
+ output_section() const
+ { return this->output_section_; }
+
// Record the output section.
void
- set_output_section(Output_section* os)
- {
- gold_assert(this->output_section_ == NULL);
- this->output_section_ = os;
- }
+ set_output_section(Output_section* os);
protected:
// The child class must implement do_write.
+ // The child class may implement specific adjustments to the output
+ // section.
+ virtual void
+ do_adjust_output_section(Output_section*)
+ { }
+
// Return the required alignment.
uint64_t
do_addralign() const
unsigned int
do_out_shndx() const;
+ // Set the alignment.
+ void
+ set_addralign(uint64_t addralign)
+ { this->addralign_ = addralign; }
+
private:
// The output section for this section.
const Output_section* output_section_;
set_space_size(off_t space_size)
{ this->set_data_size(space_size); }
+ // Set the alignment.
+ void
+ set_space_alignment(uint64_t align)
+ { this->set_addralign(align); }
+
// Write out the data--this must be handled elsewhere.
void
do_write(Output_file*)
{ }
// A reloc against a global symbol.
+
Output_reloc(Symbol* gsym, unsigned int type, Output_data* od,
Address address)
- : local_sym_index_(GSYM_CODE), type_(type), od_(od), address_(address)
- { this->u_.gsym = gsym; }
+ : address_(address), local_sym_index_(GSYM_CODE), type_(type),
+ shndx_(INVALID_CODE)
+ {
+ this->u1_.gsym = gsym;
+ this->u2_.od = od;
+ }
+
+ Output_reloc(Symbol* gsym, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address)
+ : address_(address), local_sym_index_(GSYM_CODE), type_(type),
+ shndx_(shndx)
+ {
+ gold_assert(shndx != INVALID_CODE);
+ this->u1_.gsym = gsym;
+ this->u2_.relobj = relobj;
+ }
// A reloc against a local symbol.
- Output_reloc(Sized_relobj<size, big_endian>* object,
+
+ Output_reloc(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index,
unsigned int type,
Output_data* od,
Address address)
- : local_sym_index_(local_sym_index), type_(type), od_(od),
- address_(address)
+ : address_(address), local_sym_index_(local_sym_index), type_(type),
+ shndx_(INVALID_CODE)
+ {
+ gold_assert(local_sym_index != GSYM_CODE
+ && local_sym_index != INVALID_CODE);
+ this->u1_.relobj = relobj;
+ this->u2_.od = od;
+ }
+
+ Output_reloc(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index,
+ unsigned int type,
+ unsigned int shndx,
+ Address address)
+ : address_(address), local_sym_index_(local_sym_index), type_(type),
+ shndx_(shndx)
{
gold_assert(local_sym_index != GSYM_CODE
&& local_sym_index != INVALID_CODE);
- this->u_.object = object;
+ gold_assert(shndx != INVALID_CODE);
+ this->u1_.relobj = relobj;
+ this->u2_.relobj = relobj;
}
// A reloc against the STT_SECTION symbol of an output section.
+
Output_reloc(Output_section* os, unsigned int type, Output_data* od,
Address address)
- : local_sym_index_(SECTION_CODE), type_(type), od_(od), address_(address)
- { this->u_.os = os; }
+ : address_(address), local_sym_index_(SECTION_CODE), type_(type),
+ shndx_(INVALID_CODE)
+ {
+ this->u1_.os = os;
+ this->u2_.od = od;
+ }
+
+ Output_reloc(Output_section* os, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address)
+ : address_(address), local_sym_index_(SECTION_CODE), type_(type),
+ shndx_(shndx)
+ {
+ gold_assert(shndx != INVALID_CODE);
+ this->u1_.os = os;
+ this->u2_.relobj = relobj;
+ }
// Write the reloc entry to an output view.
void
// relocation against a local symbol in a dynamic object; that
// doesn't make sense. And our callers will always be
// templatized, so we use Sized_relobj here.
- Sized_relobj<size, big_endian>* object;
+ Sized_relobj<size, big_endian>* relobj;
// For a global symbol, the symbol. If this is NULL, it indicates
// a relocation against the undefined 0 symbol.
Symbol* gsym;
// For a relocation against an output section, the output section.
Output_section* os;
- } u_;
+ } u1_;
+ union
+ {
+ // If shndx_ is not INVALID CODE, the object which holds the input
+ // section being used to specify the reloc address.
+ Relobj* relobj;
+ // If shndx_ is INVALID_CODE, the output data being used to
+ // specify the reloc address. This may be NULL if the reloc
+ // address is absolute.
+ Output_data* od;
+ } u2_;
+ // The address offset within the input section or the Output_data.
+ Address address_;
// For a local symbol, the local symbol index. This is GSYM_CODE
// for a global symbol, or INVALID_CODE for an uninitialized value.
unsigned int local_sym_index_;
// The reloc type--a processor specific code.
unsigned int type_;
- // If this is not NULL, then the relocation is against the contents
- // of this output data.
- Output_data* od_;
- // The reloc address--if od_ is not NULL, this is the offset from
- // the start of od_.
- Address address_;
+ // If the reloc address is an input section in an object, the
+ // section index. This is INVALID_CODE if the reloc address is
+ // specified in some other way.
+ unsigned int shndx_;
};
// The SHT_RELA version of Output_reloc<>. This is just derived from
{ }
// A reloc against a global symbol.
+
Output_reloc(Symbol* gsym, unsigned int type, Output_data* od,
Address address, Addend addend)
: rel_(gsym, type, od, address), addend_(addend)
{ }
+ Output_reloc(Symbol* gsym, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address, Addend addend)
+ : rel_(gsym, type, relobj, shndx, address), addend_(addend)
+ { }
+
// A reloc against a local symbol.
- Output_reloc(Sized_relobj<size, big_endian>* object,
+
+ Output_reloc(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index,
unsigned int type, Output_data* od, Address address,
Addend addend)
- : rel_(object, local_sym_index, type, od, address), addend_(addend)
+ : rel_(relobj, local_sym_index, type, od, address), addend_(addend)
+ { }
+
+ Output_reloc(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index,
+ unsigned int type,
+ unsigned int shndx,
+ Address address,
+ Addend addend)
+ : rel_(relobj, local_sym_index, type, shndx, address),
+ addend_(addend)
{ }
// A reloc against the STT_SECTION symbol of an output section.
+
Output_reloc(Output_section* os, unsigned int type, Output_data* od,
Address address, Addend addend)
: rel_(os, type, od, address), addend_(addend)
{ }
+ Output_reloc(Output_section* os, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address, Addend addend)
+ : rel_(os, type, relobj, shndx, address), addend_(addend)
+ { }
+
// Write the reloc entry to an output view.
void
write(unsigned char* pov) const;
do_write(Output_file*);
protected:
+ // Set the entry size and the link.
+ void
+ do_adjust_output_section(Output_section *os);
+
// Add a relocation entry.
void
add(const Output_reloc_type& reloc)
{ }
// Add a reloc against a global symbol.
+
void
add_global(Symbol* gsym, unsigned int type, Output_data* od, Address address)
{ this->add(Output_reloc_type(gsym, type, od, address)); }
+ void
+ add_global(Symbol* gsym, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address)
+ { this->add(Output_reloc_type(gsym, type, relobj, shndx, address)); }
+
// Add a reloc against a local symbol.
+
void
- add_local(Sized_relobj<size, big_endian>* object,
+ add_local(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index, unsigned int type,
Output_data* od, Address address)
- { this->add(Output_reloc_type(object, local_sym_index, type, od, address)); }
+ { this->add(Output_reloc_type(relobj, local_sym_index, type, od, address)); }
+
+ void
+ add_local(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index, unsigned int type,
+ unsigned int shndx, Address address)
+ { this->add(Output_reloc_type(relobj, local_sym_index, type, shndx,
+ address)); }
+
// A reloc against the STT_SECTION symbol of an output section.
+
void
add_output_section(Output_section* os, unsigned int type,
Output_data* od, Address address)
{ this->add(Output_reloc_type(os, type, od, address)); }
+
+ void
+ add_output_section(Output_section* os, unsigned int type,
+ Relobj* relobj, unsigned int shndx, Address address)
+ { this->add(Output_reloc_type(os, type, relobj, shndx, address)); }
};
// The SHT_RELA version of Output_data_reloc.
{ }
// Add a reloc against a global symbol.
+
void
add_global(Symbol* gsym, unsigned int type, Output_data* od,
Address address, Addend addend)
{ this->add(Output_reloc_type(gsym, type, od, address, addend)); }
+ void
+ add_global(Symbol* gsym, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address, Addend addend)
+ { this->add(Output_reloc_type(gsym, type, relobj, shndx, address, addend)); }
+
// Add a reloc against a local symbol.
+
void
- add_local(Sized_relobj<size, big_endian>* object,
+ add_local(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index, unsigned int type,
Output_data* od, Address address, Addend addend)
{
- this->add(Output_reloc_type(object, local_sym_index, type, od, address,
+ this->add(Output_reloc_type(relobj, local_sym_index, type, od, address,
+ addend));
+ }
+
+ void
+ add_local(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index, unsigned int type,
+ unsigned int shndx, Address address, Addend addend)
+ {
+ this->add(Output_reloc_type(relobj, local_sym_index, type, shndx, address,
addend));
}
// A reloc against the STT_SECTION symbol of an output section.
+
void
add_output_section(Output_section* os, unsigned int type, Output_data* od,
Address address, Addend addend)
{ this->add(Output_reloc_type(os, type, od, address, addend)); }
+
+ void
+ add_output_section(Output_section* os, unsigned int type, Relobj* relobj,
+ unsigned int shndx, Address address, Addend addend)
+ { this->add(Output_reloc_type(os, type, relobj, shndx, address, addend)); }
};
// Output_data_got is used to manage a GOT. Each entry in the GOT is
add_constant(elfcpp::DT tag, unsigned int val)
{ this->add_entry(Dynamic_entry(tag, val)); }
- // Add a new dynamic entry with the address of a section.
+ // Add a new dynamic entry with the address of output data.
void
- add_section_address(elfcpp::DT tag, Output_section* os)
- { this->add_entry(Dynamic_entry(tag, os, false)); }
+ add_section_address(elfcpp::DT tag, const Output_data* od)
+ { this->add_entry(Dynamic_entry(tag, od, false)); }
- // Add a new dynamic entry with the size of a section.
+ // Add a new dynamic entry with the size of output data.
void
- add_section_size(elfcpp::DT tag, Output_section* os)
- { this->add_entry(Dynamic_entry(tag, os, true)); }
+ add_section_size(elfcpp::DT tag, const Output_data* od)
+ { this->add_entry(Dynamic_entry(tag, od, true)); }
// Add a new dynamic entry with the address of a symbol.
void
- add_symbol(elfcpp::DT tag, Symbol* sym)
+ add_symbol(elfcpp::DT tag, const Symbol* sym)
{ this->add_entry(Dynamic_entry(tag, sym)); }
// Add a new dynamic entry with a string.
void
do_write(Output_file*);
+ protected:
+ // Adjust the output section to set the entry size.
+ void
+ do_adjust_output_section(Output_section*);
+
private:
// This POD class holds a single dynamic entry.
class Dynamic_entry
{ this->u_.val = val; }
// Create an entry with the size or address of a section.
- Dynamic_entry(elfcpp::DT tag, Output_section* os, bool section_size)
+ Dynamic_entry(elfcpp::DT tag, const Output_data* od, bool section_size)
: tag_(tag),
classification_(section_size
? DYNAMIC_SECTION_SIZE
: DYNAMIC_SECTION_ADDRESS)
- { this->u_.os = os; }
+ { this->u_.od = od; }
// Create an entry with the address of a symbol.
- Dynamic_entry(elfcpp::DT tag, Symbol* sym)
+ Dynamic_entry(elfcpp::DT tag, const Symbol* sym)
: tag_(tag), classification_(DYNAMIC_SYMBOL)
{ this->u_.sym = sym; }
// Write the dynamic entry to an output view.
template<int size, bool big_endian>
void
- write(unsigned char* pov, const Stringpool*) const;
+ write(unsigned char* pov, const Stringpool* ACCEPT_SIZE_ENDIAN) const;
private:
enum Classification
// For DYNAMIC_NUMBER.
unsigned int val;
// For DYNAMIC_SECTION_ADDRESS and DYNAMIC_SECTION_SIZE.
- Output_section* os;
+ const Output_data* od;
// For DYNAMIC_SYMBOL.
- Symbol* sym;
+ const Symbol* sym;
// For DYNAMIC_STRING.
const char* str;
} u_;
// Set the entsize field.
void
- set_entsize(uint64_t v)
- { this->entsize_ = v; }
+ set_entsize(uint64_t v);
- // Set the link field.
+ // Set the link field to the output section index of a section.
+ void
+ set_link_section(const Output_data* od)
+ {
+ gold_assert(this->link_ == 0
+ && !this->should_link_to_symtab_
+ && !this->should_link_to_dynsym_);
+ this->link_section_ = od;
+ }
+
+ // Set the link field to a constant.
void
set_link(unsigned int v)
- { this->link_ = v; }
+ {
+ gold_assert(this->link_section_ == NULL
+ && !this->should_link_to_symtab_
+ && !this->should_link_to_dynsym_);
+ this->link_ = v;
+ }
- // Set the info field.
+ // Record that this section should link to the normal symbol table.
+ void
+ set_should_link_to_symtab()
+ {
+ gold_assert(this->link_section_ == NULL
+ && this->link_ == 0
+ && !this->should_link_to_dynsym_);
+ this->should_link_to_symtab_ = true;
+ }
+
+ // Record that this section should link to the dynamic symbol table.
+ void
+ set_should_link_to_dynsym()
+ {
+ gold_assert(this->link_section_ == NULL
+ && this->link_ == 0
+ && !this->should_link_to_symtab_);
+ this->should_link_to_dynsym_ = true;
+ }
+
+ // Return the info field.
+ unsigned int
+ info() const
+ {
+ gold_assert(this->info_section_ == NULL);
+ return this->info_;
+ }
+
+ // Set the info field to the output section index of a section.
+ void
+ set_info_section(const Output_data* od)
+ {
+ gold_assert(this->info_ == 0);
+ this->info_section_ = od;
+ }
+
+ // Set the info field to a constant.
void
set_info(unsigned int v)
- { this->info_ = v; }
+ {
+ gold_assert(this->info_section_ == NULL);
+ this->info_ = v;
+ }
// Set the addralign field.
void
// Write the section header into *OPHDR.
template<int size, bool big_endian>
void
- write_header(const Stringpool*, elfcpp::Shdr_write<size, big_endian>*) const;
+ write_header(const Layout*, const Stringpool*,
+ elfcpp::Shdr_write<size, big_endian>*) const;
private:
// In some cases we need to keep a list of the input sections
// The section entry size.
uint64_t entsize_;
// The file offset is in the parent class.
- // The section link field.
+ // Set the section link field to the index of this section.
+ const Output_data* link_section_;
+ // If link_section_ is NULL, this is the link field.
unsigned int link_;
- // The section info field.
+ // Set the section info field to the index of this section.
+ const Output_data* info_section_;
+ // If info_section_ is NULL, this is the section info field.
unsigned int info_;
// The section type.
elfcpp::Elf_Word type_;
// dynamic symbol table. This will be true if there is a dynamic
// relocation which needs it.
bool needs_dynsym_index_ : 1;
+ // Whether the link field of this output section should point to the
+ // normal symbol table.
+ bool should_link_to_symtab_ : 1;
+ // Whether the link field of this output section should point to the
+ // dynamic symbol table.
+ bool should_link_to_dynsym_ : 1;
};
// An output segment. PT_LOAD segments are built from collections of
// Write the section headers of associated sections into V.
template<int size, bool big_endian>
unsigned char*
- write_section_headers(const Stringpool*,
- unsigned char* v,
+ write_section_headers(const Layout*, const Stringpool*, unsigned char* v,
unsigned int* pshndx ACCEPT_SIZE_ENDIAN) const;
private:
// Write the section headers in the list into V.
template<int size, bool big_endian>
unsigned char*
- write_section_headers_list(const Stringpool*, const Output_data_list*,
- unsigned char* v,
+ write_section_headers_list(const Layout*, const Stringpool*,
+ const Output_data_list*, unsigned char* v,
unsigned int* pshdx ACCEPT_SIZE_ENDIAN) const;
// The list of output data with contents attached to this segment.