[BOLT] Fix TBSS-related issue

Summary:
TLS segment provide a template for initializing thread-local storage
for every new thread. It consists of initialized  and uninitialized
parts. The uninitialized part of TLS, .tbss, is completely meaningless
from a binary analysis perspective. It doesn't take any space in the
file, or in memory. Note that this is different from a regular .bss
section that takes space in memory.

We should not place .tbss into a list of allocatable sections, otherwise
it may cause conflicts with objects contained in the next section.

(cherry picked from FBD9074056)
This commit is contained in:
Maksim Panchenko 2018-07-30 16:30:18 -07:00
parent 771d976543
commit fe9f8219fa
3 changed files with 10 additions and 5 deletions

View File

@ -158,7 +158,7 @@ void BinaryContext::updateObjectNesting(BinaryDataMapType::iterator GAI) {
auto Itr = std::next(GAI);
while (Itr != BinaryDataMap.end() &&
BD->containsRange(Itr->second->getAddress(),
Itr->second->getSize())) {
Itr->second->getSize())) {
Itr->second->Parent = BD;
++Itr;
}
@ -391,7 +391,7 @@ void BinaryContext::postProcessSymbolTable() {
!BD->getSize() &&
!BD->isAbsolute() &&
BD->getSection()) {
errs() << "BOLT-WARNING: zero sized top level symbol: " << *BD << "\n";
errs() << "BOLT-WARNING: zero-sized top level symbol: " << *BD << "\n";
Valid = false;
}
}

View File

@ -113,8 +113,10 @@ void BinaryData::printBrief(raw_ostream &OS) const {
OS << ")";
}
if (opts::Verbosity > 1 && Parent) {
OS << " (" << Parent->getName() << "/" << Parent->getSize() << ")";
if (Parent) {
OS << " (parent: ";
Parent->printBrief(OS);
OS << ")";
}
OS << ", 0x" << Twine::utohexstr(getAddress())

View File

@ -246,6 +246,9 @@ public:
bool isTLS() const {
return (ELFFlags & ELF::SHF_TLS);
}
bool isTBSS() const {
return isBSS() && isTLS();
}
bool isNote() const { return ELFType == ELF::SHT_NOTE; }
bool isStrTab() const { return ELFType == ELF::SHT_STRTAB; }
bool isSymTab() const { return ELFType == ELF::SHT_SYMTAB; }
@ -257,7 +260,7 @@ public:
ELFType == ELF::SHT_PROGBITS);
}
bool isAllocatable() const {
return (ELFFlags & ELF::SHF_ALLOC);
return (ELFFlags & ELF::SHF_ALLOC) && !isTBSS();
}
bool isLocal() const { return IsLocal; }
bool isReordered() const { return IsReordered; }