Author: Shuhong Liu <shuhong.liu@ibm.com>

Date:   Mon Aug 10 10:31:50 2020 +0300

    [AIX][Clang][Driver] Generate reference to the C++ library on the link step

    Have the linker find libc++ on its search path by adding -lc++.

    Reviewed by: daltenty, hubert.reinterpretcast, stevewan

    Differential Revision: https://reviews.llvm.org/D85315
This commit is contained in:
Shuhong Liu 2020-08-10 10:27:04 -04:00
parent 6ef801aa6b
commit b129c9d81a
3 changed files with 181 additions and 3 deletions

View File

@ -141,6 +141,9 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddAllArgs(CmdArgs, options::OPT_L);
ToolChain.AddFilePathLibArgs(Args, CmdArgs);
if (getToolChain().ShouldLinkCXXStdlib(Args))
getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
// Support POSIX threads if "-pthreads" or "-pthread" is present.
if (Args.hasArg(options::OPT_pthreads, options::OPT_pthread))
@ -197,6 +200,23 @@ void AIX::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
addSystemInclude(DriverArgs, CC1Args, UP.str());
}
void AIX::AddCXXStdlibLibArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
switch (GetCXXStdlibType(DriverArgs)) {
case ToolChain::CST_Libcxx:
CC1Args.push_back("-lc++");
return;
case ToolChain::CST_Libstdcxx:
llvm::report_fatal_error("linking libstdc++ unimplemented on AIX");
}
llvm_unreachable("Unexpected C++ library type; only libc++ is supported.");
}
ToolChain::CXXStdlibType AIX::GetDefaultCXXStdlibType() const {
return ToolChain::CST_Libcxx;
}
auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); }
auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); }

View File

@ -67,6 +67,11 @@ public:
AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;
CXXStdlibType GetDefaultCXXStdlibType() const override;
protected:
Tool *buildAssembler() const override;
Tool *buildLinker() const override;

View File

@ -15,6 +15,7 @@
// CHECK-LD32: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-NOT: "-lc++"
// CHECK-LD32: "-lc"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
@ -31,6 +32,7 @@
// CHECK-LD64: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
// CHECK-LD64: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NOT: "-lc++"
// CHECK-LD64: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. Enable POSIX thread support.
@ -48,6 +50,7 @@
// CHECK-LD32-PTHREAD: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-PTHREAD: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-PTHREAD: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-PTHREAD-NOT: "-lc++"
// CHECK-LD32-PTHREAD: "-lpthreads"
// CHECK-LD32-PTHREAD: "-lc"
@ -66,6 +69,7 @@
// CHECK-LD64-PTHREAD: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-PTHREAD: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
// CHECK-LD64-PTHREAD: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-PTHREAD-NOT: "-lc++"
// CHECK-LD64-PTHREAD: "-lpthreads"
// CHECK-LD64-PTHREAD: "-lc"
@ -84,6 +88,7 @@
// CHECK-LD32-PROF: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-PROF: "[[SYSROOT]]/usr/lib{{/|\\\\}}mcrt0.o"
// CHECK-LD32-PROF: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-PROF-NOT: "-lc++"
// CHECK-LD32-PROF: "-lc"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. Enable g-profiling.
@ -101,6 +106,7 @@
// CHECK-LD64-GPROF: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-GPROF: "[[SYSROOT]]/usr/lib{{/|\\\\}}gcrt0_64.o"
// CHECK-LD64-GPROF: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-GPROF-NOT: "-lc++"
// CHECK-LD64-GPROF: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. Static linking.
@ -118,6 +124,7 @@
// CHECK-LD32-STATIC: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-STATIC: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-STATIC: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-STATIC-NOT: "-lc++"
// CHECK-LD32-STATIC: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. Library search path.
@ -136,6 +143,7 @@
// CHECK-LD32-LIBP: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-LIBP: "-L[[SYSROOT]]/powerpc-ibm-aix7.1.0.0"
// CHECK-LD32-LIBP: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-LIBP-NOT: "-lc++"
// CHECK-LD32-LIBP: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. nostdlib.
@ -154,6 +162,7 @@
// CHECK-LD32-NO-STD-LIB: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-NO-STD-LIB-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-NO-STD-LIB: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-NO-STD-LIB-NOT: "-lc++"
// CHECK-LD32-NO-STD-LIB-NOT: "-lpthreads"
// CHECK-LD32-NO-STD-LIB-NOT: "-lc"
@ -173,14 +182,15 @@
// 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: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NO-DEFAULT-LIBS-NOT: "-lc++"
// 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: -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:[^"]+]]"
@ -192,3 +202,146 @@
// 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"
// CHECK-LD32-CXX-ARG-ORDER: "-lc++"
// CHECK-LD32-CXX-ARG-ORDER: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. lc++ and lc order.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -target powerpc-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD32-CXX-ARG-LCXX %s
// CHECK-LD32-CXX-ARG-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
// CHECK-LD32-CXX-ARG-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD32-CXX-ARG-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD32-CXX-ARG-LCXX: "-b32"
// CHECK-LD32-CXX-ARG-LCXX: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-CXX-ARG-LCXX: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-CXX-ARG-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-CXX-ARG-LCXX: "-lc++"
// CHECK-LD32-CXX-ARG-LCXX: "-lc"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. lc++ and lc order.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -target powerpc64-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD64-CXX-ARG-LCXX %s
// CHECK-LD64-CXX-ARG-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
// CHECK-LD64-CXX-ARG-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD64-CXX-ARG-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD64-CXX-ARG-LCXX: "-b64"
// CHECK-LD64-CXX-ARG-LCXX: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-CXX-ARG-LCXX: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
// CHECK-LD64-CXX-ARG-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-CXX-ARG-LCXX: "-lc++"
// CHECK-LD64-CXX-ARG-LCXX: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. -nodefaultlibs.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -nodefaultlibs \
// RUN: -target powerpc-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD32-NODEFLIB-LCXX %s
// CHECK-LD32-NODEFLIB-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
// CHECK-LD32-NODEFLIB-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD32-NODEFLIB-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD32-NODEFLIB-LCXX: "-b32"
// CHECK-LD32-NODEFLIB-LCXX: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-NODEFLIB-LCXX: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-NODEFLIB-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-NODEFLIB-LCXX-NOT: "-lc++"
// CHECK-LD32-NODEFLIB-LCXX-NOT: "-lc"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -nodefaultlibs.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -nodefaultlibs \
// RUN: -target powerpc64-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD64-NODEFLIB-LCXX %s
// CHECK-LD64-NODEFLIB-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
// CHECK-LD64-NODEFLIB-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD64-NODEFLIB-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD64-NODEFLIB-LCXX: "-b64"
// CHECK-LD64-NODEFLIB-LCXX: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-NODEFLIB-LCXX: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
// CHECK-LD64-NODEFLIB-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NODEFLIB-LCXX-NOT: "-lc++"
// CHECK-LD64-NODEFLIB-LCXX-NOT: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. -nostdlib.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -nostdlib \
// RUN: -target powerpc-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD32-NOSTDLIB-LCXX %s
// CHECK-LD32-NOSTDLIB-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
// CHECK-LD32-NOSTDLIB-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD32-NOSTDLIB-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD32-NOSTDLIB-LCXX: "-b32"
// CHECK-LD32-NOSTDLIB-LCXX: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-NOSTDLIB-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-NOSTDLIB-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-NOSTDLIB-LCXX-NOT: "-lc++"
// CHECK-LD32-NOSTDLIB-LCXX-NOT: "-lc"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -nostdlib.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -nostdlib \
// RUN: -target powerpc64-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD64-NOSTDLIB-LCXX %s
// CHECK-LD64-NOSTDLIB-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
// CHECK-LD64-NOSTDLIB-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD64-NOSTDLIB-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD64-NOSTDLIB-LCXX: "-b64"
// CHECK-LD64-NOSTDLIB-LCXX: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-NOSTDLIB-LCXX-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
// CHECK-LD64-NOSTDLIB-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NOSTDLIB-LCXX-NOT: "-lc++"
// CHECK-LD64-NOSTDLIB-LCXX-NOT: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. -nostdlib++.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -nostdlib++ \
// RUN: -target powerpc-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD32-NOSTDLIBXX-LCXX %s
// CHECK-LD32-NOSTDLIBXX-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
// CHECK-LD32-NOSTDLIBXX-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD32-NOSTDLIBXX-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD32-NOSTDLIBXX-LCXX: "-b32"
// CHECK-LD32-NOSTDLIBXX-LCXX: "-bpT:0x10000000" "-bpD:0x20000000"
// CHECK-LD32-NOSTDLIBXX-LCXX: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
// CHECK-LD32-NOSTDLIBXX-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD32-NOSTDLIBXX-LCXX-NOT: "-lc++"
// CHECK-LD32-NOSTDLIBXX-LCXX: "-lc"
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -nostdlib++.
// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -nostdlib++ \
// RUN: -target powerpc64-ibm-aix7.1.0.0 \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD64-NOSTDLIBXX-LCXX %s
// CHECK-LD64-NOSTDLIBXX-LCXX: {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
// CHECK-LD64-NOSTDLIBXX-LCXX: "-isysroot" "[[SYSROOT:[^"]+]]"
// CHECK-LD64-NOSTDLIBXX-LCXX: "{{.*}}ld{{(.exe)?}}"
// CHECK-LD64-NOSTDLIBXX-LCXX: "-b64"
// CHECK-LD64-NOSTDLIBXX-LCXX: "-bpT:0x100000000" "-bpD:0x110000000"
// CHECK-LD64-NOSTDLIBXX-LCXX: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
// CHECK-LD64-NOSTDLIBXX-LCXX: "-L[[SYSROOT]]/usr/lib"
// CHECK-LD64-NOSTDLIBXX-LCXX-NOT: "-lc++"
// CHECK-LD64-NOSTDLIBXX-LCXX: "-lc"
// Check powerpc-ibm-aix7.1.0.0, 32-bit. -stdlib=libstdc++ invokes fatal error.
// RUN: not --crash %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -target powerpc-ibm-aix7.1.0.0 \
// RUN: -stdlib=libstdc++ \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD-LIBSTDCXX %s
// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -stdlib=libstdc++ invokes fatal error.
// RUN: not --crash %clangxx -no-canonical-prefixes %s 2>&1 -### \
// RUN: -target powerpc64-ibm-aix7.1.0.0 \
// RUN: -stdlib=libstdc++ \
// RUN: --sysroot %S/Inputs/aix_ppc_tree \
// RUN: | FileCheck --check-prefix=CHECK-LD-LIBSTDCXX %s
// CHECK-LD-LIBSTDCXX: LLVM ERROR: linking libstdc++ unimplemented on AIX