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(Operand)->operands()) { + Directive.push_back(' '); + Directive.append(cast(Option)->getString()); + } + Streamer.EmitBytes(Directive); + } + Streamer.EmitIntValue(0, 1); + } + unsigned Version = 0; unsigned Flags = 0; StringRef Section; Index: test/Feature/elf-linker-options.ll =================================================================== --- /dev/null +++ test/Feature/elf-linker-options.ll @@ -0,0 +1,12 @@ +; RUN: llc -mtriple i686-unknown-linux-gnu -filetype asm -o - %s | FileCheck %s + +!llvm.linker.options = !{!0, !1} + +!0 = !{!"spaced", !"option"} +!1 = !{!"nospace"} + +; CHECK: .section ".note.linker-options","",@note +; CHECK: .long 1 +; CHECK: .ascii " spaced option" +; CHECK: .ascii " nospace" +; CHECK: .byte 0