diff options
author | Fangrui Song <i@maskray.me> | 2021-06-16 10:08:20 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2021-06-16 10:08:20 -0700 |
commit | 1de18ad8d79eb328ad410fa60209e5dfa19752c8 (patch) | |
tree | db67bfd7889ee7824e56a7594e4b7efb16c993ec /llvm/tools/llvm-objcopy/ELF/Object.cpp | |
parent | 2193347e72fad6a78ce4a96c8d89f9a43a028e79 (diff) | |
download | llvm-1de18ad8d79eb328ad410fa60209e5dfa19752c8.zip llvm-1de18ad8d79eb328ad410fa60209e5dfa19752c8.tar.gz llvm-1de18ad8d79eb328ad410fa60209e5dfa19752c8.tar.bz2 |
[llvm-objcopy] Make ihex writer similar to binary writer
There is no need to differentiate whether `UseSegments` is true or
false. Unifying the cases makes the behavior closer to BinaryWriter.
This improves compatibility with objcopy because SHF_ALLOC sections not in
a PT_LOAD will not be skipped. Such cases are usually erroneous input, though.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D104186
Diffstat (limited to 'llvm/tools/llvm-objcopy/ELF/Object.cpp')
-rw-r--r-- | llvm/tools/llvm-objcopy/ELF/Object.cpp | 21 |
1 files changed, 2 insertions, 19 deletions
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp index 7b34110..5f1b4c3 100644 --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -2666,32 +2666,15 @@ Error IHexWriter::checkSection(const SectionBase &Sec) { } Error IHexWriter::finalize() { - bool UseSegments = false; - auto ShouldWrite = [](const SectionBase &Sec) { - return (Sec.Flags & ELF::SHF_ALLOC) && Sec.Type != ELF::SHT_NOBITS && - Sec.Size > 0; - }; - auto IsInPtLoad = [](const SectionBase &Sec) { - return Sec.ParentSegment && Sec.ParentSegment->Type == ELF::PT_LOAD; - }; - // We can't write 64-bit addresses. if (addressOverflows32bit(Obj.Entry)) return createStringError(errc::invalid_argument, "Entry point address 0x%llx overflows 32 bits", Obj.Entry); - // If any section we're to write has segment then we - // switch to using physical addresses. Otherwise we - // use section virtual address. - for (const SectionBase &Sec : Obj.sections()) - if (ShouldWrite(Sec) && IsInPtLoad(Sec)) { - UseSegments = true; - break; - } - for (const SectionBase &Sec : Obj.sections()) - if (ShouldWrite(Sec) && (!UseSegments || IsInPtLoad(Sec))) { + if ((Sec.Flags & ELF::SHF_ALLOC) && Sec.Type != ELF::SHT_NOBITS && + Sec.Size > 0) { if (Error E = checkSection(Sec)) return E; Sections.insert(&Sec); |