# SEGMENTS-NEXT: :0B001800303132333435363738394090
# SEGMENTS-NEXT: :0400280040414243CE
# SEGMENTS-NEXT: :0B003000505152535455565758596018
+# SEGMENTS-NEXT: :020000040020DA
+# SEGMENTS-NEXT: :03FFF80000000006
# SEGMENTS-NEXT: :0400000500100000E7
# SEGMENTS-NEXT: :00000001FF
+# SEGMENTS-NOT: {{.}}
# 'ExtendedAddr' (04) record shouldn't be created
# PT_NULL-NOT: :02000004
}
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);