Author: stevewan Date: 2020-05-25T13:44:15-04:00 New Revision: 5bf2409a4e4d23018ecffe4eff39988a957e76f7
URL: https://github.com/llvm/llvm-project/commit/5bf2409a4e4d23018ecffe4eff39988a957e76f7 DIFF: https://github.com/llvm/llvm-project/commit/5bf2409a4e4d23018ecffe4eff39988a957e76f7.diff LOG: [AIX] Add '-bcdtors:all:0:s' to linker to gather static init functions Summary: On AIX, add '-bcdtors:all:0:s' to the linker implicitly through the driver so that we can collect all static constructor and destructor functions. Reviewers: hubert.reinterpretcast, Xiangling_L, ZarkoCA, daltenty Reviewed By: hubert.reinterpretcast Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80415 Added: Modified: clang/lib/Driver/ToolChains/AIX.cpp clang/test/Driver/aix-ld.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/AIX.cpp b/clang/lib/Driver/ToolChains/AIX.cpp index 6fbff61f7656..df2e30da32a8 100644 --- a/clang/lib/Driver/ToolChains/AIX.cpp +++ b/clang/lib/Driver/ToolChains/AIX.cpp @@ -81,6 +81,7 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, 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 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA, 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); diff --git a/clang/test/Driver/aix-ld.c b/clang/test/Driver/aix-ld.c index 95495718546c..218fbd2bb380 100644 --- a/clang/test/Driver/aix-ld.c +++ b/clang/test/Driver/aix-ld.c @@ -175,3 +175,21 @@ // CHECK-LD64-NO-DEFAULT-LIBS: "-L[[SYSROOT]]/usr/lib" // CHECK-LD64-NO-DEFAULT-LIBS-NOT: "-lpthreads" // CHECK-LD64-NO-DEFAULT-LIBS-NOT: "-lc" + +// 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-CXX-ARG-ORDER %s + +// CHECK-LD32-CXX-ARG-ORDER: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0" +// CHECK-LD32-CXX-ARG-ORDER: "-isysroot" "[[SYSROOT:[^"]+]]" +// CHECK-LD32-CXX-ARG-ORDER: "{{.*}}ld{{(.exe)?}}" +// CHECK-LD32-CXX-ARG-ORDER-NOT: "-bnso" +// CHECK-LD32-CXX-ARG-ORDER: "-b32" +// CHECK-LD32-CXX-ARG-ORDER: "-bpT:0x10000000" "-bpD:0x20000000" +// CHECK-LD32-CXX-ARG-ORDER: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o" +// CHECK-LD32-CXX-ARG-ORDER: "-bcdtors:all:0:s" +// CHECK-LD32-CXX-ARG-ORDER: "-bnocdtors" +// CHECK-LD32-CXX-ARG-ORDER-NOT: "-bcdtors:all:0:s" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits