<div dir="ltr">I'm not a fan of passing arbitrary options to the linker from object files. I'd rather have a list of specific instructions for the linker with well defined semantics such as "append this library to list of libraries to link against".<div><br></div><div>What options did you need to handle other than -l?<br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">- Michael Spencer</div></div>
<br><div class="gmail_quote">On Tue, Dec 5, 2017 at 12:21 PM, Saleem Abdulrasool 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">compnerd created this revision.<br>
<br>
Introduce an extension to support passing linker options to the linker.<br>
These would be ignored by older linkers, but newer linkers which<br>
this feature would be able to process the linker.  The section is<br>
simple structure consisting of a version field, an array of strings<br>
terminated by a null string.<br>
<br>
  struct LinkerOptions {<br>
    uint32_t Version;<br>
    const char Options[];<br>
    uint32_t Reserved;<br>
  };<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D40849" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D40849</a><br>
<br>
Files:<br>
  lib/CodeGen/<wbr>TargetLoweringObjectFileImpl.<wbr>cpp<br>
  test/Feature/elf-linker-<wbr>options.ll<br>
<br>
<br>
Index: test/Feature/elf-linker-<wbr>options.ll<br>
==============================<wbr>==============================<wbr>=======<br>
--- /dev/null<br>
+++ test/Feature/elf-linker-<wbr>options.ll<br>
@@ -0,0 +1,14 @@<br>
+; RUN: llc -mtriple i686-unknown-linux-gnu -filetype asm -o - %s | FileCheck %s<br>
+<br>
+!llvm.module.flags = !{!0}<br>
+!llvm.linker.options = !{!2, !3}<br>
+<br>
+!0 = !{i32 1, !"Objective-C Version", i32 2}<br>
+!2 = !{!"spaced", !"option"}<br>
+!3 = !{!"nospace"}<br>
+<br>
+; CHECK: .section ".note.linker-options","",@<wbr>note<br>
+; CHECK: .long 1<br>
+; CHECK: .ascii " spaced option"<br>
+; CHECK: .ascii " nospace"<br>
+; CHECK: .byte 0<br>
Index: lib/CodeGen/<wbr>TargetLoweringObjectFileImpl.<wbr>cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/CodeGen/<wbr>TargetLoweringObjectFileImpl.<wbr>cpp<br>
+++ lib/CodeGen/<wbr>TargetLoweringObjectFileImpl.<wbr>cpp<br>
@@ -93,6 +93,21 @@<br>
<br>
 void TargetLoweringObjectFileELF::<wbr>emitModuleMetadata(<br>
     MCStreamer &Streamer, Module &M, const TargetMachine &TM) const {<br>
+  if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.<wbr>linker.options")) {<br>
+    Streamer.SwitchSection(<wbr>getContext().getELFSection(".<wbr>note.linker-options",<br>
+                                                      ELF::SHT_NOTE, 0));<br>
+    Streamer.EmitIntValue(1, 4);<br>
+    for (const auto &Operand : LinkerOptions->operands()) {<br>
+      std::string Directive;<br>
+      for (const auto &Option : cast<MDNode>(Operand)-><wbr>operands()) {<br>
+        Directive.push_back(' ');<br>
+        Directive.append(cast<<wbr>MDString>(Option)->getString()<wbr>);<br>
+      }<br>
+      Streamer.EmitBytes(Directive);<br>
+    }<br>
+    Streamer.EmitIntValue(0, 1);<br>
+  }<br>
+<br>
   unsigned Version = 0;<br>
   unsigned Flags = 0;<br>
   StringRef Section;<br>
<br>
<br>
</blockquote></div><br></div></div></div>