[PATCH] D78786: [llvm-objcopy] Delete dead code after D71035. NFC
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 21:10:48 PDT 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson.
Herald added subscribers: llvm-commits, abrachet, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a reviewer: rupprecht.
Herald added a project: LLVM.
MaskRay edited the summary of this revision.
Spotted by https://reviews.llvm.org/D74755#1998673
> it looks like OrderedSegments in the function is only used to set the physical address to the virtual address when there are no physical addresses set amongst these sections.
I believe this behavior was copied from https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=6ffd79000b45e77b3625143932ffbf781b6aecab (2008-05)
The commit was made for very old linkers.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D78786
Files:
llvm/tools/llvm-objcopy/ELF/Object.cpp
Index: llvm/tools/llvm-objcopy/ELF/Object.cpp
===================================================================
--- llvm/tools/llvm-objcopy/ELF/Object.cpp
+++ llvm/tools/llvm-objcopy/ELF/Object.cpp
@@ -1101,14 +1101,6 @@
return A->Index < B->Index;
}
-static bool compareSegmentsByPAddr(const Segment *A, const Segment *B) {
- if (A->PAddr < B->PAddr)
- return true;
- if (A->PAddr > B->PAddr)
- return false;
- return A->Index < B->Index;
-}
-
void BasicELFBuilder::initFileHeader() {
Obj->Flags = 0x0;
Obj->Type = ET_REL;
@@ -2228,30 +2220,20 @@
// so that we know that anytime ->ParentSegment is set that segment has
// already had it's offset properly set. We only want to consider the segments
// that will affect layout of allocated sections so we only add those.
- std::vector<Segment *> OrderedSegments;
+ std::vector<Segment *> Segments;
for (const SectionBase &Sec : Obj.allocSections())
if (Sec.ParentSegment != nullptr)
- OrderedSegments.push_back(Sec.ParentSegment);
+ Segments.push_back(Sec.ParentSegment);
// For binary output, we're going to use physical addresses instead of
// virtual addresses, since a binary output is used for cases like ROM
// loading and physical addresses are intended for ROM loading.
// However, if no segment has a physical address, we'll fallback to using
// virtual addresses for all.
- if (all_of(OrderedSegments,
- [](const Segment *Seg) { return Seg->PAddr == 0; }))
- for (Segment *Seg : OrderedSegments)
+ if (all_of(Segments, [](const Segment *Seg) { return Seg->PAddr == 0; }))
+ for (Segment *Seg : Segments)
Seg->PAddr = Seg->VAddr;
- llvm::stable_sort(OrderedSegments, compareSegmentsByPAddr);
-
- // Because we add a ParentSegment for each section we might have duplicate
- // segments in OrderedSegments. If there were duplicates then layoutSegments
- // would do very strange things.
- auto End =
- std::unique(std::begin(OrderedSegments), std::end(OrderedSegments));
- OrderedSegments.erase(End, std::end(OrderedSegments));
-
// Compute the section LMA based on its sh_offset and the containing segment's
// p_offset and p_paddr. Also compute the minimum LMA of all sections as
// MinAddr. In the output, the contents between address 0 and MinAddr will be
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78786.259794.patch
Type: text/x-patch
Size: 2335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200424/85fdad46/attachment-0001.bin>
More information about the llvm-commits
mailing list