Bug 27490

Summary: gold: Don't produce two output sections __llvm_prf_names
Product: binutils Reporter: Fangrui Song <i>
Component: goldAssignee: Cary Coutant <ccoutant>
Status: UNCONFIRMED ---    
Severity: normal CC: ian
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Fangrui Song 2021-03-01 00:49:12 UTC
LLVM integrated assembler does not set EI_OSABI in the ELF header to ELFOSABI_GNU for SHF_GNU_RETAIN usage. (LLVM does not have the "emulation" concept. In a FreeBSD environment, arguably ELFOSABI_FREEBSD is better. For other OSABI systems, perhaps other values should be used. Anycase, the ELFOSABI_NONE choice is consistent with integrated assembler's handling with  STT_GNU_IFUNC/STB_GNU_UNIQUE.)

cat > ./a.s <<eof
.section __llvm_prf_names,"a",@progbits
.quad 0
eof
echo '.section __llvm_prf_names,"aR",@progbits' > ./b.s
clang -c a.s b.s  # clang >= 12.0.0
# a.o b.o  are ELFOSABI_NONE
~/Dev/binutils-gdb/Debug/gold/ld-new a.o b.o

There are two __llvm_prf_names output sections. GNU ld produces just one.
llvm-cov show  errors if there are two __llvm_prf_names sections.

% readelf -WS a.out
There are 8 section headers, starting at offset 0x168:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        0000000000400078 000078 000000 00  AX  0   0  4
  [ 2] __llvm_prf_names  PROGBITS        0000000000400078 000078 000008 00   A  0   0  1
  [ 3] __llvm_prf_names  PROGBITS        0000000000400080 000080 000000 00  Ao  0   0  1
  [ 4] .note.gnu.gold-version NOTE            0000000000000000 000080 00001c 00      0   0  4
  [ 5] .symtab           SYMTAB          0000000000000000 0000a0 000060 18      6   1  8
  [ 6] .strtab           STRTAB          0000000000000000 000100 000019 00      0   0  1
  [ 7] .shstrtab         STRTAB          0000000000000000 000119 000049 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  l (large), p (processor specific)
Comment 1 Fangrui Song 2021-08-11 03:57:00 UTC
LLVM integrated assembler now sets ELFOSABI_GNU.

That said, the gold behavior creating multiple output sections may continue trapping future new section flags.