* powerpc.cc (Target_powerpc::glink_section): Provide non-const
accessor.
(Target_powerpc::Branch_info::make_stub): Make global entry stubs.
Only call ppc64_local_entry_offset for 64-bit. Restrict
symval_for_branch lookup to ELFv1.
(Stub_table::add_plt_call_entry): Use unsigned int off.
(Output_data_glink::Address, invalid_address): New.
(Output_data_glink::add_eh_frame): Move out of line. Add
support for ELFv2.
(Output_data_glink::add_global_entry, find_global_entry,
global_entry_address): New functions.
(Output_data_glink::global_entry_stubs_, end_branch_table_,
ge_size): New variables.
(Output_data_glink::set_final_data_size): Add global entry
stub sizing.
(Output_data_glink::do_write): Write global entry stubs.
(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Add target
parameter. Return true for ELFv2. Adjust callers.
(Target_powerpc::Scan::local, global): Restrict opd lookup to
ELFv1. Similarly for ifunc and dynamic relocation processing
specific to ELFv1. Recognize that symbols are defined on
their plt entries for ELFv2.
(Target_powerpc::symval_for_branch): Assert if called for
ELFv2 or ppc32.
(Target_powerpc::Relocate::relocate): Use global entry plt
stub for symbol value if such exists on ELFv2.
(Target_powerpc::Relocate::relocate): Don't call
symval_for_branch when ELFv2. Do adjust for local entry
offset when ELFv2.
(Target_powerpc::do_dynsym_value): Set symbols to global entry
plt stub for ELFv2.
(Target_powerpc::do_plt_address_for_global): Similarly.
This adds an extra flag for needs_dynamic_reloc() in order to remove
the copy of this function and use_plt_offset() in powerpc.cc, and
tweaks the powerpc get_reference_flags() to return the flag as
appropriate. ELFv2 does not want ELFv1 behaviour here.
* symtab.h (Symbol::Reference_flags): Add FUNC_DESC_ABI.
(Symbol::needs_dynamic_reloc): Test new flag.
* powerpc.cc (needs_dynamic_reloc, use_plt_offset): Delete.
(Target_powerpc::Scan::get_reference_flags): Add target param.
Return FUNC_DESC_ABI for 64-bit ELFv1.
(Target_powerpc::Branch_info::make_stub): Adjust get_reference_flags
call.
(Target_powerpc::Scan::global): Use Symbol::needs_dynamic_reloc.
(Target_powerpc::Relocate::relocate): Use Symbol::use_plt_offset.
elfcpp/
* powerpc.h (EF_PPC64_ABI): New enum constant.
(STO_PPC64_LOCAL_BIT, STO_PPC64_LOCAL_MASK): Likewise.
(ppc64_decode_local_entry): New function.
(ppc64_encode_local_entry): Likewise.
gold/
* powerpc.cc (Powerpc_relobj::abiversion, set_abiversion,
ppc64_local_entry_offset, ppc64_local_entry_offset,
do_read_symbols): New functions.
(Powerpc_relobj::e_flags_, st_other_): New vars.
(Powerpc_relobj::Powerpc_relobj): Call set_abiversion.
(Powerpc_dynobj::abiversion, set_abiversion): New functions.
(Powerpc_relobj::e_flags_): New var.
(Target_powerpc::first_plt_entry_offset, plt_entry_size): Inline
and adjust for ELFv2.
(Target_powerpc::abiversion, set_abiversion, stk_toc): New functions.
(Powerpc_relobj::do_find_special_sections): Check no .opd in ELFv2.
(Powerpc_dynobj::do_find_special_sections): Likewise.
(Target_powerpc::do_define_standard_symbols): Define ".TOC.".
(Target_powerpc::Branch_info::make_stub): Adjust stub destination
to ELFv2 local entry.
(Target_powerpc::do_relax): No thread safe barriers needed for
ELFv2.
(Output_data_plt_powerpc::initial_plt_entry_size_,
plt_entry_size): Delete. Replace all uses with
first_plt_entry_offset() and plt_entry_size().
(Output_data_plt_powerpc::Output_data_plt_powerpc): Remove
reserved_size parm. Update callers.
(Output_data_plt_powerpc::entry_count): Update.
(Output_data_plt_powerpc::first_plt_entry_offset): Make private
and use Target_powerpc::first_plt_entry_offset().
(Output_data_plt_powerpc::get_plt_entry_size): Similarly and
rename to plt_entry_size.
(Output_data_plt_powerpc::add_ifunc_entry,
add_local_ifunc_entry): Adjust reloc for ELFv2.
(glink_eh_frame_fde_64): Rename to glink_eh_frame_fde_64v1.
(glink_eh_frame_fde_64v2): New.
(Stub_table::plt_call_size): Support ELFv2 sizing.
(Output_data_glink::add_eh_frame): Use the new FDE.
(Output_data_glink::set_final_data_size): Adjust for ELFv2 glink.
(Stub_table::do_write): Write ELFv2 stubs and glink.
(Target_powerpc::Relocate::relocate): Replaces nop after call
with ld 2,24(1) and adjust local offset destination for ELFv2.
This changes the behaviour of @h and @ha on PowerPC64 to report errors
on 32-bit overflow. The motivation for this change is that on
PowerPC64, most uses of @h and @ha modifiers and their corresponding
relocations are to build up 32-bit offsets. We'd like to know when
such offsets overflow. Only rarely do people use @h or @ha with the
high 32-bit modifiers to build a 64-bit constant. Those uses will now
need to use two new modifiers, @high and @higha, if the constant isn't
known at assembly time. For now, we won't report overflow at assembly
time..
This also fixes an error when applying some of the HIGHER and HIGHEST
relocations.
include/elf/
* ppc64.h (R_PPC64_ADDR16_HIGH, R_PPC64_ADDR16_HIGHA,
R_PPC64_TPREL16_HIGH, R_PPC64_TPREL16_HIGHA,
R_PPC64_DTPREL16_HIGH, R_PPC64_DTPREL16_HIGHA): New.
(IS_PPC64_TLS_RELOC): Match new tls relocs.
bfd/
* reloc.c (BFD_RELOC_PPC64_ADDR16_HIGH, BFD_RELOC_PPC64_ADDR16_HIGHA,
BFD_RELOC_PPC64_TPREL16_HIGH, BFD_RELOC_PPC64_TPREL16_HIGHA,
BFD_RELOC_PPC64_DTPREL16_HIGH, BFD_RELOC_PPC64_DTPREL16_HIGHA): New.
* elf64-ppc.c (ppc64_elf_howto_raw): Add entries for new relocs.
Make all _HA and _HI relocs report signed overflow.
(ppc64_elf_reloc_type_lookup): Handle new relocs.
(must_be_dyn_reloc, ppc64_elf_check_relocs): Likewise.
(dec_dynrel_count, ppc64_elf_relocate_section): Likewise.
(ppc64_elf_relocate_section): Don't apply 0x8000 adjust to
R_PPC64_TPREL16_HIGHER, R_PPC64_TPREL16_HIGHEST,
R_PPC64_DTPREL16_HIGHER, and R_PPC64_DTPREL16_HIGHEST.
* libbfd.h: Regenerate.
* bfd-in2.h: Regenerate.
gas/
* config/tc-ppc.c (SEX16): Don't mask.
(REPORT_OVERFLOW_HI): Define as zero.
(ppc_elf_suffix): Support @high, @higha, @dtprel@high, @dtprel@higha,
@tprel@high, and @tprel@higha modifiers.
(md_assemble): Ignore X_unsigned when applying 16-bit insn fields.
Add (disabled) code to check @h and @ha reloc overflow for powerpc64.
Handle new relocs.
(md_apply_fix): Similarly.
elfcpp/
* powerpc.h (R_PPC64_ADDR16_HIGH, R_PPC64_ADDR16_HIGHA,
R_PPC64_TPREL16_HIGH, R_PPC64_TPREL16_HIGHA,
R_PPC64_DTPREL16_HIGH, R_PPC64_DTPREL16_HIGHA): Define.
gold/
* powerpc.cc (Target_powerpc::Scan::check_non_pic): Handle new relocs.
(Target_powerpc::Scan::global, local): Likewise.
(Target_powerpc::Relocate::relocate): Likewise. Check for overflow
on all ppc64 @h and @ha relocs.
(Output_data_got::add_constant_pair): New function.
* powerpc.cc (Output_data_got_powerpc): Override all Output_data_got
methods used so as to first call reserve_ent().
* object.cc (Sized_relobj::do_output_section_address): New function.
(Sized_relobj): Instantiate explicitly.
* object.h (Object::output_section_address): New function.
(Object::do_output_section_address): New function.
(Sized_relobj::do_output_section_address): New function.
* powerpc.cc (Target_powerpc::symval_for_branch): Use it.
* elf64-ppc.c (struct ppc_stub_hash_entry): Delete "addend".
(ppc64_elf_size_stubs): Don't set "addend".
(ppc64_elf_relocate_section): Don't allow calls via
toc-adjusting stubs without a following nop even in an
executable, except for self-calls and both libc_start_main
and .libc_start_main.
gold/
* powerpc.cc (Target_powerpc::Relocate::relocate): Update self-call
comment.
* powerpc.cc (Output_data_brlt_powerpc::reset_brlt_sizes): New
function.
(Output_data_brlt_powerpc::finalize_brlt_sizes): New function.
(Target_powerpc::do_relax): Call the above.
on garbage collected .opd section.
* powerpc.cc (Target_powerpc::do_gc_add_reference): Test dst_shndx
is non-zero.
(Target_powerpc::do_gc_mark_symbols): Likewise for sym->shndx().
(Target_powerpc::do_function_location): Likewise for loc->shndx.
owner when sections are not adjacent and exceed group size.
(Target_powerpc::group_sections): Handle corner case.
(Target_powerpc::Branch_info::make_stub): Handle case where
stub table doesn't exist due to branches in non-exec sections.
(Target_powerpc::Relocate::relocate): Likewise.
static and public. Add report_err param. Return false for data refs.
(Target_powerpc::rela_dyn_section): New overloaded function.
(Target_powerpc::plt_, iplt_): Elucidate.
(Output_data_plt_powerpc::entry_count): Handle current_data_size()==0.
(Output_data_plt_powerpc::do_write): Don't write .iplt.
(Output_data_plt_powerpc::plt_entry_count): Don't add .iplt entries.
(Target_powerpc::Scan::local, global): Adjust reloc_needs_plt_for_ifunc
calls. Put ifunc dynamic relocs in irela_dyn_section. Only
push_branch and make_plt_entry for ifunc syms when
reloc_needs_plt_for_ifunc.
(Target_powerpc::Relocate::relocate): Don't use plt entry value
for ifunc unless reloc_needs_plt_for_ifunc.
* target.cc (Target::do_plt_fde_location): New function.
* ehframe.h (class FDE): Add post_map field to u_.from_linker,
accessor function, and constructor param.
(struct Post_fde, Post_fdes): Declare.
(Cie::write): Add post_fdes param.
* ehframe.cc (Fde::write): Use plt_fde_location.
(struct Post_fde): Define.
(Cie::write): Stash FDEs added post merge mapping.
(Eh_frame::add_ehframe_for_plt): Assert no new CIEs after mapping.
Adjust Fde constructor call. Bump final_data_size_ for post map FDEs.
(Eh_frame::do_sized_write): Arrange to write post map FDES after
other FDEs.
* powerpc.cc (Target_powerpc::do_plt_fde_location): New function.
(Target_powerpc::has_glink): New function.
(Target_powerpc::do_relax): Add eh_frame info for stubs.
(struct Eh_cie, eh_frame_cie, glink_eh_frame_fde_64,
glink_eh_frame_fde_32, default_fde): New data.
(Stub_table::eh_frame_added_): New var.
(Stub_table::find_long_branch_entry, stub_address, stub_offset):
Make const.
(Stub_table::add_eh_frame): New function.
(Output_data_glink::add_eh_frame): New function.
(Target_powerpc::make_glink_section): Call add_eh_frame.
(class Relocate, class Scan): Inherit Track_tls.
(Target_powerpc::Scan::local, global): Track tls optimization
and avoid creating plt entry for __tls_get_addr if all uses
are optimized away.
(Target_powerpc::Relocate::relocate): Update to use Track_tls.
plt_thread_safe. Update stub_group_size help text.
* powerpc.cc (Target_powerpc::plt_thread_safe): New access function
for new plt_thread_safe_ var.
(use_plt_offset): Correct comments.
(Target_powerpc::do_relax): Look for thread creation symbols to
determine default plt_thread_safe value. Clear plt call stubs
as well as branch stubs each iteration.
(add_2_2_11, add_12_12_11, bnectr_p4, cmpldi_2_0, xor_11_11_11): New
insn constants.
(l, hi, ha, write_insn): Move earlier.
(Stub_table): Delete prev_size, add last_plt_size and last_branch_size.
(Stub_table::clear_stubs): Rename from clear_long_branch_stubs, clear
plt stubs too.
(Stub_table::update_size): Adjust.
(Stub_table::prev_size, set_prev_size): Delete.
(Stub_table::stub_align): Let --plt-align affect result.
(Stub_table::plt_call_size): Calculate sizes for various stubs.
(Stub_table::branch_stub_size): Use last_plt_size in address calc.
(Stub_table::add_plt_call_stub): Pass iterator to plt_call_size.
(Stub_table::do_write): Support more stub variants.
* layout.cc (Layout::get_executable_sections): New function.
* arm.cc (Target_arm::group_sections): Use it.
(Arm_output_section::group_sections): Delete now redundant test.
* output.cc (Output_reloc::Output_reloc): Add is_relative.
param to handle relative relocs.
* output.h (Output_reloc::Output_reloc <absolute reloc>): Likewise.
(Output_data_reloc::add_absolute): Adjust.
(Output_data_reloc::add_relative): New function.
(Output_data::reset_data_size): New function.
(Output_relaxed_input_section::set_relobj, set_shndx): New functions.
(Output_section::set_addralign): New function.
(Output_section::checkpoint_set_addralign): New function.
(Output_section::clear_section_offsets_need_adjustment): New function.
(Output_section::input_sections): Make public.
* powerpc.cc (class Output_data_brlt_powerpc): New.
(class Stub_table, class Stub_control): New.
(Powerpc_relobj::has14_, set_has_14bit_branch, has_14bit_branch,
stub_table_, set_stub_table, stub_table): New vectors and accessor
functions.
(Target_powerpc::do_may_relax, do_relax, push_branch,
new_stub_table, stub_tables, brlt_section, group_sections,
add_branch_lookup_table, find_branch_lookup_table,
write_branch_lookup_table, make_brlt_section): New functions.
(Target_powerpc::struct Sort_sections, class Branch_info): New.
(Target_powerpc::brlt_section_, stub_tables_, branch_lookup_table_,
branch_info_): New vars.
(Target_powerpc::make_plt_entry, make_local_ifunc_plt_entry): Don't
make call stubs here.
(Output_data_glink): Remove all call stub handling from this class.
(Target_powerpc::Scan::local, global): Save interesting branch
relocs and relocs for ifunc. Adjust calls to plt entry functions.
(Target_powerpc::do_finalize_sections): Only make reg save/restore
functions on final link.
(Target_powerpc::Relocate::relocate): Adjust lookup of call stubs.
Handle long branch destinations too.
(Target_powerpc::do_dynsym_value, do_plt_address_for_global,
do_plt_address_for_local): Adjust lookup of plt call stubs.
(struct Opd_ent): Use "Address" rather than "Offset".
(Output_data_got_powerpc::got_base_offset): Return Valtype.
(Target_powerpc::got_section): Make public.
(Target_powerpc::scan_relocs): Move code setting symbols..
(Powerpc_relobj::do_scan_relocs): ..to here, new function.
Create _SDA_BASE_ only when referenced.
dynamic relocs for GOT_TPREL got entries, without symbol if
resolving locally.
(Target_powerpc::do_gc_add_reference): Don't add for dynamic objects.
(Target_powerpc::scan_relocs): Define _GLOBAL_OFFSET_TABLE_ early.
(Target_powerpc::Relocate:relocate): REL32 reloc may be unaligned.
(Target_powerpc::do_finalize_sections): Call it.
(Output_data_save_res): New class and supporting functions.
(Target_powerpc::symval_for_branch): Only look up .opd entry for
normal symbols defined in object files.
(struct Opd_ent): Make "discard" a bit field. Add "gc_mark".
(Target_powerpc::do_gc_mark_symbol): Delay marking function code
section if scan_opd_relocs not yet called.
(Target_powerpc::gc_process_relocs): Call process_gc_mark.
do_plt_address_for_global): New functions.
(Output_data_got_powerpc::do_write): Don't segfault when linking
statically.
(Output_data_plt_powerpc::add_entry, add_ifunc_entry,
add_local_ifunc_entry): Return true on adding entry..
(Target_powerpc::make_plt_entry): ..use to avoid unnecessary
glink->add_entry call. Remove unused symtab param. Adjust calls.
(Target_powerpc::make_local_ifunc_plt_entry): Likewise.
(Target_powerpc::make_iplt_section): Remove symtab param. Don't
set up symbols here.
(Target_powerpc::do_finalize_sections): Instead set up __rela_iplt
syms here. Do so even when no .iplt. Don't segfault when linking
statically.
(Output_data_glink::add_entry, find_entry): Rearrange params. Add
new variants without reloc param.
(Glink_sym_ent::Glink_sym_ent): Likewise.
(Target_powerpc::Scan::reloc_needs_plt_for_ifunc): Accept any
reloc when refs will resolve to plt call stub.
(Target_powerpc::Scan::local): Correct ifunc handling. Allow
R_PPC_PLTREL24 to resolve locally.
(Target_powerpc::Scan::global): Correct ifunc handling.
(Target_powerpc::Relocate::relocate): Correct local sym glink
lookup. Don't destroy "value" when we have a plt call stub,
and when checking plt call validity.
(Target_powerpc::do_dynsym_value): Simplify.
(Target_powerpc::iplt_section, make_iplt_section,
reloc_needs_plt_for_ifunc, make_local_ifunc_plt_entry): New functions.
(Target_powerpc::make_plt_entry): Handle ifunc syms.
Target_powerpc::plt_entry_count): Count iplt entries too.
(Output_data_plt_powerpc::Output_data_plt_powerpc): Don't create
reloc section in constructor. New params.
(Target_powerpc::make_plt_section): Create reloc section here instead.
(Output_data_plt_powerpc::add_ifunc_entry, add_local_ifunc_entry): New
functions.
(Output_data_plt_powerpc::initial_plt_entry_size_, name_): New vars.
(Output_data_glink::add_entry, find_entry): New functions to
deal with local syms.
(Glink_sym_ent): Add support for local syms.
(Output_data_glink::do_write): Handle ifunc plt entries.
(Target_powerpc::Scan::get_reference_flags): Handle more relocs.
(Target_powerpc::Scan::local, global): Handle ifunc syms.
(Target_powerpc::Relocate::relocate): Likewise.
(Target_powerpc::do_dynsym_value): Use glink stub, not plt entry.
do_adjust_local_symbol): New functions.
* object.cc (Sized_relobj_file::do_count_local_symbols): Use the above.
* powerpc.cc (Powerpc_relobj::do_adjust_local_symbol): New function.
(Powerpc_relobj::scan_opd_relocs): Warn on unexpected opd relocs
and irregular opd entry spacing.
(Powerpc_relobj::do_read_relocs): Add opd size checks.
(Global_symbol_visitor_opd): New functor.
(Target_powerpc::do_finalize_sections): Omit global symbols defined
on deleted opd entries.
against symbols in discarded sections. Pass is_discarded
param.
* arm.cc, * i386.cc, * sparc.cc, * x86_64.cc (Target_*::Scan::local):
Add is_discarded param.
* powerpc (Target_powerpc::Scan::local): Likewise. Use
is_discarded to flag opd entry as discarded. Don't emit dyn
relocs on such entries.
(Target_powerpc::Scan::global): Similarly detect and handle
such opd entries.
(Powerpc_relobj): Replace opd_ent_shndx_ and opd_ent_off_ with
opd_ent_. Update all uses.
(Powerpc_relobj::get_opd_discard, set_opd_discard): New functions.
(Target_powerpc::relocate_section): Zero out discarded opd
entry relocs.
(Sized_target::gc_add_reference, do_gc_add_reference): New functions.
* gc.h (gc_process_relocs): Call target gc_add_reference.
* gold.cc (queue_middle_tasks): Use gc_mark_symbol on start sym.
* symtab.cc (Symbol_table::gc_mark_undef_symbols): Use gc_mark_symbol.
(Symbol_table::gc_mark_symbol): Call target gc_mark_symbol. Remove
unnecessary cast.
* powerpc.cc (Powerpc_relobj::get_opd_ent): Rearrange parameters
to cater for when we don't need code offset. Update use.
(Powerpc_relobj::access_from_map_, opd_valid_): New vars.
(Powerpc_relobj::access_from_map, add_reference, opd_valid,
set_opd_valid): New functions.
(Target_powerpc::do_gc_add_reference): New function.
(Target_powerpc::gc_process_relocs): Call gc()->add_reference on
stashed refs.
(Target_powerpc::do_gc_mark_symbol): New function.