[AIX][Clang][Driver] Add handling of shared option
authorDavid Tenty <daltenty@ibm.com>
Fri, 28 Aug 2020 18:38:59 +0000 (14:38 -0400)
committerDavid Tenty <daltenty@ibm.com>
Mon, 21 Sep 2020 18:03:08 +0000 (14:03 -0400)
Reviewed By: jasonliu

Differential Revision: https://reviews.llvm.org/D87914

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

index e492cd7..f4bab83 100644 (file)
@@ -92,6 +92,12 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   if (Args.hasArg(options::OPT_static))
     CmdArgs.push_back("-bnso");
 
+  // Add options for shared libraries.
+  if (Args.hasArg(options::OPT_shared)) {
+    CmdArgs.push_back("-bM:SRE");
+    CmdArgs.push_back("-bnoentry");
+  }
+
   // Specify linker output file.
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
@@ -123,7 +129,8 @@ void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
       return IsArch32Bit ? "crt0.o" : "crt0_64.o";
   };
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+                   options::OPT_shared)) {
     CmdArgs.push_back(
         Args.MakeArgString(ToolChain.GetFilePath(getCrt0Basename())));
   }
index 695260b..22b0378 100644 (file)
 // 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
+
+// Check powerpc64-ibm-aix7.1.0.0, 32-bit. -shared.
+// RUN: %clang -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -shared \
+// RUN:        -target powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED %s
+// CHECK-LD32-SHARED:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-SHARED:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-SHARED:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-SHARED:     "-bM:SRE"
+// CHECK-LD32-SHARED:     "-bnoentry"
+// CHECK-LD32-SHARED:     "-b32"
+// CHECK-LD32-SHARED:     "-bpT:0x10000000" "-bpD:0x20000000"
+// CHECK-LD32-SHARED-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
+// CHECK-LD32-SHARED:     "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD32-SHARED:     "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared.
+// RUN: %clang -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED %s
+// CHECK-LD64-SHARED:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-SHARED:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-SHARED:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-SHARED:     "-bM:SRE"
+// CHECK-LD64-SHARED:     "-bnoentry"
+// CHECK-LD64-SHARED:     "-b64"
+// CHECK-LD64-SHARED:     "-bpT:0x100000000" "-bpD:0x110000000"
+// CHECK-LD64-SHARED-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
+// CHECK-LD64-SHARED:     "-L[[SYSROOT]]/usr/lib"
+// CHECK-LD64-SHARED:     "-lc"