Bug 28035 - objcopy/strip: Don't convert SHT_REL to SHT_RELA
Summary: objcopy/strip: Don't convert SHT_REL to SHT_RELA
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-30 19:59 UTC by Fangrui Song
Modified: 2023-08-07 10:02 UTC (History)
1 user (show)

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-06-30 19:59:40 UTC
With 'clang' and 'llvm-profdata' built from the main branch of llvm-project (the future clang 13.0.0 release):

echo -e '#include <stdio.h>\nint main() { puts("foo"); }' > a.c
clang -O1 -fprofile-generate a.c; rm default*.profraw; ./a.out; llvm-profdata merge default_*.profraw -o a.profdata
clang -O1 -fprofile-use=a.profdata a.c -c

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .strtab           STRTAB          0000000000000000 0001a0 000097 00      0   0  1
  [ 2] .text             PROGBITS        0000000000000000 000040 000000 00  AX  0   0  4
  [ 3] .text.hot.        PROGBITS        0000000000000000 000040 00000f 00  AX  0   0 16
  [ 4] .rela.text.hot.   RELA            0000000000000000 000138 000030 18     13   3  8
  [ 5] .rodata.str1.1    PROGBITS        0000000000000000 00004f 000004 01 AMS  0   0  1
  [ 6] .comment          PROGBITS        0000000000000000 000053 000016 01  MS  0   0  1
  [ 7] .note.GNU-stack   PROGBITS        0000000000000000 000069 000000 00      0   0  1
  [ 8] .llvm.call-graph-profile LOOS+0xfff4c09  0000000000000000 000069 000008 08   E 13   0  1
  [ 9] .rel.llvm.call-graph-profile REL             0000000000000000 000168 000020 10     13   8  8
  [10] .eh_frame         X86_64_UNWIND   0000000000000000 000078 000030 00   A  0   0  8
  [11] .rela.eh_frame    RELA            0000000000000000 000188 000018 18     13  10  8
  [12] .llvm_addrsig     LOOS+0xfff4c03  0000000000000000 0001a0 000000 00   E 13   0  1
  [13] .symtab           SYMTAB          0000000000000000 0000a8 000090 18      1   4  8

objcopy --strip-debug a.o a.copy.o


I think it will be good to retain the original section type, don't convert REL to RELA just because of arch/ABI preference.

---

Just for completeness, the original .rel.llvm.call-graph-profile contains R_X86_64_NONE relocations.

% readelf -r a.o
...
Relocation section '.rel.llvm.call-graph-profile' at offset 0x168 contains 2 entries:
  Offset          Info           Type           Sym. Value    Sym. Name
000000000000  000400000000 R_X86_64_NONE     0000000000000000 main
000000000000  000500000000 R_X86_64_NONE     0000000000000000 puts
...