[PATCH] D40849: CodeGen: support an extension to pass linker options on ELF

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 5 13:40:56 PST 2017


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".

What options did you need to handle other than -l?

- Michael Spencer

On Tue, Dec 5, 2017 at 12:21 PM, Saleem Abdulrasool via Phabricator <
reviews at reviews.llvm.org> wrote:

> compnerd created this revision.
>
> Introduce an extension to support passing linker options to the linker.
> These would be ignored by older linkers, but newer linkers which
> this feature would be able to process the linker.  The section is
> simple structure consisting of a version field, an array of strings
> terminated by a null string.
>
>   struct LinkerOptions {
>     uint32_t Version;
>     const char Options[];
>     uint32_t Reserved;
>   };
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D40849
>
> Files:
>   lib/CodeGen/TargetLoweringObjectFileImpl.cpp
>   test/Feature/elf-linker-options.ll
>
>
> Index: test/Feature/elf-linker-options.ll
> ===================================================================
> --- /dev/null
> +++ test/Feature/elf-linker-options.ll
> @@ -0,0 +1,14 @@
> +; RUN: llc -mtriple i686-unknown-linux-gnu -filetype asm -o - %s |
> FileCheck %s
> +
> +!llvm.module.flags = !{!0}
> +!llvm.linker.options = !{!2, !3}
> +
> +!0 = !{i32 1, !"Objective-C Version", i32 2}
> +!2 = !{!"spaced", !"option"}
> +!3 = !{!"nospace"}
> +
> +; CHECK: .section ".note.linker-options","", at note
> +; CHECK: .long 1
> +; CHECK: .ascii " spaced option"
> +; CHECK: .ascii " nospace"
> +; CHECK: .byte 0
> Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> ===================================================================
> --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp
> @@ -93,6 +93,21 @@
>
>  void TargetLoweringObjectFileELF::emitModuleMetadata(
>      MCStreamer &Streamer, Module &M, const TargetMachine &TM) const {
> +  if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options"))
> {
> +    Streamer.SwitchSection(getContext().getELFSection(".
> note.linker-options",
> +                                                      ELF::SHT_NOTE, 0));
> +    Streamer.EmitIntValue(1, 4);
> +    for (const auto &Operand : LinkerOptions->operands()) {
> +      std::string Directive;
> +      for (const auto &Option : cast<MDNode>(Operand)->operands()) {
> +        Directive.push_back(' ');
> +        Directive.append(cast<MDString>(Option)->getString());
> +      }
> +      Streamer.EmitBytes(Directive);
> +    }
> +    Streamer.EmitIntValue(0, 1);
> +  }
> +
>    unsigned Version = 0;
>    unsigned Flags = 0;
>    StringRef Section;
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171205/cdbab44b/attachment.html>


More information about the llvm-commits mailing list