[PATCH] D59958: [llvm-objcopy] Change SHT_NOBITS to SHT_PROBITS for some --set-section-flags

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 30 08:56:48 PDT 2019


MaskRay added inline comments.


================
Comment at: llvm/tools/llvm-objcopy/ELF/ELFObjcopy.cpp:107
+       SectionFlag::SecRom | SectionFlag::SecDebug))
+    Sec.Type = SHT_PROGBITS;
+}
----------------
MaskRay wrote:
> rupprecht wrote:
> > jhenderson wrote:
> > > Won't this change the type of other non-NOBITS sections (e.g. SHT_RELA or SHT_DYNSYM)? Is that intended (I suspect not...)?
> > I did some experimentation with gnu objcopy.
> > * For some sections (rela, symtab, init_array), it never touched the section type, *or* SHF flags (so we're actually already different there)
> > * For some sections like .gnu.hash, it *always* changed it to progbits (even for flags like alloc that don't change nobits to progbits).
> > Fixed this to only change the type if the old type is NOBITS.
> `SHT_NULL` may also change but it may not have much sense.
> 
> Other than that, `SHT_NOBITS` -> `SHT_PROGBITS` is the only possible change. I believe GNU objcopy's rule is similar to the following:
> 
> ```
>           if (Sec.Type == SHT_NOTES && NewFlags & SectionFlags::SecAlloc &&
>               NewFlags & !(SectionFlags::SecLoad))
>             Sec.Type = SHT_PROGBITS;
> ```
Sorry, excessive `!`. It should be:

```
if (Sec.Type == SHT_NOTES && NewFlags & SectionFlags::SecAlloc &&
    NewFlags & SectionFlags::SecLoad)
  Sec.Type = SHT_PROGBITS;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59958





More information about the llvm-commits mailing list