unsigned int type,
Output_data* od,
Address address,
- bool is_relative)
+ bool is_relative,
+ bool is_symbolless)
: address_(address), local_sym_index_(GSYM_CODE), type_(type),
- is_relative_(is_relative), is_section_symbol_(false), shndx_(INVALID_CODE)
+ is_relative_(is_relative), is_symbolless_(is_symbolless),
+ is_section_symbol_(false), shndx_(INVALID_CODE)
{
// this->type_ is a bitfield; make sure TYPE fits.
gold_assert(this->type_ == type);
Sized_relobj<size, big_endian>* relobj,
unsigned int shndx,
Address address,
- bool is_relative)
+ bool is_relative,
+ bool is_symbolless)
: address_(address), local_sym_index_(GSYM_CODE), type_(type),
- is_relative_(is_relative), is_section_symbol_(false), shndx_(shndx)
+ is_relative_(is_relative), is_symbolless_(is_symbolless),
+ is_section_symbol_(false), shndx_(shndx)
{
gold_assert(shndx != INVALID_CODE);
// this->type_ is a bitfield; make sure TYPE fits.
Output_data* od,
Address address,
bool is_relative,
+ bool is_symbolless,
bool is_section_symbol)
: address_(address), local_sym_index_(local_sym_index), type_(type),
- is_relative_(is_relative), is_section_symbol_(is_section_symbol),
- shndx_(INVALID_CODE)
+ is_relative_(is_relative), is_symbolless_(is_symbolless),
+ is_section_symbol_(is_section_symbol), shndx_(INVALID_CODE)
{
gold_assert(local_sym_index != GSYM_CODE
&& local_sym_index != INVALID_CODE);
unsigned int shndx,
Address address,
bool is_relative,
+ bool is_symbolless,
bool is_section_symbol)
: address_(address), local_sym_index_(local_sym_index), type_(type),
- is_relative_(is_relative), is_section_symbol_(is_section_symbol),
- shndx_(shndx)
+ is_relative_(is_relative), is_symbolless_(is_symbolless),
+ is_section_symbol_(is_section_symbol), shndx_(shndx)
{
gold_assert(local_sym_index != GSYM_CODE
&& local_sym_index != INVALID_CODE);
Output_data* od,
Address address)
: address_(address), local_sym_index_(SECTION_CODE), type_(type),
- is_relative_(false), is_section_symbol_(true), shndx_(INVALID_CODE)
+ is_relative_(false), is_symbolless_(false),
+ is_section_symbol_(true), shndx_(INVALID_CODE)
{
// this->type_ is a bitfield; make sure TYPE fits.
gold_assert(this->type_ == type);
unsigned int shndx,
Address address)
: address_(address), local_sym_index_(SECTION_CODE), type_(type),
- is_relative_(false), is_section_symbol_(true), shndx_(shndx)
+ is_relative_(false), is_symbolless_(false),
+ is_section_symbol_(true), shndx_(shndx)
{
gold_assert(shndx != INVALID_CODE);
// this->type_ is a bitfield; make sure TYPE fits.
Output_data* od,
Address address)
: address_(address), local_sym_index_(0), type_(type),
- is_relative_(false), is_section_symbol_(false), shndx_(INVALID_CODE)
+ is_relative_(false), is_symbolless_(false),
+ is_section_symbol_(false), shndx_(INVALID_CODE)
{
// this->type_ is a bitfield; make sure TYPE fits.
gold_assert(this->type_ == type);
unsigned int shndx,
Address address)
: address_(address), local_sym_index_(0), type_(type),
- is_relative_(false), is_section_symbol_(false), shndx_(shndx)
+ is_relative_(false), is_symbolless_(false),
+ is_section_symbol_(false), shndx_(shndx)
{
gold_assert(shndx != INVALID_CODE);
// this->type_ is a bitfield; make sure TYPE fits.
Output_data* od,
Address address)
: address_(address), local_sym_index_(TARGET_CODE), type_(type),
- is_relative_(false), is_section_symbol_(false), shndx_(INVALID_CODE)
+ is_relative_(false), is_symbolless_(false),
+ is_section_symbol_(false), shndx_(INVALID_CODE)
{
// this->type_ is a bitfield; make sure TYPE fits.
gold_assert(this->type_ == type);
unsigned int shndx,
Address address)
: address_(address), local_sym_index_(TARGET_CODE), type_(type),
- is_relative_(false), is_section_symbol_(false), shndx_(shndx)
+ is_relative_(false), is_symbolless_(false),
+ is_section_symbol_(false), shndx_(shndx)
{
gold_assert(shndx != INVALID_CODE);
// this->type_ is a bitfield; make sure TYPE fits.
Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian>::
set_needs_dynsym_index()
{
- if (this->is_relative_)
+ if (this->is_symbolless_)
return;
switch (this->local_sym_index_)
{
const
{
unsigned int index;
+ if (this->is_symbolless_)
+ return 0;
switch (this->local_sym_index_)
{
case INVALID_CODE:
Write_rel* wr) const
{
wr->put_r_offset(this->get_address());
- unsigned int sym_index = this->is_relative_ ? 0 : this->get_symbol_index();
+ unsigned int sym_index = this->get_symbol_index();
wr->put_r_info(elfcpp::elf_r_info<size>(sym_index, this->type_));
}
if (this->rel_.is_target_specific())
addend = parameters->target().reloc_addend(this->rel_.target_arg(),
this->rel_.type(), addend);
- else if (this->rel_.is_relative())
+ else if (this->rel_.is_symbolless())
addend = this->rel_.symbol_value(addend);
else if (this->rel_.is_local_section_symbol())
addend = this->rel_.local_section_offset(addend);
// A reloc against a global symbol.
Output_reloc(Symbol* gsym, unsigned int type, Output_data* od,
- Address address, bool is_relative);
+ Address address, bool is_relative, bool is_symbolless);
Output_reloc(Symbol* gsym, unsigned int type,
Sized_relobj<size, big_endian>* relobj,
- unsigned int shndx, Address address, bool is_relative);
+ unsigned int shndx, Address address, bool is_relative,
+ bool is_symbolless);
// A reloc against a local symbol or local section symbol.
Output_reloc(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index, unsigned int type,
Output_data* od, Address address, bool is_relative,
- bool is_section_symbol);
+ bool is_symbolless, bool is_section_symbol);
Output_reloc(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index, unsigned int type,
unsigned int shndx, Address address, bool is_relative,
- bool is_section_symbol);
+ bool is_symbolless, bool is_section_symbol);
// A reloc against the STT_SECTION symbol of an output section.
is_relative() const
{ return this->is_relative_; }
+ // Return whether this is a relocation which should not use
+ // a symbol, but which obtains its addend from a symbol.
+ bool
+ is_symbolless() const
+ { return this->is_symbolless_; }
+
// Return whether this is against a local section symbol.
bool
is_local_section_symbol() const
// input file.
unsigned int local_sym_index_;
// The reloc type--a processor specific code.
- unsigned int type_ : 30;
+ unsigned int type_ : 29;
// True if the relocation is a RELATIVE relocation.
bool is_relative_ : 1;
+ // True if the relocation is one which should not use
+ // a symbol, but which obtains its addend from a symbol.
+ bool is_symbolless_ : 1;
// True if the relocation is against a section symbol.
bool is_section_symbol_ : 1;
// If the reloc address is an input section in an object, the
// A reloc against a global symbol.
Output_reloc(Symbol* gsym, unsigned int type, Output_data* od,
- Address address, Addend addend, bool is_relative)
- : rel_(gsym, type, od, address, is_relative), addend_(addend)
+ Address address, Addend addend, bool is_relative,
+ bool is_symbolless)
+ : rel_(gsym, type, od, address, is_relative, is_symbolless),
+ addend_(addend)
{ }
Output_reloc(Symbol* gsym, unsigned int type,
Sized_relobj<size, big_endian>* relobj,
unsigned int shndx, Address address, Addend addend,
- bool is_relative)
- : rel_(gsym, type, relobj, shndx, address, is_relative), addend_(addend)
+ bool is_relative, bool is_symbolless)
+ : rel_(gsym, type, relobj, shndx, address, is_relative,
+ is_symbolless), addend_(addend)
{ }
// A reloc against a local symbol.
Output_reloc(Sized_relobj<size, big_endian>* relobj,
unsigned int local_sym_index, unsigned int type,
Output_data* od, Address address,
- Addend addend, bool is_relative, bool is_section_symbol)
+ Addend addend, bool is_relative,
+ bool is_symbolless, bool is_section_symbol)
: rel_(relobj, local_sym_index, type, od, address, is_relative,
- is_section_symbol),
+ is_symbolless, is_section_symbol),
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, bool is_relative, bool is_section_symbol)
+ Addend addend, bool is_relative,
+ bool is_symbolless, bool is_section_symbol)
: rel_(relobj, local_sym_index, type, shndx, address, is_relative,
- is_section_symbol),
+ is_symbolless, is_section_symbol),
addend_(addend)
{ }
is_relative() const
{ return this->rel_.is_relative(); }
+ // Return whether this is a relocation which should not use
+ // a symbol, but which obtains its addend from a symbol.
+ bool
+ is_symbolless() const
+ { return this->rel_.is_symbolless(); }
+
// Write the reloc entry to an output view.
void
write(unsigned char* pov) const;
void
add_global(Symbol* gsym, unsigned int type, Output_data* od, Address address)
- { this->add(od, Output_reloc_type(gsym, type, od, address, false)); }
+ { this->add(od, Output_reloc_type(gsym, type, od, address, false, false)); }
void
add_global(Symbol* gsym, unsigned int type, Output_data* od,
Sized_relobj<size, big_endian>* relobj,
unsigned int shndx, Address address)
{ this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address,
- false)); }
+ false, false)); }
// These are to simplify the Copy_relocs class.
void
add_global_relative(Symbol* gsym, unsigned int type, Output_data* od,
Address address)
- { this->add(od, Output_reloc_type(gsym, type, od, address, true)); }
+ { this->add(od, Output_reloc_type(gsym, type, od, address, true, true)); }
void
add_global_relative(Symbol* gsym, unsigned int type, Output_data* od,
unsigned int shndx, Address address)
{
this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address,
- true));
+ true, true));
+ }
+
+ // Add a global relocation which does not use a symbol for the relocation,
+ // but which gets its addend from a symbol.
+
+ void
+ add_symbolless_global_addend(Symbol* gsym, unsigned int type,
+ Output_data* od, Address address)
+ { this->add(od, Output_reloc_type(gsym, type, od, address, false, true)); }
+
+ void
+ add_symbolless_global_addend(Symbol* gsym, unsigned int type,
+ Output_data* od,
+ Sized_relobj<size, big_endian>* relobj,
+ unsigned int shndx, Address address)
+ {
+ this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address,
+ false, true));
}
// Add a reloc against a local symbol.
Output_data* od, Address address)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, od,
- address, false, false));
+ address, false, false, false));
}
void
Output_data* od, unsigned int shndx, Address address)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx,
- address, false, false));
+ address, false, false, false));
}
// Add a RELATIVE reloc against a local symbol.
Output_data* od, Address address)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, od,
- address, true, false));
+ address, true, true, false));
}
void
Output_data* od, unsigned int shndx, Address address)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx,
- address, true, false));
+ address, true, true, false));
+ }
+
+ // Add a local relocation which does not use a symbol for the relocation,
+ // but which gets its addend from a symbol.
+
+ void
+ add_symbolless_local_addend(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index, unsigned int type,
+ Output_data* od, Address address)
+ {
+ this->add(od, Output_reloc_type(relobj, local_sym_index, type, od,
+ address, false, true, false));
+ }
+
+ void
+ add_symbolless_local_addend(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index, unsigned int type,
+ Output_data* od, unsigned int shndx,
+ Address address)
+ {
+ this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx,
+ address, false, true, false));
}
// Add a reloc against a local section symbol. This will be
Output_data* od, Address address)
{
this->add(od, Output_reloc_type(relobj, input_shndx, type, od,
- address, false, true));
+ address, false, false, true));
}
void
Output_data* od, unsigned int shndx, Address address)
{
this->add(od, Output_reloc_type(relobj, input_shndx, type, shndx,
- address, false, true));
+ address, false, false, true));
}
// A reloc against the STT_SECTION symbol of an output section.
add_global(Symbol* gsym, unsigned int type, Output_data* od,
Address address, Addend addend)
{ this->add(od, Output_reloc_type(gsym, type, od, address, addend,
- false)); }
+ false, false)); }
void
add_global(Symbol* gsym, unsigned int type, Output_data* od,
unsigned int shndx, Address address,
Addend addend)
{ this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address,
- addend, false)); }
+ addend, false, false)); }
// Add a RELATIVE reloc against a global symbol. The final output
// relocation will not reference the symbol, but we must keep the symbol
void
add_global_relative(Symbol* gsym, unsigned int type, Output_data* od,
Address address, Addend addend)
- { this->add(od, Output_reloc_type(gsym, type, od, address, addend, true)); }
+ { this->add(od, Output_reloc_type(gsym, type, od, address, addend, true,
+ true)); }
void
add_global_relative(Symbol* gsym, unsigned int type, Output_data* od,
Sized_relobj<size, big_endian>* relobj,
unsigned int shndx, Address address, Addend addend)
{ this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address,
- addend, true)); }
+ addend, true, true)); }
+
+ // Add a global relocation which does not use a symbol for the relocation,
+ // but which gets its addend from a symbol.
+
+ void
+ add_symbolless_global_addend(Symbol* gsym, unsigned int type, Output_data* od,
+ Address address, Addend addend)
+ { this->add(od, Output_reloc_type(gsym, type, od, address, addend,
+ false, true)); }
+
+ void
+ add_symbolless_global_addend(Symbol* gsym, unsigned int type,
+ Output_data* od,
+ Sized_relobj<size, big_endian>* relobj,
+ unsigned int shndx, Address address, Addend addend)
+ { this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address,
+ addend, false, true)); }
// Add a reloc against a local symbol.
Output_data* od, Address address, Addend addend)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, address,
- addend, false, false));
+ addend, false, false, false));
}
void
Addend addend)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx,
- address, addend, false, false));
+ address, addend, false, false, false));
}
// Add a RELATIVE reloc against a local symbol.
Output_data* od, Address address, Addend addend)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, address,
- addend, true, false));
+ addend, true, true, false));
}
void
Addend addend)
{
this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx,
- address, addend, true, false));
+ address, addend, true, true, false));
+ }
+
+ // Add a local relocation which does not use a symbol for the relocation,
+ // but which gets it's addend from a symbol.
+
+ void
+ add_symbolless_local_addend(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index, unsigned int type,
+ Output_data* od, Address address, Addend addend)
+ {
+ this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, address,
+ addend, false, true, false));
+ }
+
+ void
+ add_symbolless_local_addend(Sized_relobj<size, big_endian>* relobj,
+ unsigned int local_sym_index, unsigned int type,
+ Output_data* od, unsigned int shndx,
+ Address address, Addend addend)
+ {
+ this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx,
+ address, addend, false, true, false));
}
// Add a reloc against a local section symbol. This will be
Output_data* od, Address address, Addend addend)
{
this->add(od, Output_reloc_type(relobj, input_shndx, type, od, address,
- addend, false, true));
+ addend, false, false, true));
}
void
Addend addend)
{
this->add(od, Output_reloc_type(relobj, input_shndx, type, shndx,
- address, addend, false, true));
+ address, addend, false, false, true));
}
// A reloc against the STT_SECTION symbol of an output section.
}
else
{
- unsigned int shndx = lsym.get_st_shndx();
- bool is_ordinary;
-
gold_assert(lsym.get_st_value() == 0);
- shndx = object->adjust_sym_shndx(r_sym, shndx,
- &is_ordinary);
- if (!is_ordinary)
- object->error(_("section symbol %u has bad shndx %u"),
- r_sym, shndx);
- else
- rela_dyn->add_local_section(object, shndx,
- r_type, output_section,
- data_shndx, reloc.get_r_offset(),
- reloc.get_r_addend());
+ rela_dyn->add_symbolless_local_addend(object, r_sym, orig_r_type,
+ output_section, data_shndx,
+ reloc.get_r_offset(),
+ reloc.get_r_addend());
}
}
break;
if (!object->local_has_got_offset(r_sym, GOT_TYPE_TLS_OFFSET))
{
Reloc_section* rela_dyn = target->rela_dyn_section(layout);
+ unsigned int off = got->add_constant(0);
+
+ object->set_local_got_offset(r_sym, GOT_TYPE_TLS_OFFSET, off);
- got->add_local_with_rela(object, r_sym,
- GOT_TYPE_TLS_OFFSET,
- rela_dyn,
- (size == 64 ?
- elfcpp::R_SPARC_TLS_TPOFF64 :
- elfcpp::R_SPARC_TLS_TPOFF32));
+ rela_dyn->add_symbolless_local_addend(object, r_sym,
+ (size == 64 ?
+ elfcpp::R_SPARC_TLS_TPOFF64 :
+ elfcpp::R_SPARC_TLS_TPOFF32),
+ got, off, 0);
}
}
else if (optimized_type != tls::TLSOPT_TO_LE)
gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
Reloc_section* rela_dyn = target->rela_dyn_section(layout);
- rela_dyn->add_local(object, r_sym, r_type,
- output_section, data_shndx,
- reloc.get_r_offset(), 0);
+ rela_dyn->add_symbolless_local_addend(object, r_sym, r_type,
+ output_section, data_shndx,
+ reloc.get_r_offset(), 0);
}
break;
}
// Make a dynamic relocation if necessary.
if (gsym->needs_dynamic_reloc(Symbol::ABSOLUTE_REF))
{
+ unsigned int r_off = reloc.get_r_offset();
+
+ // The assembler can sometimes emit unaligned relocations
+ // for dwarf2 cfi directives.
+ switch (r_type)
+ {
+ case elfcpp::R_SPARC_16:
+ if (r_off & 0x1)
+ orig_r_type = r_type = elfcpp::R_SPARC_UA16;
+ break;
+ case elfcpp::R_SPARC_32:
+ if (r_off & 0x3)
+ orig_r_type = r_type = elfcpp::R_SPARC_UA32;
+ break;
+ case elfcpp::R_SPARC_64:
+ if (r_off & 0x7)
+ orig_r_type = r_type = elfcpp::R_SPARC_UA64;
+ break;
+ case elfcpp::R_SPARC_UA16:
+ if (!(r_off & 0x1))
+ orig_r_type = r_type = elfcpp::R_SPARC_16;
+ break;
+ case elfcpp::R_SPARC_UA32:
+ if (!(r_off & 0x3))
+ orig_r_type = r_type = elfcpp::R_SPARC_32;
+ break;
+ case elfcpp::R_SPARC_UA64:
+ if (!(r_off & 0x7))
+ orig_r_type = r_type = elfcpp::R_SPARC_64;
+ break;
+ }
+
if (gsym->may_need_copy_reloc())
{
target->copy_reloc(symtab, layout, object,
Reloc_section* rela_dyn = target->rela_dyn_section(layout);
check_non_pic(object, r_type);
- rela_dyn->add_global(gsym, orig_r_type, output_section,
- object, data_shndx,
- reloc.get_r_offset(),
- reloc.get_r_addend());
+ if (gsym->is_from_dynobj()
+ || gsym->is_undefined()
+ || gsym->is_preemptible())
+ rela_dyn->add_global(gsym, orig_r_type, output_section,
+ object, data_shndx,
+ reloc.get_r_offset(),
+ reloc.get_r_addend());
+ else
+ rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
+ output_section,
+ object, data_shndx,
+ reloc.get_r_offset(),
+ reloc.get_r_addend());
}
}
}
if (parameters->options().shared())
{
Reloc_section* rela_dyn = target->rela_dyn_section(layout);
- rela_dyn->add_global(gsym, orig_r_type,
- output_section, object,
- data_shndx, reloc.get_r_offset(),
- 0);
+ rela_dyn->add_symbolless_global_addend(gsym, orig_r_type,
+ output_section, object,
+ data_shndx, reloc.get_r_offset(),
+ 0);
}
break;