WIP: [IRGen] Update for changes to how autolinking works in LLVM.

The tests still need to be updated.
This commit is contained in:
Jordan Rose
2017-06-23 12:47:55 -07:00
parent c22168d02d
commit 90ca8f119a
2 changed files with 11 additions and 27 deletions

View File

@@ -949,21 +949,17 @@ static bool replaceModuleFlagsEntry(llvm::LLVMContext &Ctx,
} }
void IRGenModule::emitAutolinkInfo() { void IRGenModule::emitAutolinkInfo() {
// FIXME: This constant should be vended by LLVM somewhere.
static const char * const LinkerOptionsFlagName = "Linker Options";
// Collect the linker options already in the module (from ClangCodeGen). // Collect the linker options already in the module (from ClangCodeGen).
auto *LinkerOptions = Module.getModuleFlag(LinkerOptionsFlagName); // FIXME: This constant should be vended by LLVM somewhere.
if (LinkerOptions) auto *Metadata = Module.getOrInsertNamedMetadata("llvm.linker.options");
for (const auto &LinkOption : cast<llvm::MDNode>(LinkerOptions)->operands()) for (llvm::MDNode *LinkOption : Metadata->operands())
AutolinkEntries.push_back(LinkOption); AutolinkEntries.push_back(LinkOption);
// Remove duplicates. // Remove duplicates.
llvm::SmallPtrSet<llvm::Metadata*, 4> knownAutolinkEntries; llvm::SmallPtrSet<llvm::MDNode *, 4> knownAutolinkEntries;
AutolinkEntries.erase(std::remove_if(AutolinkEntries.begin(), AutolinkEntries.erase(std::remove_if(AutolinkEntries.begin(),
AutolinkEntries.end(), AutolinkEntries.end(),
[&](llvm::Metadata *entry) -> bool { [&](llvm::MDNode *entry) -> bool {
return !knownAutolinkEntries.insert( return !knownAutolinkEntries.insert(
entry).second; entry).second;
}), }),
@@ -972,21 +968,12 @@ void IRGenModule::emitAutolinkInfo() {
if ((TargetInfo.OutputObjectFormat == llvm::Triple::COFF && if ((TargetInfo.OutputObjectFormat == llvm::Triple::COFF &&
!Triple.isOSCygMing()) || !Triple.isOSCygMing()) ||
TargetInfo.OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4()) { TargetInfo.OutputObjectFormat == llvm::Triple::MachO || Triple.isPS4()) {
llvm::LLVMContext &ctx = Module.getContext();
if (!LinkerOptions) { // On platforms that support autolinking, continue to use the metadata.
// Create a new linker flag entry. Metadata->clearOperands();
Module.addModuleFlag(llvm::Module::AppendUnique, LinkerOptionsFlagName, for (auto *Entry : AutolinkEntries)
llvm::MDNode::get(ctx, AutolinkEntries)); Metadata->addOperand(Entry);
} else {
// Replace the old linker flag entry.
bool FoundOldEntry = replaceModuleFlagsEntry(
ctx, Module, LinkerOptionsFlagName, llvm::Module::AppendUnique,
llvm::MDNode::get(ctx, AutolinkEntries));
(void)FoundOldEntry;
assert(FoundOldEntry && "Could not replace old linker options entry?");
}
} else { } else {
assert((TargetInfo.OutputObjectFormat == llvm::Triple::ELF || assert((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
Triple.isOSCygMing()) && Triple.isOSCygMing()) &&

View File

@@ -740,10 +740,7 @@ private:
SmallVector<llvm::WeakTrackingVH, 4> LLVMCompilerUsed; SmallVector<llvm::WeakTrackingVH, 4> LLVMCompilerUsed;
/// Metadata nodes for autolinking info. /// Metadata nodes for autolinking info.
/// SmallVector<llvm::MDNode *, 32> AutolinkEntries;
/// This is typed using llvm::Value instead of llvm::MDNode because it
/// needs to be used to produce another MDNode during finalization.
SmallVector<llvm::Metadata *, 32> AutolinkEntries;
/// List of Objective-C classes, bitcast to i8*. /// List of Objective-C classes, bitcast to i8*.
SmallVector<llvm::WeakTrackingVH, 4> ObjCClasses; SmallVector<llvm::WeakTrackingVH, 4> ObjCClasses;