[PATCH] D92163: [obj2yaml] - Don't assert when trying to calculate the expected section offset.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 26 02:47:55 PST 2020


grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added a subscriber: emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
grimar requested review of this revision.

The following line asserts when `sh_addralign > MAX_UINT32 && (uint32_t)sh_addralign == 0`:

  ExpectedOffset = alignTo(ExpectedOffset,
                           SecHdr.sh_addralign ? SecHdr.sh_addralign : 1);

it happens because `sh_addralign` is truncated to 32-bit value, but `alignTo`
doesn't accept `Align == 0`. We should change `1` to `1uLL`.


https://reviews.llvm.org/D92163

Files:
  llvm/test/tools/obj2yaml/ELF/offset.yaml
  llvm/tools/obj2yaml/elf2yaml.cpp


Index: llvm/tools/obj2yaml/elf2yaml.cpp
===================================================================
--- llvm/tools/obj2yaml/elf2yaml.cpp
+++ llvm/tools/obj2yaml/elf2yaml.cpp
@@ -248,8 +248,8 @@
     ELFYAML::Section &Sec = *cast<ELFYAML::Section>(C.get());
     const typename ELFT::Shdr &SecHdr = S[Sec.OriginalSecNdx];
 
-    ExpectedOffset =
-        alignTo(ExpectedOffset, SecHdr.sh_addralign ? SecHdr.sh_addralign : 1);
+    ExpectedOffset = alignTo(ExpectedOffset,
+                             SecHdr.sh_addralign ? SecHdr.sh_addralign : 1uLL);
 
     // We only set the "Offset" field when it can't be naturally derived
     // from the offset and size of the previous section. This reduces
Index: llvm/test/tools/obj2yaml/ELF/offset.yaml
===================================================================
--- llvm/test/tools/obj2yaml/ELF/offset.yaml
+++ llvm/test/tools/obj2yaml/ELF/offset.yaml
@@ -32,6 +32,10 @@
 # BASIC-NEXT:     Type:         SHT_PROGBITS
 # BASIC-NEXT:     AddressAlign: 0x10
 # BASIC-NEXT:     Offset:       0x200
+# BASIC-NEXT:   - Name:         .bar4
+# BASIC-NEXT:     Type:         SHT_PROGBITS
+# BASIC-NEXT:     AddressAlign: 0x100000000
+# BASIC-NEXT:     Offset:       0x210
 
 --- !ELF
 FileHeader:
@@ -81,6 +85,12 @@
     Type:         SHT_PROGBITS
     AddressAlign: 0x10
     Offset:       0x200
+## A case where AddressAlign > MAX_UINT32 and (uint32_t)AddressAlign == 0.
+## Check we dump an offset in this case properly.
+  - Name:         .bar4
+    Type:         SHT_PROGBITS
+    AddressAlign: 0x100000000
+    Offset:       0x210
 
 ## Show we dump the "Offset" key for the first section when
 ## it has an unexpected file offset.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92163.307806.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201126/70875960/attachment.bin>


More information about the llvm-commits mailing list