[clang] 9e407af - [AIX][driver] Include crti[_64].o and -bcdtors also for C language link invocations by default
Xiangling Liao via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 16 07:08:10 PST 2020
Author: Xiangling Liao
Date: 2020-11-16T10:07:57-05:00
New Revision: 9e407afd9bd3b5181db24b08f78cb43344bd8292
URL: https://github.com/llvm/llvm-project/commit/9e407afd9bd3b5181db24b08f78cb43344bd8292
DIFF: https://github.com/llvm/llvm-project/commit/9e407afd9bd3b5181db24b08f78cb43344bd8292.diff
LOG: [AIX][driver] Include crti[_64].o and -bcdtors also for C language link invocations by default
In order to support attribute((constructor)) and attribute((destructor)),
which is used by various LLVM non-C++ runtime components, AIX will include
crti[_64].o and -bcdtors for C language link invocations by default.
Differential Revision: https://reviews.llvm.org/D91361
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 47ce99a7c625..7b5d7da8c873 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -134,16 +134,15 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(
Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename())));
- if (D.CCCIsCXX())
- CmdArgs.push_back(Args.MakeArgString(
- ToolChain.GetFilePath(IsArch32Bit ? "crti.o" : "crti_64.o")));
+ CmdArgs.push_back(Args.MakeArgString(
+ ToolChain.GetFilePath(IsArch32Bit ? "crti.o" : "crti_64.o")));
}
- // 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");
+ // Collect all static constructor and destructor functions in both C and CXX
+ // language link invocations. This has to come before AddLinkerInputs as the
+ // implied option needs to precede any other '-bcdtors' settings or
+ // '-bnocdtors' that '-Wl' might forward.
+ 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 89959d851b93..6abfa10c92f6 100644
--- a/clang/test/Driver/aix-ld.c
+++ b/clang/test/Driver/aix-ld.c
@@ -16,7 +16,7 @@
// CHECK-LD32: "-b32"
// CHECK-LD32: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
-// CHECK-LD32-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-NOT: "-lc++"
// CHECK-LD32: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
@@ -38,7 +38,7 @@
// CHECK-LD64: "-b64"
// CHECK-LD64: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
-// CHECK-LD64-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
// CHECK-LD64: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NOT: "-lc++"
// CHECK-LD64: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
@@ -61,7 +61,7 @@
// CHECK-LD32-PTHREAD: "-b32"
// CHECK-LD32-PTHREAD: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
-// CHECK-LD32-PTHREAD-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32-PTHREAD: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-PTHREAD-NOT: "-lc++"
// CHECK-LD32-PTHREAD: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
@@ -85,7 +85,7 @@
// CHECK-LD64-PTHREAD: "-b64"
// CHECK-LD64-PTHREAD: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
-// CHECK-LD64-PTHREAD-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
// CHECK-LD64-PTHREAD: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-PTHREAD-NOT: "-lc++"
// CHECK-LD64-PTHREAD: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
@@ -109,7 +109,7 @@
// CHECK-LD32-PROF: "-b32"
// CHECK-LD32-PROF: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|\\\\}}mcrt0.o"
-// CHECK-LD32-PROF-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-PROF-NOT: "-lc++"
// CHECK-LD32-PROF: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
@@ -132,7 +132,7 @@
// CHECK-LD64-GPROF: "-b64"
// CHECK-LD64-GPROF: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-GPROF: "[[SYSROOT]]/usr/lib{{/|\\\\}}gcrt0_64.o"
-// CHECK-LD64-GPROF-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-GPROF: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
// CHECK-LD64-GPROF: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-GPROF-NOT: "-lc++"
// CHECK-LD64-GPROF: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
@@ -155,7 +155,7 @@
// CHECK-LD32-STATIC: "-b32"
// CHECK-LD32-STATIC: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-STATIC: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
-// CHECK-LD32-STATIC-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-STATIC: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32-STATIC: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-STATIC-NOT: "-lc++"
// CHECK-LD32-STATIC: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
@@ -178,7 +178,7 @@
// CHECK-LD32-LIBP: "-b32"
// CHECK-LD32-LIBP: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-LIBP: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
-// CHECK-LD32-LIBP-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-LIBP: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
// CHECK-LD32-LIBP: "-L[[SYSROOT]]/powerpc-ibm-aix7.1.0.0"
// CHECK-LD32-LIBP: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-LIBP-NOT: "-lc++"
@@ -228,7 +228,7 @@
// CHECK-LD64-NO-DEFAULT-LIBS: "-b64"
// CHECK-LD64-NO-DEFAULT-LIBS: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-NO-DEFAULT-LIBS: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
-// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-NO-DEFAULT-LIBS: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
// CHECK-LD64-NO-DEFAULT-LIBS: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "-lc++"
// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
@@ -236,6 +236,30 @@
// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "-lm"
// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "-lc"
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. 'bcdtors' and argument order.
+// RUN: %clang -no-canonical-prefixes %s 2>&1 -### \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// 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: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-ARG-ORDER: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// 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: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-ARG-ORDER: "-bcdtors:all:0:s"
+// CHECK-LD32-ARG-ORDER: "-bnocdtors"
+// CHECK-LD32-ARG-ORDER-NOT: "-bcdtors:all:0:s"
+// CHECK-LD32-ARG-ORDER-NOT: "-lc++"
+// CHECK-LD32-ARG-ORDER: "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
+// CHECK-LD32-ARG-ORDER-NOT: "-lm"
+// CHECK-LD32-ARG-ORDER: "-lc"
+
// Check powerpc-ibm-aix7.1.0.0, 32-bit. 'bcdtors' and argument order.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -resource-dir=%S/Inputs/resource_dir \
More information about the cfe-commits
mailing list