[GOLD] Support --icf=safe with -pie for x86_64
Rahul Chaudhry via binutils
binutils@sourceware.org
Fri Feb 3 20:17:00 GMT 2017
>> I looked (maybe not carefully enough), but I didn't find anything in
>> this call chain that restricts the check to text sections:
>>
>> gc_process_relocs
>> -> scan.[global|local]_reloc_may_be_function_pointer
>> -> possible_function_pointer_reloc
>>
>> You need to check the SHF_EXECINST flag before assuming you're looking
>> at an opcode. (Look in x86_64.cc for "is_executable".)
>
> I'll take a closer look at this, add a check, and send an updated patch.
>
>
>> I think you should also be checking that the target symbol is
>> STT_FUNC; that should rule out most jump table cases. (I see a check
>> for != STT_OBJECT in the local symbol path, but nothing in the global
>> symbol path. It may be the case that STT_NOTYPE is used for some
>> extern function symbols, but you want to be conservative, right?)
>
> Ditto for this one.
Please see the updated patch below. There are two updates:
* Added a check for SHF_EXECINSTR flag before checking the call/jump opcodes.
* Added a check for STT_FUNC in the global symbol path.
Also, to add some background behind this patch, we're linking a large C++
binary (chrome-browser) with -pie.
* With --icf=none, the binary size is 177M.
* With --icf=safe, before this patch, the binary size is 176M.
ICF is able to fold 16730 sections (only ctors and dtors, since
Target_x86_64::do_can_check_for_function_pointers returns
false when using -pie).
* After applying this patch, with --icf=safe, the binary size is 169M.
ICF is able to fold 55623 sections.
* 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.
* gc.h (gc_process_relocs): Add check for STT_FUNC.
* 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: 14467 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20170203/b4e1c7ad/attachment.bin>
More information about the Binutils
mailing list