[PATCH] D55229: [COFF, ARM64] Make -flto-visibility-public-std a driver and cc1 flag

Mandeep Singh Grang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 12:02:34 PST 2018


mgrang created this revision.
mgrang added reviewers: rnk, mstorsjo, efriedma, TomTan.
Herald added subscribers: dexonsmith, kristof.beyls, inglorion, javed.absar, mehdi_amini.

Clang currently imports certain functions (like __imp__CxxThrowException) even when statically linking.
Whereas MSVC statically links them (like __CxxThrowException). In clang, function linkage is controlled via /MT 
flag which is a clang-cl flag. This flag gets expanded to -flto-visibility-public-std which is a -cc1 option.
So from clang driver there is no way to statically link these functions. This patch makes -flto-visibility-public-std a
 driver flag which can be used to control function linkage.


Repository:
  rC Clang

https://reviews.llvm.org/D55229

Files:
  CodeGen/arm64-microsoft-symbol-linkage.cpp
  Driver/ToolChains/Clang.cpp
  clang/Driver/CC1Options.td
  clang/Driver/Options.td


Index: CodeGen/arm64-microsoft-symbol-linkage.cpp
===================================================================
--- /dev/null
+++ CodeGen/arm64-microsoft-symbol-linkage.cpp
@@ -0,0 +1,29 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clangxx -target aarch64-windows \
+// RUN: -fcxx-exceptions -emit-obj -c -o - %s \
+// RUN: | llvm-objdump -syms - 2>&1 | FileCheck %s --check-prefix LINK-DYN
+
+// RUN: %clangxx -target aarch64-windows -flto-visibility-public-std \
+// RUN: -fcxx-exceptions -emit-obj -c -o - %s \
+// RUN: | llvm-objdump -syms - 2>&1 | FileCheck %s --check-prefix LINK-STAT
+
+void foo1() { throw 1; }
+// CHECK-LABEL: foo1
+// LINK-DYN: __imp__CxxThrowException
+// LINK-STAT-NOT: __imp__CxxThrowException
+
+void bar();
+void foo2() noexcept(true) { bar(); }
+// CHECK-LABEL: foo2
+// LINK-DYN: __imp___std_terminate
+// LINK-STAT-NOT: __imp___std_terminate
+
+struct A {};
+struct B { virtual void f(); };
+struct C : A, virtual B {};
+struct T {};
+T *foo3() { return dynamic_cast<T *>((C *)0); }
+// CHECK-LABEL: foo3
+// LINK-DYN: __imp___RTDynamicCast
+// LINK-STAT-NOT: __imp___RTDynamicCast
Index: Driver/ToolChains/Clang.cpp
===================================================================
--- Driver/ToolChains/Clang.cpp
+++ Driver/ToolChains/Clang.cpp
@@ -5210,6 +5210,9 @@
                        TC.useIntegratedAs()))
     CmdArgs.push_back("-faddrsig");
 
+  if (Args.hasArg(options::OPT_flto_visibility_public_std))
+    CmdArgs.push_back("-flto-visibility-public-std");
+
   // Finally add the compile command to the compilation.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
       Output.getType() == types::TY_Object &&
Index: clang/Driver/Options.td
===================================================================
--- clang/Driver/Options.td
+++ clang/Driver/Options.td
@@ -825,6 +825,9 @@
 def fcreate_profile : Flag<["-"], "fcreate-profile">, Group<f_Group>;
 def fcxx_exceptions: Flag<["-"], "fcxx-exceptions">, Group<f_Group>,
   HelpText<"Enable C++ exceptions">, Flags<[CC1Option]>;
+def flto_visibility_public_std:
+    Flag<["-"], "flto-visibility-public-std">, Group<f_Group>, Flags<[CC1Option]>,
+    HelpText<"Use public LTO visibility for classes in std and stdext namespaces">;
 def fcxx_modules : Flag <["-"], "fcxx-modules">, Group<f_Group>,
   Flags<[DriverOption]>;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, Group<f_Group>;
Index: clang/Driver/CC1Options.td
===================================================================
--- clang/Driver/CC1Options.td
+++ clang/Driver/CC1Options.td
@@ -345,9 +345,6 @@
 def fprofile_instrument_use_path_EQ :
     Joined<["-"], "fprofile-instrument-use-path=">,
     HelpText<"Specify the profile path in PGO use compilation">;
-def flto_visibility_public_std:
-    Flag<["-"], "flto-visibility-public-std">,
-    HelpText<"Use public LTO visibility for classes in std and stdext namespaces">;
 def flto_unit: Flag<["-"], "flto-unit">,
     HelpText<"Emit IR to support LTO unit features (CFI, whole program vtable opt)">;
 def fno_lto_unit: Flag<["-"], "fno-lto-unit">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55229.176445.patch
Type: text/x-patch
Size: 3119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181203/e80620c1/attachment-0001.bin>


More information about the cfe-commits mailing list