Skip to content

Commit

Permalink
llvm-objcopy: Change sectionWithinSegment() to use virtual addresses …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
pcc committed May 24, 2019
1 parent 55229f6 commit ab09cca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions llvm/tools/llvm-objcopy/ELF/Object.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit ab09cca

Please sign in to comment.