[PATCH] D30770: Ensure that prefix data is preserved with subsections-via-symbols

Moritz Angermann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 28 06:29:45 PDT 2017


angerman added a comment.

The following diff, seems to at least resolve this:

  diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  index ff427c9a0d7..0aca2478cc5 100644
  --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  @@ -655,25 +655,6 @@ void AsmPrinter::EmitFunctionHeader() {
       OutStreamer->GetCommentOS() << '\n';
     }
  
  -  // Emit the prefix data.
  -  if (F->hasPrefixData()) {
  -    if (MAI->hasSubsectionsViaSymbols()) {
  -      // Preserving prefix data on platforms which use subsections-via-symbols
  -      // is a bit tricky. Here we introduce a symbol for the prefix data
  -      // and use the .alt_entry attribute to mark the function's real entry point
  -      // as an alternative entry point to the prefix-data symbol.
  -      MCSymbol *PrefixSym = OutContext.createLinkerPrivateTempSymbol();
  -      OutStreamer->EmitLabel(PrefixSym);
  -
  -      EmitGlobalConstant(F->getParent()->getDataLayout(), F->getPrefixData());
  -
  -      // Emit an .alt_entry directive for the actual function symbol.
  -      OutStreamer->EmitSymbolAttribute(CurrentFnSym, MCSA_AltEntry);
  -    } else {
  -      EmitGlobalConstant(F->getParent()->getDataLayout(), F->getPrefixData());
  -    }
  -  }
  -
     // Emit the CurrentFnSym.  This is a virtual function to allow targets to
     // do their wild and crazy things as required.
     EmitFunctionEntryLabel();
  @@ -725,6 +706,30 @@ void AsmPrinter::EmitFunctionEntryLabel() {
       report_fatal_error("'" + Twine(CurrentFnSym->getName()) +
                          "' label emitted multiple times to assembly file");
  
  +  // Emit the prefix data.
  +  const Function *F = MF->getFunction();
  +  if (F->hasPrefixData()) {
  +    if (MAI->hasSubsectionsViaSymbols()) {
  +      // Preserving prefix data on platforms which use subsections-via-symbols
  +      // is a bit tricky. Here we introduce a symbol for the prefix data
  +      // and use the .alt_entry attribute to mark the function's real entry point
  +      // as an alternative entry point to the prefix-data symbol.
  +
  +      MCSymbol *PrefixSym = OutContext.getOrCreateSymbol(
  +          Twine(CurrentFnSym->getName()) + "$prefix");
  +      PrefixSym->setPrivateExtern(true);
  +
  +      OutStreamer->EmitLabel(PrefixSym);
  +
  +      EmitGlobalConstant(F->getParent()->getDataLayout(), F->getPrefixData());
  +
  +      // Emit an .alt_entry directive for the actual function symbol.
  +      OutStreamer->EmitSymbolAttribute(CurrentFnSym, MCSA_AltEntry);
  +    } else {
  +      EmitGlobalConstant(F->getParent()->getDataLayout(), F->getPrefixData());
  +    }
  +  }
  +
     return OutStreamer->EmitLabel(CurrentFnSym);
   }

There are however a few items I'm a bit unhappy about:

- the prefix data is moved into the `EmitFunctionEntryLabel` from the `EmitFunctionHeader` function; this feels a little off.
- this however ensures that `CurrentFnSym->redefineIfPossible();` is called before `CurrentFnSym->getName()` is used.
- a `$prefix` is appended, which might if one decides to define `@f` with prefix data **and** `@f$prefix` clash.
- The symbol is now set to private extern, and I'm not sure if this is the sweet spot we are looking for.

@pcc if you could spare some feedback on this, that would be great. I'm truly sorry for having missed this case initially.


Repository:
  rL LLVM

https://reviews.llvm.org/D30770





More information about the llvm-commits mailing list