mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-20 19:04:10 -04:00
CodeGen: support an extension to pass linker options on ELF
Introduce an extension to support passing linker options to the linker. These would be ignored by older linkers, but newer linkers which support this feature would be able to process the linker. Emit a special discarded section `.linker-option`. The content of this section is a pair of strings (key, value). The key is a type identifier for the parameter. This allows for an argument free parameter that will be processed by the linker with the value being the parameter. As an example, `lib` identifies a library to be linked against, traditionally the `-l` argument for Unix-based linkers with the parameter being the library name. Thanks to James Henderson, Cary Coutant, Rafael Espinolda, Sean Silva for the valuable discussion on the design of this feature. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323783 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -93,6 +93,24 @@ static void GetObjCImageInfo(Module &M, unsigned &Version, unsigned &Flags,
|
||||
|
||||
void TargetLoweringObjectFileELF::emitModuleMetadata(
|
||||
MCStreamer &Streamer, Module &M, const TargetMachine &TM) 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.EmitIntValue(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned Version = 0;
|
||||
unsigned Flags = 0;
|
||||
StringRef Section;
|
||||
@@ -101,7 +119,6 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(
|
||||
if (Section.empty())
|
||||
return;
|
||||
|
||||
auto &C = getContext();
|
||||
auto *S = C.getELFSection(Section, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
|
||||
Streamer.SwitchSection(S);
|
||||
Streamer.EmitLabel(C.getOrCreateSymbol(StringRef("OBJC_IMAGE_INFO")));
|
||||
|
||||
Reference in New Issue
Block a user