[llvm] [llvm][yaml2obj] Modify section header overriding timing (PR #130942)

Ruoyu Qiu via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 3 09:21:44 PDT 2025


================
@@ -179,3 +179,34 @@ ProgramHeaders:
 # RUN:   FileCheck %s --check-prefix=INVALID-OFFSET
 
 # INVALID-OFFSET: yaml2obj: error: 'Offset' for segment with index 1 must be less than or equal to the minimum file offset of all included sections (0x78)
+
+## Document that the "Offset" value should be checked before the section offset is overriden using "ShOffset".
+## And the offset of the first section in a segment should not greater than the offset of the segment.
+# RUN: yaml2obj --docnum=4 %s -o %t5
+# RUN: llvm-readelf %t5 --sections --program-headers | FileCheck %s --check-prefix=SHOFFSET
+
+# SHOFFSET: [Nr] Name Type     Address          Off
+# SHOFFSET: [ 1] .foo PROGBITS 0000000000000000 0000ff
+
+# SHOFFSET:      Type Offset
+# SHOFFSET-NEXT: LOAD 0x000078
+
+--- !ELF
+FileHeader:
+  Class: ELFCLASS64
+  Data:  ELFDATA2LSB
+  Type:  ET_EXEC
+Sections:
+  - Name:     .foo
+    Type:     SHT_PROGBITS
+    Flags:    [ SHF_ALLOC ]
+    Size:     0x1
+## Note: the real .foo offset is much less than 0xFFFFFFFF or
+##       0xFFFFFF00, but no error is reported.
----------------
cabbaken wrote:

I just forgot to remove the comment. 
The origin test seems to be used to show that yaml2obj use `ShOffset` instead of `Offset` to place segments.
Now the purpose of this test is to show the offset of segments is decided by `Offset`, and the output of yaml2obj with this yaml is different now. 
So the comment here is unnecessary now.

https://github.com/llvm/llvm-project/pull/130942


More information about the llvm-commits mailing list