[GOLD] Support --icf=safe with -pie for x86_64

Rahul Chaudhry via binutils binutils@sourceware.org
Thu Jan 12 21:29:00 GMT 2017


--icf=safe folds identical functions only if the functions do not have their
address taken. It uses relocation types to distinguish between a function call
and taking the address of a function. This works fine for all architectures
except x86_64, where the same relocation type (R_X86_64_PC32) may be used for
both function call and taking the address of a function (when compiled with
-fPIE). Currently Target_x86_64::do_can_check_for_function_pointers returns
false if the linker is invoked with -pie, and --icf=safe folds only ctors and
dtors.

This patch adds improved support for --icf=safe when used with -pie. For the
ambiguous case of R_X86_64_PC32 relocation, it checks the instruction opcode to
distinguish between function calls and taking the address of a function.

OK?

        * x86_64.cc (Target_x86_64::do_can_check_for_function_pointers):
        Return true even when building pie binaries.
        (Target_x86_64::possible_function_pointer_reloc): Check opcode
        for R_X86_64_PC32 relocations.
        (Target_x86_64::local_reloc_may_be_function_pointer): Pass
        extra arguments to local_reloc_may_be_function_pointer.
        (Target_x86_64::global_reloc_may_be_function_pointer): Likewise.
        * testsuite/Makefile.am (icf_safe_pie_test): New test case.
        * testsuite/Makefile.in: Regenerate.
        * testsuite/icf_safe_pie_test.sh: New shell script.

-- 
Rahul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pie-safe-icf.patch
Type: text/x-patch
Size: 13644 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20170112/0b178c1a/attachment.bin>


More information about the Binutils mailing list