From 247b4181a306aff348c1d2d8c3847280866a7f32 Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Mon, 12 Oct 2020 13:02:50 -0700 Subject: [PATCH] [BOLT] Emit symbol size for functions 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) --- bolt/src/BinaryEmitter.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bolt/src/BinaryEmitter.cpp b/bolt/src/BinaryEmitter.cpp index 9143f88b1066..0fa5774100a8 100644 --- a/bolt/src/BinaryEmitter.cpp +++ b/bolt/src/BinaryEmitter.cpp @@ -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 @@ -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);