diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2019-05-24 00:21:46 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2019-05-24 00:21:46 +0000 |
commit | ab09cca310e8de1b79766f93b3b83897eabb52dd (patch) | |
tree | 94cd3b9ad6bd3255ad727ebbb1d6aa7d2c6cd5f9 | |
parent | 55229f6b10276526d76f7f6b900053e3c82b5bf7 (diff) | |
download | bcm5719-llvm-ab09cca310e8de1b79766f93b3b83897eabb52dd.tar.gz bcm5719-llvm-ab09cca310e8de1b79766f93b3b83897eabb52dd.zip |
llvm-objcopy: Change sectionWithinSegment() to use virtual addresses instead of file offsets for SHT_NOBITS sections.
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
llvm-svn: 361578
-rw-r--r-- | llvm/tools/llvm-objcopy/ELF/Object.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/ELF/Object.cpp b/llvm/tools/llvm-objcopy/ELF/Object.cpp index 0c80bad6c10..85e7ffa6d8e 100644 --- a/llvm/tools/llvm-objcopy/ELF/Object.cpp +++ b/llvm/tools/llvm-objcopy/ELF/Object.cpp @@ -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; } |