[llvm] [llvm][yaml2obj] Modify section header overriding timing (PR #130942)
Ruoyu Qiu via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 17 03:24:19 PDT 2025
cabbaken wrote:
> I _think_ the test is just using `ShOffset` when it should be using `Offset` instead. I'm not 100% certain about this though and would like @MaskRay to take a look if he gets a chance. Does changing that help fix any issues?
Yes, this fixed this test.
> > And I also found another two failed tests
> > ```
> > * [`tools/llvm-readobj/ELF/malformed-pt-dynamic.test`](https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test#L43): Failed because it assumes `p_offset` is determined by `sh_offset`.
> > ```
>
> I think the fix here is to avoid this assumption somehow. The test itself is fine, it's just the change in yaml2obj behaviour means we need a different way of forcing the p_offset value. I believe you can fix this test by removing the ShOffset field and replacing it with an Offset field in the program header description.
I tried to fix this tests, but I got
```
yaml2obj: error: 'Offset' for segment with index 1 must be less than or equal to the minimum file offset of all included sections (0x1000)
```
in [malformed-pt-dynamic.test](https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test) with `-DOFFSET=0x1131`
```diff
--- a/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test
+++ b/llvm/test/tools/llvm-readobj/ELF/malformed-pt-dynamic.test
@@ -133,7 +133,6 @@ Sections:
Type: SHT_DYNAMIC
Address: 0x1000
Offset: 0x1000
- ShOffset: [[OFFSET=<none>]]
Entries:
- Tag: DT_NULL
Value: 0
@@ -142,5 +141,6 @@ Sections:
ProgramHeaders:
- Type: PT_DYNAMIC
FileSize: [[FILESIZE=<none>]]
+ Offset: [[OFFSET=<none>]]
FirstSec: .dynamic
LastSec: .dynamic
```
This occurs because there is a check when the program header offset is explicitly defined. It seems that `yaml2obj` is unable to generate a valid elf for analogous tests. But `llvm-readobj` itself needs this test. What is your advice?
> > ```
> > * [`tools/obj2yaml/ELF/program-headers.yaml`](https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/obj2yaml/ELF/program-headers.yaml#L437): Failed due to a mismatch between the overridden `sh_offset` and the corresponding `p_offset`.
> > ```
>
> The line number reference here didn't make sense to me for the description you've mentioned. Are you referring to the bar/zed sections at
>
> https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/obj2yaml/ELF/program-headers.yaml#L570
>
> and the check at line 533? If so, I'm not sure what the fix should be here. Changing `ShOffset` to `Offset` in the zed section description might work, but I'm not sure if it will or not (it might result in a different error). If that doesn't work, you might be able to use the [SectionHeaderTable field](https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/yaml2obj/ELF/section-headers.yaml) in the YAML to reorder the section headers: put the zed section first in the Sections: list in the YAML, without any specific offset (but a non-zero size), followed by bar, but then in the SectionHeaderTable listing, specify the sections in the opposite order. You might need to break the individual test case into two parts, with two different YAMLs, each for one of the warning messages. Aside: this test case is in the wrong directory, as it's purely a yaml2obj test, not an obj2yaml one. I'm not sure it's worth moving though.
And about `[tools/obj2yaml/ELF/program-headers.yaml]`(https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/obj2yaml/ELF/program-headers.yaml#L437), the real failed point is [here](https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/obj2yaml/ELF/program-headers.yaml#L437). I am sorry that I didn't do some detailed explaination. This test failed because the miss of all `.bss`, such as:
```diff
# NOBITS-NEXT: FirstSec: .bss
# NOBITS-NEXT: LastSec: .bss
```
and it will continue to fail [here](https://github.com/llvm/llvm-project/blob/main/llvm/test/tools/obj2yaml/ELF/program-headers.yaml#L533):
```diff
# UNSORTED-NEXT: error: sections in the program header with index 3 are not sorted by their file offset
```
https://github.com/llvm/llvm-project/pull/130942
More information about the llvm-commits
mailing list