[PATCH] D58426: llvm-objcopy: Change sectionWithinSegment() to use virtual addresses instead of file offsets.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 12:56:29 PDT 2019
pcc updated this revision to Diff 191372.
pcc added a comment.
Handle TLS
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D58426/new/
https://reviews.llvm.org/D58426
Files:
llvm/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test
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
@@ -770,13 +770,21 @@
// Returns true IFF a section is wholly inside the range of a segment
static bool sectionWithinSegment(const SectionBase &Section,
const Segment &Segment) {
+ if (!(Section.Flags & SHF_ALLOC))
+ return false;
+
+ bool SectionIsTLS = Section.Flags & SHF_TLS;
+ bool SegmentIsTLS = Segment.Type == PT_TLS;
+ if (SectionIsTLS != SegmentIsTLS)
+ return false;
+
// If a section is empty it should be treated like it has a size of 1. This is
// to clarify the case when an empty section lies on a boundary between two
// segments and ensures that the section "belongs" to the second segment and
// not the first.
uint64_t SecSize = Section.Size ? Section.Size : 1;
- return Segment.Offset <= Section.OriginalOffset &&
- Segment.Offset + Segment.FileSize >= Section.OriginalOffset + SecSize;
+ return Segment.VAddr <= Section.Addr &&
+ Segment.VAddr + Segment.MemSize >= Section.Addr + SecSize;
}
// Returns true IFF a segment's original offset is inside of another segment's
Index: llvm/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test
+++ llvm/test/tools/llvm-objcopy/ELF/segment-test-remove-section.test
@@ -38,6 +38,8 @@
ProgramHeaders:
- Type: PT_LOAD
Flags: [ PF_X, PF_R ]
+ PAddr: 0x1000
+ VAddr: 0x1000
Sections:
- Section: .text
- Section: .text2
@@ -143,8 +145,8 @@
#CHECK-NEXT: ProgramHeader {
#CHECK-NEXT: Type: PT_LOAD (0x1)
#CHECK-NEXT: Offset: 0x1000
-#CHECK-NEXT: VirtualAddress: 0x0
-#CHECK-NEXT: PhysicalAddress: 0x0
+#CHECK-NEXT: VirtualAddress: 0x1000
+#CHECK-NEXT: PhysicalAddress: 0x1000
#CHECK-NEXT: FileSize: 12288
#CHECK-NEXT: MemSize: 12288
#CHECK-NEXT: Flags [ (0x5)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58426.191372.patch
Type: text/x-patch
Size: 2111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190319/6a0398ea/attachment.bin>
More information about the llvm-commits
mailing list