From 16f8142b11598d6d4a4c26333bd3cb9b9f4898f0 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 11 Nov 2020 10:20:30 -0800 Subject: [PATCH] [llvm-objcopy][ELF] Try fixing non-determinism of Segment::firstSection --- llvm/tools/llvm-objcopy/ELF/Object.cpp | 1 + llvm/tools/llvm-objcopy/ELF/Object.h | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp index 76db901..2f455d7 100644 --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -1775,6 +1775,7 @@ template Error ELFBuilder::readSectionHeaders() { Sec->Align = Shdr.sh_addralign; Sec->EntrySize = Shdr.sh_entsize; Sec->Index = Index++; + Sec->OriginalIndex = Sec->Index; Sec->OriginalData = ArrayRef(ElfFile.base() + Shdr.sh_offset, (Shdr.sh_type == SHT_NOBITS) ? 0 : Shdr.sh_size); diff --git a/llvm/tools/llvm-objcopy/ELF/Object.h b/llvm/tools/llvm-objcopy/ELF/Object.h index 8185181..5bd1589 100644 --- a/llvm/tools/llvm-objcopy/ELF/Object.h +++ b/llvm/tools/llvm-objcopy/ELF/Object.h @@ -390,8 +390,8 @@ public: Segment *ParentSegment = nullptr; uint64_t HeaderOffset = 0; uint32_t Index = 0; - bool HasSymbol = false; + uint32_t OriginalIndex = 0; uint64_t OriginalFlags = 0; uint64_t OriginalType = ELF::SHT_NULL; uint64_t OriginalOffset = std::numeric_limits::max(); @@ -407,6 +407,7 @@ public: uint64_t Size = 0; uint64_t Type = ELF::SHT_NULL; ArrayRef OriginalData; + bool HasSymbol = false; SectionBase() = default; SectionBase(const SectionBase &) = default; @@ -435,9 +436,9 @@ private: bool operator()(const SectionBase *Lhs, const SectionBase *Rhs) const { // Some sections might have the same address if one of them is empty. To // fix this we can use the lexicographic ordering on ->Addr and the - // address of the actully stored section. + // original index. if (Lhs->OriginalOffset == Rhs->OriginalOffset) - return Lhs < Rhs; + return Lhs->OriginalIndex < Rhs->OriginalIndex; return Lhs->OriginalOffset < Rhs->OriginalOffset; } }; -- 2.7.4