Skip to content

Commit

Permalink
[BOLT] Set local symbols in relocation mode to zero
Browse files Browse the repository at this point in the history
Summary:
Strobelight is getting confused by local symbols that we do not
update in relocation mode. These symbols were preserved by the linker in
relocation mode in order support emitting relocations against local
labels, but they are unused.

Issue a quick fix to this by detecting such symbols and setting their
value to zero.

This patch also fixes an issue with the symbol table that was assigning
the wrong section index to symbols associated with the .text section.

(cherry picked from FBD5271277)
  • Loading branch information
rafaelauler authored and maksfb committed Jun 17, 2017
1 parent 59e90f0 commit 3469396
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion bolt/RewriteInstance.cpp
Expand Up @@ -3000,7 +3000,8 @@ void RewriteInstance::patchELFSectionHeaderTable(ELFObjectFile<ELFT> *File) {
// Write all section header entries while patching section references.
for (uint64_t Index = 0; Index < SectionsToWrite.size(); ++Index) {
auto &Section = SectionsToWrite[Index];
if (Section.sh_addr <= NewTextSectionStartAddress &&
if (Section.sh_flags & ELF::SHF_ALLOC &&
Section.sh_addr <= NewTextSectionStartAddress &&
Section.sh_addr + Section.sh_size > NewTextSectionStartAddress) {
NewTextSectionIndex = Index;
}
Expand Down Expand Up @@ -3050,6 +3051,22 @@ void RewriteInstance::patchELFSymTabs(ELFObjectFile<ELFT> *File) {
if (NewSymbol.st_shndx < ELF::SHN_LORESERVE) {
NewSymbol.st_shndx = NewSectionIndex[NewSymbol.st_shndx];
}
// Set to zero local syms in the text section that we didn't update
// and were preserved by the linker to support relocations against
// .text (t15274167).
if (opts::Relocs && NewSymbol.getType() == ELF::STT_NOTYPE &&
NewSymbol.getBinding() == ELF::STB_LOCAL &&
NewSymbol.st_size == 0) {
if (auto SecOrErr =
File->getELFFile()->getSection(NewSymbol.st_shndx)) {
auto Section = *SecOrErr;
if (Section->sh_type == ELF::SHT_PROGBITS &&
Section->sh_flags & ELF::SHF_ALLOC &&
Section->sh_flags & ELF::SHF_EXECINSTR) {
NewSymbol.st_value = 0;
}
}
}
}

if (opts::HotText) {
Expand Down

0 comments on commit 3469396

Please sign in to comment.