* x86_64.cc (Scan::get_reference_flags): Mark PC relative relocations as possibly created from function calls too. (Scan::global): Allow PLT entry for PC32 relocation of a function symbol for pie links. Set the address of the dynamic symbol table entry for this function to that of the PLT entry. diff --git a/gold/x86_64.cc b/gold/x86_64.cc index 4543c8a..26943fb 100644 --- a/gold/x86_64.cc +++ b/gold/x86_64.cc @@ -2157,6 +2157,7 @@ Target_x86_64::Scan::get_reference_flags(unsigned int r_type) case elfcpp::R_X86_64_PC64: case elfcpp::R_X86_64_PC32: + return Symbol::FUNCTION_CALL | Symbol::RELATIVE_REF; case elfcpp::R_X86_64_PC32_BND: case elfcpp::R_X86_64_PC16: case elfcpp::R_X86_64_PC8: @@ -2835,9 +2836,20 @@ Target_x86_64::Scan::global(Symbol_table* symtab, case elfcpp::R_X86_64_PC16: case elfcpp::R_X86_64_PC8: { - // Make a PLT entry if necessary. - if (gsym->needs_plt_entry()) - target->make_plt_entry(symtab, layout, gsym); + // Make a PLT entry if necessary. Allow elfcpp::R_X86_64_PC32 + // relocations on function symbols to create PLT entries for pie links. + if (gsym->needs_plt_entry() + || (r_type == elfcpp::R_X86_64_PC32 && gsym->is_func() + && parameters->options().pie())) + { + target->make_plt_entry(symtab, layout, gsym); + // For PIE links, a R_X86_64_PC32 relocation may be used in + // function calls. In that case we need to set the entry in + // the dynamic symbol table to the address of the PLT entry. + if (gsym->is_from_dynobj() &&r_type == elfcpp::R_X86_64_PC32 + && gsym->is_func() && parameters->options().pie()) + gsym->set_needs_dynsym_value(); + } // Make a dynamic relocation if necessary. if (gsym->needs_dynamic_reloc(Scan::get_reference_flags(r_type))) {