Skip to content

Commit

Permalink
[BOLT] Emit symbol size for functions
Browse files Browse the repository at this point in the history
Summary:
On targets that support it, emit size of the emitted function symbol.

At the moment there's no use for the size except that it is visible in a
temporary .o file symbol table.

(cherry picked from FBD24246177)
  • Loading branch information
maksfb committed Oct 12, 2020
1 parent 528da5d commit 247b418
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions bolt/src/BinaryEmitter.cpp
Expand Up @@ -290,16 +290,19 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
MCContext &Context = Streamer.getContext();
const MCAsmInfo *MAI = Context.getAsmInfo();

MCSymbol *StartSymbol = nullptr;

// Emit all symbols associated with the main function entry.
if (!EmitColdPart) {
for (auto *Symbol : Function.getSymbols()) {
StartSymbol = Function.getSymbol();
for (MCSymbol *Symbol : Function.getSymbols()) {
Streamer.EmitSymbolAttribute(Symbol, MCSA_ELF_TypeFunction);
Streamer.EmitLabel(Symbol);
}
} else {
auto *Symbol = Function.getColdSymbol();
Streamer.EmitSymbolAttribute(Symbol, MCSA_ELF_TypeFunction);
Streamer.EmitLabel(Symbol);
StartSymbol = Function.getColdSymbol();
Streamer.EmitSymbolAttribute(StartSymbol, MCSA_ELF_TypeFunction);
Streamer.EmitLabel(StartSymbol);
}

// Emit CFI start
Expand Down Expand Up @@ -358,8 +361,16 @@ bool BinaryEmitter::emitFunction(BinaryFunction &Function, bool EmitColdPart) {
if (Function.hasCFI())
Streamer.EmitCFIEndProc();

Streamer.EmitLabel(EmitColdPart ? Function.getFunctionColdEndLabel()
: Function.getFunctionEndLabel());
MCSymbol *EndSymbol = EmitColdPart ? Function.getFunctionColdEndLabel()
: Function.getFunctionEndLabel();
Streamer.EmitLabel(EndSymbol);

if (MAI->hasDotTypeDotSizeDirective()) {
const MCExpr *SizeExpr = MCBinaryExpr::createSub(
MCSymbolRefExpr::create(EndSymbol, Context),
MCSymbolRefExpr::create(StartSymbol, Context), Context);
Streamer.emitELFSize(StartSymbol, SizeExpr);
}

// Exception handling info for the function.
emitLSDA(Function, EmitColdPart);
Expand Down

0 comments on commit 247b418

Please sign in to comment.