diff options
author | Jason Eckhardt <jeckhardt@nvidia.com> | 2025-01-21 18:24:33 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-21 18:24:33 -0600 |
commit | 7cf8addc2d487154dfb65db70829abc943345302 (patch) | |
tree | 168fd56b9086dd4673b722026739b9bf59c704fb /llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | |
parent | 6ab9dafec807a64a4e940bfaecc815e23454dfe8 (diff) | |
download | llvm-7cf8addc2d487154dfb65db70829abc943345302.zip llvm-7cf8addc2d487154dfb65db70829abc943345302.tar.gz llvm-7cf8addc2d487154dfb65db70829abc943345302.tar.bz2 |
[TLOF][NFC] Make emitLinkerDirectives virtual and public. (#123773)
Today, emitLinkerDirectives is private to TLOFCOFF-- it isolates parsing
and processing of the linker options. Similar processing is also done by
other TLOFs inline within emitModuleMetadata. This patch promotes
emitLinkerDirectives to a virtual (public) method so that this handling
is similarly isolated in the other TLOFs.
This also enables downstream targets to override just this handling
instead of the whole of emitModuleMetadata.
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) |