Skip to content

Commit

Permalink
[BOLT] Update section index for symbols from unemitted functions
Browse files Browse the repository at this point in the history
Summary:
Under some conditions, e.g. while running in lite mode or when a
function is non-simple, BOLT may decide not to emit function code and
hence there's no need to update the symbol. However, since we change
section table, the corresponding section index may need an update.

Also, update section index for ICF symbols.

(cherry picked from FBD21970017)
  • Loading branch information
maksfb committed Jun 10, 2020
1 parent 9bd7161 commit 2d524fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bolt/src/RewriteInstance.cpp
Expand Up @@ -3633,6 +3633,7 @@ void RewriteInstance::updateELFSymbolTable(
.toStringRef(Buf));
ICFSymbol.st_value = ICFParent->getOutputAddress();
ICFSymbol.st_size = ICFParent->getOutputSize();
ICFSymbol.st_shndx = ICFParent->getCodeSection()->getIndex();
Symbols.emplace_back(ICFSymbol);
}
if (Function.isSplit() && Function.cold().getAddress()) {
Expand Down Expand Up @@ -3735,12 +3736,14 @@ void RewriteInstance::updateELFSymbolTable(
auto NewSymbol = Symbol;

if (Function) {
// If the symbol matched a function that was not emitted, leave the
// symbol unchanged.
// If the symbol matched a function that was not emitted, update the
// corresponding section index but otherwise leave it unchanged.
if (Function->isEmitted()) {
NewSymbol.st_value = Function->getOutputAddress();
NewSymbol.st_size = Function->getOutputSize();
NewSymbol.st_shndx = Function->getCodeSection()->getIndex();
} else if (Symbol.st_shndx < ELF::SHN_LORESERVE) {
NewSymbol.st_shndx = NewSectionIndex[Symbol.st_shndx];
}

// Add new symbols to the symbol table if necessary.
Expand Down

0 comments on commit 2d524fd

Please sign in to comment.