diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 18 | ||||
-rw-r--r-- | lib/LTO/LTOModule.cpp | 29 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 60e74cf8ef..3621b58287 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -402,6 +402,16 @@ TargetLoweringObjectFileELF::InitializeELF(bool UseInitArray_) { // MachO //===----------------------------------------------------------------------===// +/// getDepLibFromLinkerOpt - Extract the dependent library name from a linker +/// option string. Returns StringRef() if the option does not specify a library. +StringRef TargetLoweringObjectFileMachO:: +getDepLibFromLinkerOpt(StringRef LinkerOption) const { + const char *LibCmd = "-l"; + if (LinkerOption.startswith(LibCmd)) + return LinkerOption.substr(strlen(LibCmd)); + return StringRef(); +} + /// emitModuleFlags - Perform code emission for module flags. void TargetLoweringObjectFileMachO:: emitModuleFlags(MCStreamer &Streamer, @@ -774,6 +784,14 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, return DataSection; } +StringRef TargetLoweringObjectFileCOFF:: +getDepLibFromLinkerOpt(StringRef LinkerOption) const { + const char *LibCmd = "/DEFAULTLIB:"; + if (LinkerOption.startswith(LibCmd)) + return LinkerOption.substr(strlen(LibCmd)); + return StringRef(); +} + void TargetLoweringObjectFileCOFF:: emitModuleFlags(MCStreamer &Streamer, ArrayRef<Module::ModuleFlagEntry> ModuleFlags, diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 79cff1f68f..f73a608e3c 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -18,6 +18,7 @@ #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Constants.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" @@ -37,6 +38,8 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" +#include "llvm/Target/TargetLowering.h" +#include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetRegisterInfo.h" #include "llvm/Transforms/Utils/GlobalStatus.h" using namespace llvm; @@ -177,6 +180,8 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, return NULL; } + Ret->parseMetadata(); + return Ret; } @@ -798,3 +803,27 @@ bool LTOModule::parseSymbols(std::string &errMsg) { return false; } + +/// parseMetadata - Parse metadata from the module +void LTOModule::parseMetadata() { + // Linker Options + if (Value *Val = _module->getModuleFlag("Linker Options")) { + MDNode *LinkerOptions = cast<MDNode>(Val); + for (unsigned i = 0, e = LinkerOptions->getNumOperands(); i != e; ++i) { + MDNode *MDOptions = cast<MDNode>(LinkerOptions->getOperand(i)); + for (unsigned ii = 0, ie = MDOptions->getNumOperands(); ii != ie; ++ii) { + MDString *MDOption = cast<MDString>(MDOptions->getOperand(ii)); + StringRef Op = _linkeropt_strings. + GetOrCreateValue(MDOption->getString()).getKey(); + StringRef DepLibName = _target->getTargetLowering()-> + getObjFileLowering().getDepLibFromLinkerOpt(Op); + if (!DepLibName.empty()) + _deplibs.push_back(DepLibName.data()); + else if (!Op.empty()) + _linkeropts.push_back(Op.data()); + } + } + } + + // Add other interesting metadata here. +} |