From 80987ad1a6febf3a18d372c30364824cdc0078e8 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 12 Jun 2017 20:10:48 +0000 Subject: [PATCH] IR: Replace the "Linker Options" module flag with "llvm.linker.options" named metadata. The new metadata is easier to manipulate than module flags. Differential Revision: https://reviews.llvm.org/D31349 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@305227 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 10 +++++----- lib/CodeGen/CodeGenModule.h | 7 ++++--- test/CodeGen/dependent-lib.c | 8 ++------ test/CodeGen/linker-option.c | 4 +--- test/CodeGen/pragma-comment.c | 4 +--- test/CodeGen/pragma-detect_mismatch.c | 4 +--- test/CodeGenCXX/ms-thread_local.cpp | 4 +--- test/CodeGenObjC/availability-cf-link-guard.m | 5 ++--- test/Modules/autolink.m | 6 ++---- test/Modules/autolinkTBD.m | 6 ++---- test/Modules/module-impl-with-link.c | 3 +-- 11 files changed, 22 insertions(+), 39 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 77adf7b441..19a0550756 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1243,7 +1243,7 @@ void CodeGenModule::AddDependentLib(StringRef Lib) { /// \brief Add link options implied by the given module, including modules /// it depends on, using a postorder walk. static void addLinkOptionsPostorder(CodeGenModule &CGM, Module *Mod, - SmallVectorImpl &Metadata, + SmallVectorImpl &Metadata, llvm::SmallPtrSet &Visited) { // Import this module's parent. if (Mod->Parent && Visited.insert(Mod->Parent).second) { @@ -1331,7 +1331,7 @@ void CodeGenModule::EmitModuleLinkOptions() { // Add link options for all of the imported modules in reverse topological // order. We don't do anything to try to order import link flags with respect // to linker options inserted by things like #pragma comment(). - SmallVector MetadataArgs; + SmallVector MetadataArgs; Visited.clear(); for (Module *M : LinkModules) if (Visited.insert(M).second) @@ -1340,9 +1340,9 @@ void CodeGenModule::EmitModuleLinkOptions() { LinkerOptionsMetadata.append(MetadataArgs.begin(), MetadataArgs.end()); // Add the linker options metadata flag. - getModule().addModuleFlag(llvm::Module::AppendUnique, "Linker Options", - llvm::MDNode::get(getLLVMContext(), - LinkerOptionsMetadata)); + auto *NMD = getModule().getOrInsertNamedMetadata("llvm.linker.options"); + for (auto *MD : LinkerOptionsMetadata) + NMD->addOperand(MD); } void CodeGenModule::EmitDeferred() { diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 0a71c635e8..59e56a6ba1 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -429,7 +429,7 @@ private: llvm::SmallPtrSet EmittedModuleInitializers; /// \brief A vector of metadata strings. - SmallVector LinkerOptionsMetadata; + SmallVector LinkerOptionsMetadata; /// @name Cache for Objective-C runtime types /// @{ @@ -1058,13 +1058,14 @@ public: void RefreshTypeCacheForClass(const CXXRecordDecl *Class); - /// \brief Appends Opts to the "Linker Options" metadata value. + /// \brief Appends Opts to the "llvm.linker.options" metadata value. void AppendLinkerOptions(StringRef Opts); /// \brief Appends a detect mismatch command to the linker options. void AddDetectMismatch(StringRef Name, StringRef Value); - /// \brief Appends a dependent lib to the "Linker Options" metadata value. + /// \brief Appends a dependent lib to the "llvm.linker.options" metadata + /// value. void AddDependentLib(StringRef Lib); llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD); diff --git a/test/CodeGen/dependent-lib.c b/test/CodeGen/dependent-lib.c index 9cf49c88d7..7178a29692 100644 --- a/test/CodeGen/dependent-lib.c +++ b/test/CodeGen/dependent-lib.c @@ -3,14 +3,10 @@ // RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple x86_64-pc-win32 -emit-llvm -o - | FileCheck %s // RUN: %clang_cc1 %s --dependent-lib=msvcrt -triple i686-pc-linux -emit-llvm -o - | FileCheck -check-prefix LINUX %s -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} -// CHECK: ![[link_opts]] = !{![[msvcrt:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[msvcrt:[0-9]+]]} // CHECK: ![[msvcrt]] = !{!"/DEFAULTLIB:msvcrt.lib"} -// LINUX: !llvm.module.flags = !{{{.*}}} -// LINUX: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} -// LINUX: ![[link_opts]] = !{![[msvcrt:[0-9]+]]} +// LINUX: !llvm.linker.options = !{![[msvcrt:[0-9]+]]} // LINUX: ![[msvcrt]] = !{!"-lmsvcrt"} int f(); diff --git a/test/CodeGen/linker-option.c b/test/CodeGen/linker-option.c index b1b2ec461c..13bd981179 100644 --- a/test/CodeGen/linker-option.c +++ b/test/CodeGen/linker-option.c @@ -1,8 +1,6 @@ // RUN: %clang_cc1 %s --linker-option=/include:foo -triple i686-pc-win32 -emit-llvm -o - | FileCheck %s -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} -// CHECK: ![[link_opts]] = !{![[msvcrt:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[msvcrt:[0-9]+]]} // CHECK: ![[msvcrt]] = !{!"/include:foo"} int f(); diff --git a/test/CodeGen/pragma-comment.c b/test/CodeGen/pragma-comment.c index 71a7dfc0b0..e20efacdcb 100644 --- a/test/CodeGen/pragma-comment.c +++ b/test/CodeGen/pragma-comment.c @@ -14,9 +14,7 @@ #pragma comment(linker," /bar=" BAR) #pragma comment(linker," /foo=\"foo bar\"") -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} -// CHECK: ![[link_opts]] = !{![[msvcrt:[0-9]+]], ![[kernel32:[0-9]+]], ![[USER32:[0-9]+]], ![[space:[0-9]+]], ![[bar:[0-9]+]], ![[foo:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[msvcrt:[0-9]+]], ![[kernel32:[0-9]+]], ![[USER32:[0-9]+]], ![[space:[0-9]+]], ![[bar:[0-9]+]], ![[foo:[0-9]+]]} // CHECK: ![[msvcrt]] = !{!"/DEFAULTLIB:msvcrt.lib"} // CHECK: ![[kernel32]] = !{!"/DEFAULTLIB:kernel32.lib"} // CHECK: ![[USER32]] = !{!"/DEFAULTLIB:USER32.LIB"} diff --git a/test/CodeGen/pragma-detect_mismatch.c b/test/CodeGen/pragma-detect_mismatch.c index 08259fc6be..066183d312 100644 --- a/test/CodeGen/pragma-detect_mismatch.c +++ b/test/CodeGen/pragma-detect_mismatch.c @@ -6,8 +6,6 @@ #define BAR "2" #pragma detect_mismatch("test2", BAR) -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} -// CHECK: ![[link_opts]] = !{![[test:[0-9]+]], ![[test2:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[test:[0-9]+]], ![[test2:[0-9]+]]} // CHECK: ![[test]] = !{!"/FAILIFMISMATCH:\22test=1\22"} // CHECK: ![[test2]] = !{!"/FAILIFMISMATCH:\22test2=2\22"} diff --git a/test/CodeGenCXX/ms-thread_local.cpp b/test/CodeGenCXX/ms-thread_local.cpp index 5183ab5c32..dc7958d6ea 100644 --- a/test/CodeGenCXX/ms-thread_local.cpp +++ b/test/CodeGenCXX/ms-thread_local.cpp @@ -27,7 +27,5 @@ A f() { return c; } -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[link_opts:[0-9]+]]} -// CHECK: ![[link_opts]] = !{![[dyn_tls_init:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[dyn_tls_init:[0-9]+]]} // CHECK: ![[dyn_tls_init]] = !{!"/include:___dyn_tls_init@12"} diff --git a/test/CodeGenObjC/availability-cf-link-guard.m b/test/CodeGenObjC/availability-cf-link-guard.m index 918d13ffd9..6bd426476b 100644 --- a/test/CodeGenObjC/availability-cf-link-guard.m +++ b/test/CodeGenObjC/availability-cf-link-guard.m @@ -37,9 +37,8 @@ void use_at_available() { // CHECK_NO_GUARD-NOT: __clang_at_available_requires_core_foundation_framework // CHECK_NO_GUARD-NOT: CFBundleGetVersionNumber -// CHECK_LINK_OPT: !"Linker Options", ![[OPTS:[0-9]+]] -// CHECK_LINK_OPT: ![[OPTS]] = !{![[FRAMEWORK:[0-9]+]] +// CHECK_LINK_OPT: !llvm.linker.options = !{![[FRAMEWORK:[0-9]+]] // CHECK_LINK_OPT: ![[FRAMEWORK]] = !{!"-framework", !"CoreFoundation"} -// CHECK_NO_GUARD-NOT: "Linker Options" +// CHECK_NO_GUARD-NOT: !llvm.linker.options // CHECK_NO_GUARD-NOT: CoreFoundation diff --git a/test/Modules/autolink.m b/test/Modules/autolink.m index 28b9e40678..6aee0e11b1 100644 --- a/test/Modules/autolink.m +++ b/test/Modules/autolink.m @@ -36,9 +36,7 @@ int use_autolink_sub3() { // NOTE: "autolink_sub" is intentionally not linked. -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[AUTOLINK_OPTIONS:[0-9]+]]} -// CHECK: ![[AUTOLINK_OPTIONS]] = !{![[AUTOLINK_PCH:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[AUTOLINK:[0-9]+]], ![[DEPENDSONMODULE:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[AUTOLINK_PCH:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[AUTOLINK:[0-9]+]], ![[DEPENDSONMODULE:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]} // CHECK: ![[AUTOLINK_PCH]] = !{!"{{(\\01|-l|/DEFAULTLIB:)}}autolink_from_pch{{(\.lib)?}}"} // CHECK: ![[AUTOLINK_FRAMEWORK]] = !{!"-framework", !"autolink_framework"} // CHECK: ![[AUTOLINK]] = !{!"{{(\\01|-l|/DEFAULTLIB:)}}autolink{{(\.lib)?}}"} @@ -47,4 +45,4 @@ int use_autolink_sub3() { // CHECK: ![[NOUMBRELLA]] = !{!"-framework", !"NoUmbrella"} // CHECK-AUTOLINK-DISABLED: !llvm.module.flags -// CHECK-AUTOLINK-DISABLED-NOT: "Linker Options" +// CHECK-AUTOLINK-DISABLED-NOT: !llvm.linker.options diff --git a/test/Modules/autolinkTBD.m b/test/Modules/autolinkTBD.m index 6107952c3b..d6b9e997b2 100644 --- a/test/Modules/autolinkTBD.m +++ b/test/Modules/autolinkTBD.m @@ -8,10 +8,8 @@ int f() { return foo(); } -// CHECK: !llvm.module.flags = !{{{.*}}} -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[AUTOLINK_OPTIONS:[0-9]+]]} -// CHECK: ![[AUTOLINK_OPTIONS]] = !{![[AUTOLINK_FRAMEWORK:[0-9]+]]} +// CHECK: !llvm.linker.options = !{![[AUTOLINK_FRAMEWORK:[0-9]+]]} // CHECK: ![[AUTOLINK_FRAMEWORK]] = !{!"-framework", !"AutolinkTBD"} // CHECK-AUTOLINK-DISABLED: !llvm.module.flags -// CHECK-AUTOLINK-DISABLED-NOT: "Linker Options" +// CHECK-AUTOLINK-DISABLED-NOT: !llvm.linker.options diff --git a/test/Modules/module-impl-with-link.c b/test/Modules/module-impl-with-link.c index 3bd4c4abd9..ffd388c56b 100644 --- a/test/Modules/module-impl-with-link.c +++ b/test/Modules/module-impl-with-link.c @@ -1,7 +1,6 @@ // RUN: rm -rf %t // RUN: %clang_cc1 -fmodules-cache-path=%t -fmodules -fimplicit-module-maps -fmodule-name=Clib %s -I %S/Inputs/module-impl-with-link -emit-llvm -o - | FileCheck %s #include "foo.h" -// CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[LINK_OPTIONS:[0-9]+]]} // Make sure we don't generate linker option for module Clib since this TU is // an implementation of Clib. -// CHECK: ![[LINK_OPTIONS]] = !{} +// CHECK: !llvm.linker.options = !{} -- 2.40.0