Bug 27282 - ld: Should SHF_GNU_RETAIN/STT_GNU_IFUNC/STB_GNU_UNIQUE work for ELFOSABI_NONE object files?
Summary: ld: Should SHF_GNU_RETAIN/STT_GNU_IFUNC/STB_GNU_UNIQUE work for ELFOSABI_NONE...
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-30 04:37 UTC by Fangrui Song
Modified: 2021-03-10 21:40 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.