summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp33
1 files changed, 21 insertions, 12 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 3a84bdf94c8..e592442e6bd 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -446,6 +446,19 @@ void CodeGenModule::Release() {
EmitModuleLinkOptions();
}
+ // On ELF we pass the dependent library specifiers directly to the linker
+ // without manipulating them. This is in contrast to other platforms where
+ // they are mapped to a specific linker option by the compiler. This
+ // difference is a result of the greater variety of ELF linkers and the fact
+ // that ELF linkers tend to handle libraries in a more complicated fashion
+ // than on other platforms. This forces us to defer handling the dependent
+ // libs to the linker.
+ if (!ELFDependentLibraries.empty()) {
+ auto *NMD = getModule().getOrInsertNamedMetadata("llvm.dependent-libraries");
+ for (auto *MD : ELFDependentLibraries)
+ NMD->addOperand(MD);
+ }
+
// Record mregparm value now so it is visible through rest of codegen.
if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
@@ -1903,17 +1916,18 @@ void CodeGenModule::AddDetectMismatch(StringRef Name, StringRef Value) {
LinkerOptionsMetadata.push_back(llvm::MDNode::get(getLLVMContext(), MDOpts));
}
-void CodeGenModule::AddELFLibDirective(StringRef Lib) {
+void CodeGenModule::AddDependentLib(StringRef Lib) {
auto &C = getLLVMContext();
- LinkerOptionsMetadata.push_back(llvm::MDNode::get(
- C, {llvm::MDString::get(C, "lib"), llvm::MDString::get(C, Lib)}));
-}
+ if (getTarget().getTriple().isOSBinFormatELF()) {
+ ELFDependentLibraries.push_back(
+ llvm::MDNode::get(C, llvm::MDString::get(C, Lib)));
+ return;
+ }
-void CodeGenModule::AddDependentLib(StringRef Lib) {
llvm::SmallString<24> Opt;
getTargetCodeGenInfo().getDependentLibraryOption(Lib, Opt);
auto *MDOpts = llvm::MDString::get(getLLVMContext(), Opt);
- LinkerOptionsMetadata.push_back(llvm::MDNode::get(getLLVMContext(), MDOpts));
+ LinkerOptionsMetadata.push_back(llvm::MDNode::get(C, MDOpts));
}
/// Add link options implied by the given module, including modules
@@ -1936,7 +1950,6 @@ static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod,
// described by this module.
llvm::LLVMContext &Context = CGM.getLLVMContext();
bool IsELF = CGM.getTarget().getTriple().isOSBinFormatELF();
- bool IsPS4 = CGM.getTarget().getTriple().isPS4();
// For modules that use export_as for linking, use that module
// name instead.
@@ -1956,7 +1969,7 @@ static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod,
}
// Link against a library.
- if (IsELF && !IsPS4) {
+ if (IsELF) {
llvm::Metadata *Args[2] = {
llvm::MDString::get(Context, "lib"),
llvm::MDString::get(Context, Mod->LinkLibraries[I - 1].Library),
@@ -5197,10 +5210,6 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) {
AppendLinkerOptions(PCD->getArg());
break;
case PCK_Lib:
- if (getTarget().getTriple().isOSBinFormatELF() &&
- !getTarget().getTriple().isPS4())
- AddELFLibDirective(PCD->getArg());
- else
AddDependentLib(PCD->getArg());
break;
case PCK_Compiler:
OpenPOWER on IntegriCloud