diff options
Diffstat (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r-- | llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 7db949f..fbbd92a 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -306,21 +306,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer, Module &M) const { auto &C = getContext(); - if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) { - auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS, - ELF::SHF_EXCLUDE); - - Streamer.switchSection(S); - - for (const auto *Operand : LinkerOptions->operands()) { - if (cast<MDNode>(Operand)->getNumOperands() != 2) - report_fatal_error("invalid llvm.linker.options"); - for (const auto &Option : cast<MDNode>(Operand)->operands()) { - Streamer.emitBytes(cast<MDString>(Option)->getString()); - Streamer.emitInt8(0); - } - } - } + emitLinkerDirectives(Streamer, M); if (NamedMDNode *DependentLibraries = M.getNamedMetadata("llvm.dependent-libraries")) { auto *S = C.getELFSection(".deplibs", ELF::SHT_LLVM_DEPENDENT_LIBRARIES, @@ -400,6 +386,26 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer, emitCGProfileMetadata(Streamer, M); } +void TargetLoweringObjectFileELF::emitLinkerDirectives(MCStreamer &Streamer, + Module &M) const { + auto &C = getContext(); + if (NamedMDNode *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) { + auto *S = C.getELFSection(".linker-options", ELF::SHT_LLVM_LINKER_OPTIONS, + ELF::SHF_EXCLUDE); + + Streamer.switchSection(S); + + for (const auto *Operand : LinkerOptions->operands()) { + if (cast<MDNode>(Operand)->getNumOperands() != 2) + report_fatal_error("invalid llvm.linker.options"); + for (const auto &Option : cast<MDNode>(Operand)->operands()) { + Streamer.emitBytes(cast<MDString>(Option)->getString()); + Streamer.emitInt8(0); + } + } + } +} + MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol( const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const { @@ -1244,14 +1250,7 @@ MCSection *TargetLoweringObjectFileMachO::getStaticDtorSection( void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer, Module &M) const { // Emit the linker options if present. - if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) { - for (const auto *Option : LinkerOptions->operands()) { - SmallVector<std::string, 4> StrOptions; - for (const auto &Piece : cast<MDNode>(Option)->operands()) - StrOptions.push_back(std::string(cast<MDString>(Piece)->getString())); - Streamer.emitLinkerOptions(StrOptions); - } - } + emitLinkerDirectives(Streamer, M); unsigned VersionVal = 0; unsigned ImageInfoFlags = 0; @@ -1285,6 +1284,18 @@ void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer, Streamer.addBlankLine(); } +void TargetLoweringObjectFileMachO::emitLinkerDirectives(MCStreamer &Streamer, + Module &M) const { + if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) { + for (const auto *Option : LinkerOptions->operands()) { + SmallVector<std::string, 4> StrOptions; + for (const auto &Piece : cast<MDNode>(Option)->operands()) + StrOptions.push_back(std::string(cast<MDString>(Piece)->getString())); + Streamer.emitLinkerOptions(StrOptions); + } + } +} + static void checkMachOComdat(const GlobalValue *GV) { const Comdat *C = GV->getComdat(); if (!C) |