Bug 27282

Summary: ld: Should SHF_GNU_RETAIN/STT_GNU_IFUNC/STB_GNU_UNIQUE work for ELFOSABI_NONE object files?
Product: binutils Reporter: Fangrui Song <i>
Component: ldAssignee: Not yet assigned to anyone <unassigned>
Status: UNCONFIRMED ---    
Severity: normal    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Fangrui Song 2021-01-30 04:37:10 UTC
ld -m elf_x86_64  recognizes semantics of OS-specific STT_GNU_IFUNC/STB_GNU_UNIQUE in ELFOSABI_NONE object files.

  LLVM integrated assembler as of 12.0.0 does not set ELFOSABI_GNU if you use @gnu_indirect_function/@gnu_unique_object.

  Question: how do GNU as set OSABI for STT_GNU_IFUNC/STB_GNU_UNIQUE on FreeBSD? Is the behavior host platform dependent? 

However, ld -m elf_x86_64  does not recognize SHF_GNU_RETAIN in ELFOSABI_NONE object files.

So these section/symbol properties have some inconsistency.
I can see two choices.


1. (Current behavior)
Ignore semantics of SHF_GNU_RETAIN in ELFOSABI_NONE object files.
If we want to make rules consistent, we should do this for STT_GNU_IFUNC/STB_GNU_UNIQUE,
but it would break all the object files produced by LLVM integrated assembler.

2.
Recognize the semantics of SHF_GNU_RETAIN if the ld configuration & options indicate Linux target (e.g. ld -m elf_x86_64 on Linux),
regardless of EI_OSABI in object files.
This choice gives discretion to the linker.

I think the only downside is that readelf -S does not display 'R' for SHF_GNU_RETAIN,
like readelf -s doesn't show IFUNC for LLVM integrated assembler assembled object files today.
Comment 1 Fangrui Song 2021-03-10 21:40:15 UTC
You can close this one.

For SHF_GNU_RETAIN, I've changed clang 13 to set ELFOSABI_GNU.
I am happy with the current GNU ld behavior.

For STT_GNU_IFUNC, clang has always been using ELFOSABI_NONE.
So please don't drop support.