[PATCH] D80415: [AIX] Add '-bcdtors:all:0:s' to linker to gather static init functions

Steven Wan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 10:10:48 PDT 2020


stevewan updated this revision to Diff 265765.
stevewan added a comment.

Address comments and fix windows compatibility issues with the test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80415/new/

https://reviews.llvm.org/D80415

Files:
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-ld.cpp


Index: clang/test/Driver/aix-ld.cpp
===================================================================
--- /dev/null
+++ clang/test/Driver/aix-ld.cpp
@@ -0,0 +1,19 @@
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. 'bcdtors' and argument order.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:          -Wl,-bnocdtors \
+// RUN:          -target powerpc-ibm-aix7.1.0.0 \
+// RUN:          --sysroot %S/Inputs/aix_ppc_tree \
+// RUN: | FileCheck --check-prefix=CHECK-LD32-ARG-ORDER %s
+
+// CHECK-LD32-ARG-ORDER-NOT: warning:
+// CHECK-LD32-ARG-ORDER:     {{.*}}clang{{(.exe)?}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-ARG-ORDER:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-ARG-ORDER:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-ARG-ORDER-NOT: "-bnso"
+// CHECK-LD32-ARG-ORDER:     "-b32"
+// CHECK-LD32-ARG-ORDER:     "-bpT:0x10000000" "-bpD:0x20000000"
+// CHECK-LD32-ARG-ORDER:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
+// CHECK-LD32-ARG-ORDER:     "-bcdtors:all:0:s"
+// CHECK-LD32-ARG-ORDER:     "-bnocdtors"
+// CHECK-LD32-ARG-ORDER:     "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD32-ARG-ORDER:     "-lc"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -81,6 +81,7 @@
                                const InputInfoList &Inputs, const ArgList &Args,
                                const char *LinkingOutput) const {
   const AIX &ToolChain = static_cast<const AIX &>(getToolChain());
+  const Driver &D = ToolChain.getDriver();
   ArgStringList CmdArgs;
 
   const bool IsArch32Bit = ToolChain.getTriple().isArch32Bit();
@@ -129,6 +130,12 @@
         Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename())));
   }
 
+  // Collect all static constructor and destructor functions in CXX mode. This
+  // has to come before AddLinkerInputs as the implied option needs to precede
+  // any other '-bcdtors' settings or '-bnocdtors' that '-Wl' might forward.
+  if (D.CCCIsCXX())
+    CmdArgs.push_back("-bcdtors:all:0:s");
+
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80415.265765.patch
Type: text/x-patch
Size: 2201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200522/6f52053a/attachment.bin>


More information about the cfe-commits mailing list