[PATCH] D57365: [llvm-readobj] Add a flag to dump just the section-to-segment mapping.

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 30 02:22:40 PST 2019


jhenderson requested changes to this revision.
jhenderson added a comment.
This revision now requires changes to proceed.

It occurred to me that if we were to implement section mapping for other output styles, e.g. LLVM, or formats (I don't know if that concept applies to COFF/MachO/Wasm etc mind you!), then we probably don't want to print the section mapping when program-headers is specified, except in GNU output style. This implies that the decision on whether to print the section mapping should be down to the dumper layer, not the command-line handling layer. This is very similar to the situation with --symbols/--dyn-symbols for GNU output style, and I suspect the solution should be essentially the same as rL351960 <https://reviews.llvm.org/rL351960>.



================
Comment at: llvm/test/tools/llvm-readobj/gnu-phdrs.test:17-18
+RUN:   --elf-output-style=GNU | FileCheck %s -check-prefixes ELF64-PHDRS,ELF64-MAPPING
+RUN: llvm-readelf -program-headers %p/Inputs/phdrs-elf.exe-x86_64 \
+RUN:   | FileCheck %s -check-prefixes ELF64-PHDRS,ELF64-MAPPING
+RUN: llvm-readelf -section-mapping -program-headers %p/Inputs/phdrs-elf.exe-i386 \
----------------
I'm not sure you need this test case, as it is identical to the previous one essentially. `llvm-readobj --elf-output-style=GNU` and `llvm-readelf` are essentially identical (ignoring certain unrelated switch interpretations and aliases).


================
Comment at: llvm/test/tools/llvm-readobj/gnu-phdrs.test:19-20
+RUN:   | FileCheck %s -check-prefixes ELF64-PHDRS,ELF64-MAPPING
+RUN: llvm-readelf -section-mapping -program-headers %p/Inputs/phdrs-elf.exe-i386 \
+RUN:   | FileCheck %s -check-prefix ELF32
+
----------------
What is this check giving us that's different to the one on line 13?


================
Comment at: llvm/test/tools/llvm-readobj/gnu-phdrs.test:26
+RUN: llvm-readelf -section-mapping %p/Inputs/phdrs-elf.exe-x86_64 \
+RUN:   | not grep "Program Headers:"
+
----------------
Using grep in lit has been deprecated, I believe. Use FileCheck `CHECK-NOT` patterns.

You can do the checking that the program headers are not present at the same time as the section mapping test, by using careful placement of the NOT patterns. NOT patterns fail if the output appears between the two positive checks either side of the NOT (or the start/end of file if there are none before/after it). Example that would fail if "Program Headers:" appears before or after the section mapping:
```
CHECK-NOT: Program Headers:
CHECK: Mapping
CHECK-NOT: Program Headers:
```
You can even use `check-prefixes` to share check patterns in a mix-and-match kind of way to avoid duplicating common things. All the names get added to one big bucket. When FileCheck scans the file for patterns it uses any with a matching prefix, in sequence, regardless of which prefix (i.e. the order of prefixes in the option is irrelevant).

For example, for the following case, using `FileCheck --check-prefixes=NO-PHDRS,CHECK` would be the equivalent of the above test case, whilst `FileCheck --check-prefixes=PHDRS,CHECK`  or `FileCheck --check-prefixes=CHECK,PHDRS` would match the program headers followed by the mapping. I think you could even use `FileCheck --check-prefixes=NO-PHDRS,CHECK,PHDRS` to show that the Program Headers appear followed by the mapping, but that no more program headers appear after the mapping (I'm not quite sure whether the first NO-PHDRS-NOT would have any effect in this case though).
```
NO-PHDRS-NOT: Program Headers:
PHDRS: Program Headers:
CHECK: Mapping
NO-PHDRS-NOT: Program Headers:
```



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

https://reviews.llvm.org/D57365





More information about the llvm-commits mailing list