[llvm-branch-commits] [llvm] c2090ff - [obj2yaml] - Don't assert when trying to calculate the expected section offset.

Georgii Rymar via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 27 04:49:57 PST 2020


Author: Georgii Rymar
Date: 2020-11-27T15:38:22+03:00
New Revision: c2090ff5942269c391c549f432258e4fd2fa12cb

URL: https://github.com/llvm/llvm-project/commit/c2090ff5942269c391c549f432258e4fd2fa12cb
DIFF: https://github.com/llvm/llvm-project/commit/c2090ff5942269c391c549f432258e4fd2fa12cb.diff

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

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`.

Differential revision: https://reviews.llvm.org/D92163

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/obj2yaml/ELF/offset.yaml b/llvm/test/tools/obj2yaml/ELF/offset.yaml
index 417c92aed1f8..2dc04b617417 100644
--- a/llvm/test/tools/obj2yaml/ELF/offset.yaml
+++ b/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 @@ Sections:
     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.

diff  --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 3aa74bab0c18..4d8d471817ac 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -248,8 +248,8 @@ static void dumpSectionOffsets(const typename ELFT::Ehdr &Header,
     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


        


More information about the llvm-branch-commits mailing list