[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
This commit is contained in:
Georgii Rymar 2020-11-26 13:40:39 +03:00
parent d939ba4c68
commit c2090ff594
2 changed files with 12 additions and 2 deletions

View File

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

View File

@ -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