<div dir="ltr">I can't seem to reproduce this on my Mac.<div><br></div>$ ~/src/llvm-project/ra/bin/<wbr>clang -c lib.ll -o lib.o<br>warning: overriding the module target triple with x86_64-apple-macosx10.12.0 [-Woverride-module]<br>1 warning generated.<br>$ ~/src/llvm-project/ra/bin/<wbr>clang dont.ll lib.o -o dont -Wl,-dead_strip<br>warning: overriding the module target triple with x86_64-apple-macosx10.12.0 [-Woverride-module]<br>1 warning generated.<br>$ ./dont<br>$ echo $?<br>123<br>$ cat lib.ll<br>  define void @f() prefix i32 123 {<br>   ret void<br>  }<br><br>$ cat dont.ll<br>  declare void @f();<br><br>  define i32 @main() {<br>   %f = bitcast void ()* @f to i32*<br>   %prefix_ptr = getelementptr inbounds i32, i32* %f, i32 -1<br>   %prefix_val = load i32, i32* %prefix_ptr<br>   ret i32 %prefix_val<br>  }<div><br></div><div>Which version of ld64 are you using? (I'm using 278.4 here.) I'd make sure that it isn't too old to support .alt_entry.</div><div><br></div><div>In any event, I'm not sure if your patch is correct. In addition to the points you made, declaring the prefix symbol like that could lead to symbol conflicts if a function with prefix data has internal linkage and has the same name as another function with internal linkage in another object file.</div><div><br></div><div>Peter <br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 28, 2017 at 6:29 AM, Moritz Angermann via Phabricator <span dir="ltr"><<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">angerman added a comment.<br>
<br>
The following diff, seems to at least resolve this:<br>
<br>
  diff --git a/lib/CodeGen/AsmPrinter/<wbr>AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/<wbr>AsmPrinter.cpp<br>
  index ff427c9a0d7..0aca2478cc5 100644<br>
  --- a/lib/CodeGen/AsmPrinter/<wbr>AsmPrinter.cpp<br>
  +++ b/lib/CodeGen/AsmPrinter/<wbr>AsmPrinter.cpp<br>
  @@ -655,25 +655,6 @@ void AsmPrinter::<wbr>EmitFunctionHeader() {<br>
       OutStreamer->GetCommentOS() << '\n';<br>
     }<br>
<br>
  -  // Emit the prefix data.<br>
  -  if (F->hasPrefixData()) {<br>
  -    if (MAI-><wbr>hasSubsectionsViaSymbols()) {<br>
  -      // Preserving prefix data on platforms which use subsections-via-symbols<br>
  -      // is a bit tricky. Here we introduce a symbol for the prefix data<br>
  -      // and use the .alt_entry attribute to mark the function's real entry point<br>
  -      // as an alternative entry point to the prefix-data symbol.<br>
  -      MCSymbol *PrefixSym = OutContext.<wbr>createLinkerPrivateTempSymbol(<wbr>);<br>
  -      OutStreamer->EmitLabel(<wbr>PrefixSym);<br>
  -<br>
<span class="">  -      EmitGlobalConstant(F-><wbr>getParent()->getDataLayout(), F->getPrefixData());<br>
</span>  -<br>
  -      // Emit an .alt_entry directive for the actual function symbol.<br>
  -      OutStreamer-><wbr>EmitSymbolAttribute(<wbr>CurrentFnSym, MCSA_AltEntry);<br>
  -    } else {<br>
<span class="">  -      EmitGlobalConstant(F-><wbr>getParent()->getDataLayout(), F->getPrefixData());<br>
</span>  -    }<br>
  -  }<br>
  -<br>
<span class="">     // Emit the CurrentFnSym.  This is a virtual function to allow targets to<br>
     // do their wild and crazy things as required.<br>
</span>     EmitFunctionEntryLabel();<br>
  @@ -725,6 +706,30 @@ void AsmPrinter::<wbr>EmitFunctionEntryLabel() {<br>
       report_fatal_error("'" + Twine(CurrentFnSym->getName()) +<br>
                          "' label emitted multiple times to assembly file");<br>
<br>
  +  // Emit the prefix data.<br>
  +  const Function *F = MF->getFunction();<br>
<span class="">  +  if (F->hasPrefixData()) {<br>
  +    if (MAI-><wbr>hasSubsectionsViaSymbols()) {<br>
  +      // Preserving prefix data on platforms which use subsections-via-symbols<br>
  +      // is a bit tricky. Here we introduce a symbol for the prefix data<br>
  +      // and use the .alt_entry attribute to mark the function's real entry point<br>
  +      // as an alternative entry point to the prefix-data symbol.<br>
  +<br>
</span>  +      MCSymbol *PrefixSym = OutContext.getOrCreateSymbol(<br>
  +          Twine(CurrentFnSym->getName()) + "$prefix");<br>
  +      PrefixSym->setPrivateExtern(<wbr>true);<br>
  +<br>
<span class="">  +      OutStreamer->EmitLabel(<wbr>PrefixSym);<br>
  +<br>
  +      EmitGlobalConstant(F-><wbr>getParent()->getDataLayout(), F->getPrefixData());<br>
  +<br>
  +      // Emit an .alt_entry directive for the actual function symbol.<br>
  +      OutStreamer-><wbr>EmitSymbolAttribute(<wbr>CurrentFnSym, MCSA_AltEntry);<br>
  +    } else {<br>
  +      EmitGlobalConstant(F-><wbr>getParent()->getDataLayout(), F->getPrefixData());<br>
  +    }<br>
  +  }<br>
</span>  +<br>
     return OutStreamer->EmitLabel(<wbr>CurrentFnSym);<br>
   }<br>
<br>
There are however a few items I'm a bit unhappy about:<br>
<br>
- the prefix data is moved into the `EmitFunctionEntryLabel` from the `EmitFunctionHeader` function; this feels a little off.<br>
- this however ensures that `CurrentFnSym-><wbr>redefineIfPossible();` is called before `CurrentFnSym->getName()` is used.<br>
- a `$prefix` is appended, which might if one decides to define `@f` with prefix data **and** `@f$prefix` clash.<br>
- The symbol is now set to private extern, and I'm not sure if this is the sweet spot we are looking for.<br>
<br>
@pcc if you could spare some feedback on this, that would be great. I'm truly sorry for having missed this case initially.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D30770" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D30770</a><br>
<br>
<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>