[PATCH] D58426: llvm-objcopy: Change sectionWithinSegment() to use virtual addresses instead of file offsets.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 16:40:39 PDT 2019


pcc added a comment.

Okay, finally getting back to this.

> I still however maintain that if you're relaying on what segment a NOBITS section falls into using ParentSegment then you're doing something wrong. That said there might be an offset bug we should fix for expectation's sake. If we're only trying to fix the offset bug for expectations sake then I support using VAddr/MemSize for NOBITS only as the correct solution. Could you describe your use case a bit more perhaps?

My use case is producing a correct section table when extracting a partition from a combined output file (see Partitions.rst in D60242 <https://reviews.llvm.org/D60242>). In a combined output file there is a main partition whose ELF headers are at file offset 0, as well as one or more loadable partitions whose ELF headers are stored in a section of a specific type. A tool such as llvm-objcopy can extract a partition by:

- reading the section headers using the ELF header at file offset 0;
- if extracting a loadable partition:
  - finding the section containing the required partition ELF header by looking it up in the section table;
  - reading the program headers using the ELF header found in the section;
- if extracting the main partition:
  - reading the program headers using the ELF header at file offset 0;
- filtering the section table according to which sections are in the program headers that it read: if ParentSegment != nullptr or section is not SHF_ALLOC, then it goes in.

That is why ParentSegment needs to be accurate. It doesn't matter which segment it points to, but it needs to point to one of them.

> Return false if a non-allocated NOBITS section is used here
>  If the section is NOBITS use address and check that SectionIsTLS == SegmentIsTLS
>  If the section is not NOBITS disregard SectionIsTLS == SegmentIsTLS and use offset

I think this will work for me. I will implement it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58426





More information about the llvm-commits mailing list