]> granicus.if.org Git - llvm/commitdiff
llvm-objcopy: Change sectionWithinSegment() to use virtual addresses instead of file...
authorPeter Collingbourne <peter@pcc.me.uk>
Fri, 24 May 2019 00:21:46 +0000 (00:21 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Fri, 24 May 2019 00:21:46 +0000 (00:21 +0000)
Without this, sectionWithinSegment() will return the wrong answer for bss
sections. This doesn't seem to matter now (for non-broken ELF files), but
it will matter with a change that I'm working on.

Differential Revision: https://reviews.llvm.org/D58426

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361578 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-objcopy/ELF/Object.cpp

index 0c80bad6c102d063b385b7d7e0b31777ddc5249b..85e7ffa6d8ecb0f612e1e046eab0b68ae8b5cbe8 100644 (file)
@@ -809,6 +809,20 @@ static bool sectionWithinSegment(const SectionBase &Section,
   // segments and ensures that the section "belongs" to the second segment and
   // not the first.
   uint64_t SecSize = Section.Size ? Section.Size : 1;
+
+  if (Section.Type == SHT_NOBITS) {
+    if (!(Section.Flags & SHF_ALLOC))
+      return false;
+
+    bool SectionIsTLS = Section.Flags & SHF_TLS;
+    bool SegmentIsTLS = Segment.Type == PT_TLS;
+    if (SectionIsTLS != SegmentIsTLS)
+      return false;
+
+    return Segment.VAddr <= Section.Addr &&
+           Segment.VAddr + Segment.MemSize >= Section.Addr + SecSize;
+  }
+
   return Segment.Offset <= Section.OriginalOffset &&
          Segment.Offset + Segment.FileSize >= Section.OriginalOffset + SecSize;
 }