From 2d524fd5e22f2faea123566ac1b21b7e0a5d0b53 Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Tue, 9 Jun 2020 19:12:06 -0700 Subject: [PATCH] [BOLT] Update section index for symbols from unemitted functions 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) --- bolt/src/RewriteInstance.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bolt/src/RewriteInstance.cpp b/bolt/src/RewriteInstance.cpp index 8dd5f79bd357..fbbb5f2fe550 100644 --- a/bolt/src/RewriteInstance.cpp +++ b/bolt/src/RewriteInstance.cpp @@ -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()) { @@ -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.