[PATCH] D60042: [llvm-objcopy] Add --prefix-alloc-sections

Seiya Nuta via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 4 03:40:05 PDT 2019


seiya marked an inline comment as done.
seiya added inline comments.


================
Comment at: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp:614
+    for (auto &Sec : Obj.sections()) {
+      if ((Sec.Flags & SHF_ALLOC) != 0) {
+        Sec.Name = (Config.AllocSectionsPrefix + Sec.Name).str();
----------------
jhenderson wrote:
> Hmm... What does GNU objcopy do for dynamic relocation sections (i.e. SHT_REL[A] with SHF_ALLOC)? Will it rename them according to the switch, or something else (e.g. renaming based on their target section). In other words, if for example I had a .rela.plt section targeting .plt and I did `--prefix-alloc-sections=.foo`, do you get `.foo.rela.plt` or `.rela.foo.plt` or something else?
> 
> You need a test case for this too.
It seems that GNU objcopy does not support such sections [1]. It produces `.foo.rela.plt` but does not preserve its link field:

```
$ readelf -S hello
There are 29 section headers, starting at offset 0x19e0:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .prefix.interp    PROGBITS         0000000000000238  00000238
       000000000000001c  0000000000000000   A       0     0     1
  [ 2] .prefix.note.ABI- NOTE             0000000000000254  00000254
       0000000000000020  0000000000000000   A       0     0     4
  [ 3] .prefix.note.gnu. NOTE             0000000000000274  00000274
       0000000000000024  0000000000000000   A       0     0     4
  [ 4] .prefix.gnu.hash  GNU_HASH         0000000000000298  00000298
       000000000000001c  0000000000000000   A       5     0     8
readelf: Warning: [ 5]: Link field (0) should index a string section.
  [ 5] .prefix.dynsym    DYNSYM           00000000000002b8  000002b8
       00000000000000a8  0000000000000018   A       0     1     8
  [ 6] .prefix.dynstr    STRTAB           0000000000000360  00000360
       0000000000000082  0000000000000000   A       0     0     1
  [ 7] .prefix.gnu.versi VERSYM           00000000000003e2  000003e2
       000000000000000e  0000000000000002   A       5     0     2
  [ 8] .prefix.gnu.versi VERNEED          00000000000003f0  000003f0
       0000000000000020  0000000000000000   A       6     1     8
readelf: Warning: [ 9]: Link field (0) should index a symtab section.
  [ 9] .prefix.rela.dyn  RELA             0000000000000410  00000410
       00000000000000c0  0000000000000018   A       0     0     8
readelf: Warning: [10]: Link field (0) should index a symtab section.
  [10] .prefix.rela.plt  RELA             00000000000004d0  000004d0
       0000000000000018  0000000000000018   A       0     0     8
  [11] .prefix.init      PROGBITS         00000000000004e8  000004e8
       0000000000000017  0000000000000000  AX       0     0     4
  [12] .prefix.plt       PROGBITS         0000000000000500  00000500
       0000000000000020  0000000000000010  AX       0     0     16
  [13] .prefix.plt.got   PROGBITS         0000000000000520  00000520
       0000000000000008  0000000000000008  AX       0     0     8
  [14] .prefix.text      PROGBITS         0000000000000530  00000530
       00000000000001a2  0000000000000000  AX       0     0     16
  [15] .prefix.fini      PROGBITS         00000000000006d4  000006d4
       0000000000000009  0000000000000000  AX       0     0     4
  [16] .prefix.rodata    PROGBITS         00000000000006e0  000006e0
       000000000000000a  0000000000000000   A       0     0     4
  [17] .prefix.eh_frame_ PROGBITS         00000000000006ec  000006ec
       000000000000003c  0000000000000000   A       0     0     4
  [18] .prefix.eh_frame  PROGBITS         0000000000000728  00000728
       0000000000000108  0000000000000000   A       0     0     8
  [19] .prefix.init_arra INIT_ARRAY       0000000000200db8  00000db8
       0000000000000008  0000000000000008  WA       0     0     8
  [20] .prefix.fini_arra FINI_ARRAY       0000000000200dc0  00000dc0
       0000000000000008  0000000000000008  WA       0     0     8
readelf: Warning: [21]: Link field (0) should index a string section.
```

I'll add a test case for this.

[1]: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=bfd/elf.c;h=952e4bfe11b4a222823a31d07615007e91b519ba;hb=HEAD#l2398


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60042/new/

https://reviews.llvm.org/D60042





More information about the llvm-commits mailing list