[llvm] 16f8142 - [llvm-objcopy][ELF] Try fixing non-determinism of Segment::firstSection
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 11 10:20:38 PST 2020
Author: Fangrui Song
Date: 2020-11-11T10:20:30-08:00
New Revision: 16f8142b11598d6d4a4c26333bd3cb9b9f4898f0
URL: https://github.com/llvm/llvm-project/commit/16f8142b11598d6d4a4c26333bd3cb9b9f4898f0
DIFF: https://github.com/llvm/llvm-project/commit/16f8142b11598d6d4a4c26333bd3cb9b9f4898f0.diff
LOG: [llvm-objcopy][ELF] Try fixing non-determinism of Segment::firstSection
Added:
Modified:
llvm/tools/llvm-objcopy/ELF/Object.cpp
llvm/tools/llvm-objcopy/ELF/Object.h
Removed:
################################################################################
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp
index 76db901e4abf..2f455d7ecc1e 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -1775,6 +1775,7 @@ template <class ELFT> Error ELFBuilder<ELFT>::readSectionHeaders() {
Sec->Align = Shdr.sh_addralign;
Sec->EntrySize = Shdr.sh_entsize;
Sec->Index = Index++;
+ Sec->OriginalIndex = Sec->Index;
Sec->OriginalData =
ArrayRef<uint8_t>(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 81851813a3e7..5bd15890e5fe 100644
--- a/llvm/tools/llvm-objcopy/ELF/Object.h
+++ b/llvm/tools/llvm-objcopy/ELF/Object.h
@@ -390,8 +390,8 @@ class SectionBase {
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<uint64_t>::max();
@@ -407,6 +407,7 @@ class SectionBase {
uint64_t Size = 0;
uint64_t Type = ELF::SHT_NULL;
ArrayRef<uint8_t> OriginalData;
+ bool HasSymbol = false;
SectionBase() = default;
SectionBase(const SectionBase &) = default;
@@ -435,9 +436,9 @@ class Segment {
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;
}
};
More information about the llvm-commits
mailing list