DiggerLin updated this revision to Diff 406560.
DiggerLin added a comment.

run git format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119147

Files:
  clang/include/clang/Driver/Job.h
  clang/lib/Driver/Job.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/test/Driver/aix-ld.c

Index: clang/test/Driver/aix-ld.c
===================================================================
--- clang/test/Driver/aix-ld.c
+++ clang/test/Driver/aix-ld.c
@@ -596,7 +596,7 @@
 // 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.
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared.
 // RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
 // RUN:        -resource-dir=%S/Inputs/resource_dir \
 // RUN:        -shared \
@@ -604,9 +604,25 @@
 // RUN:        --sysroot %S/Inputs/aix_ppc_tree \
 // RUN:        -unwindlib=libunwind \
 // RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED %s
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared (with exp option strings in other opt).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -unwindlib=libunwind \
+// RUN:        -Wl,-Z/expall/expfull/a-bE:/a-bexport:/ \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED %s
+
 // CHECK-LD32-SHARED:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
 // CHECK-LD32-SHARED:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-LD32-SHARED:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-SHARED:     "{{.*}}llvm-nm"
+// CHECK-LD32-SHARED:     "--export-symbols"
+// CHECK-LD32-SHARED:     "-X"
+// CHECK-LD32-SHARED:     "32"
 // CHECK-LD32-SHARED:     "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD32-SHARED:     "-bM:SRE"
 // CHECK-LD32-SHARED:     "-bnoentry"
@@ -623,6 +639,56 @@
 // CHECK-LD32-SHARED:     "-lm"
 // CHECK-LD32-SHARED:     "-lc"
 
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared with export list.
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Wl,-bE:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared with export list (no -Wl, variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -bE:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -shared with export list (-Xlinker variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Xlinker -bE:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-SHARED-EXPORTS %s
+
+// CHECK-LD32-SHARED-EXPORTS:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-SHARED-EXPORTS:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD32-SHARED-EXPORTS:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "{{.*}}llvm-nm"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "-X"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "32"
+// CHECK-LD32-SHARED-EXPORTS:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-SHARED-EXPORTS:     "-bM:SRE"
+// CHECK-LD32-SHARED-EXPORTS:     "-bnoentry"
+// CHECK-LD32-SHARED-EXPORTS:     "-b32"
+// CHECK-LD32-SHARED-EXPORTS:     "-bpT:0x10000000" "-bpD:0x20000000"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-SHARED-EXPORTS:     "-b{{(" ")?}}E:input.exp"
+// CHECK-LD32-SHARED-EXPORTS-NOT: "-bE:{{[^"]+}}"
+// CHECK-LD32-SHARED-EXPORTS:     "-lc++"
+// CHECK-LD32-SHARED-EXPORTS:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
+// CHECK-LD32-SHARED-EXPORTS:     "-lm"
+// CHECK-LD32-SHARED-EXPORTS:     "-lc"
+
 // Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared.
 // RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
 // RUN:        -resource-dir=%S/Inputs/resource_dir \
@@ -634,6 +700,10 @@
 // CHECK-LD64-SHARED:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
 // CHECK-LD64-SHARED:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-LD64-SHARED:     "-isysroot" "[[SYSROOT:[^"]+]]"
+/ /CHECK-LD64-SHARED:     "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED:     "--export-symbols"
+// CHECK-LD64-SHARED:     "-X"
+// CHECK-LD64-SHARED:     "64"
 // CHECK-LD64-SHARED:     "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD64-SHARED:     "-bM:SRE"
 // CHECK-LD64-SHARED:     "-bnoentry"
@@ -650,6 +720,127 @@
 // CHECK-LD64-SHARED:     "-lm"
 // CHECK-LD64-SHARED:     "-lc"
 
+// Check powerpc-ibm-aix7.1.0.0, 32-bit. -fno-exceptions.
+// RUN: %clangxx -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -fno-exceptions \
+// RUN:        -target powerpc-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:   | FileCheck --check-prefix=CHECK-LD32-NOEXCEPTIONS %s
+// CHECK-LD32-NOEXCEPTIONS:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc-ibm-aix7.1.0.0"
+// CHECK-LD32-NOEXCEPTIONS:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD32-NOEXCEPTIONS:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD32-NOEXCEPTIONS:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD32-NOEXCEPTIONS:     "-b32"
+// CHECK-LD32-NOEXCEPTIONS:     "-bpT:0x10000000" "-bpD:0x20000000"
+// CHECK-LD32-NOEXCEPTIONS:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0.o"
+// CHECK-LD32-NOEXCEPTIONS:     "[[SYSROOT]]/usr/lib{{/|\\\\}}crti.o"
+// CHECK-LD32-NOEXCEPTIONS:     "-lc++"
+// CHECK-LD32-NOEXCEPTIONS:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc.a"
+// CHECK-LD32-NOEXCEPTIONS:     "-lm"
+// CHECK-LD32-NOEXCEPTIONS:     "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with export list.
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Wl,-bE:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with export list (no -Wl, variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -bE:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with export list (-Xlinker variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Xlinker -bE:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS %s
+
+// CHECK-LD64-SHARED-EXPORTS:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-SHARED-EXPORTS:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD64-SHARED-EXPORTS:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "-X"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "64"
+// CHECK-LD64-SHARED-EXPORTS:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-SHARED-EXPORTS:     "-bM:SRE"
+// CHECK-LD64-SHARED-EXPORTS:     "-bnoentry"
+// CHECK-LD64-SHARED-EXPORTS:     "-b64"
+// CHECK-LD64-SHARED-EXPORTS:     "-bpT:0x100000000" "-bpD:0x110000000"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-SHARED-EXPORTS:     "-b{{(" ")?}}E:input.exp"
+// CHECK-LD64-SHARED-EXPORTS-NOT: "-bE:{{[^"]+}}"
+// CHECK-LD64-SHARED-EXPORTS:     "-lc++"
+// CHECK-LD64-SHARED-EXPORTS:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
+// CHECK-LD64-SHARED-EXPORTS:     "-lm"
+// CHECK-LD64-SHARED-EXPORTS:     "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with alternate export list.
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Wl,-bexport:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS-ALT %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with alternate export list (no -Wl, variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -bexport:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS-ALT %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with alternate export list (-Xlinker variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Xlinker -bexport:input.exp \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPORTS-ALT %s
+
+// CHECK-LD64-SHARED-EXPORTS-ALT:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "-X"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "64"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-bM:SRE"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-bnoentry"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-b64"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-bpT:0x100000000" "-bpD:0x110000000"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-b{{(" ")?}}export:input.exp"
+// CHECK-LD64-SHARED-EXPORTS-ALT-NOT: "-bE:{{[^"]+}}"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-lc++"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-lm"
+// CHECK-LD64-SHARED-EXPORTS-ALT:     "-lc"
+
 // Check powerpc-ibm-aix7.3.0.0, -fprofile-generate
 // RUN: %clang -no-canonical-prefixes %s -### 2>&1 \
 // RUN:        -resource-dir=%S/Inputs/resource_dir \
@@ -677,6 +868,56 @@
 // CHECK-PGO-NON-LTO-NOT: "-lm"
 // CHECK-PGO-NON-LTO:     "-lc"
 
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with -bexpall.
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Wl,-bexpall \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPALL %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with -bexpall (no -Wl, variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -bexpall \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPALL %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with -bexpall (-Xlinker variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Xlinker -bexpall \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPALL %s
+
+// CHECK-LD64-SHARED-EXPALL:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-SHARED-EXPALL:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD64-SHARED-EXPALL:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-SHARED-EXPALL-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPALL-NOT: "-X"
+// CHECK-LD64-SHARED-EXPALL-NOT: "64"
+// CHECK-LD64-SHARED-EXPALL:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-SHARED-EXPALL:     "-bM:SRE"
+// CHECK-LD64-SHARED-EXPALL:     "-bnoentry"
+// CHECK-LD64-SHARED-EXPALL:     "-b64"
+// CHECK-LD64-SHARED-EXPALL:     "-bpT:0x100000000" "-bpD:0x110000000"
+// CHECK-LD64-SHARED-EXPALL-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
+// CHECK-LD64-SHARED-EXPALL-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-SHARED-EXPALL:     "-b{{(" ")?}}expall"
+// CHECK-LD64-SHARED-EXPALL-NOT: "-bE:{{[^"]+}}"
+// CHECK-LD64-SHARED-EXPALL:     "-lc++"
+// CHECK-LD64-SHARED-EXPALL:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
+// CHECK-LD64-SHARED-EXPALL:     "-lm"
+// CHECK-LD64-SHARED-EXPALL:     "-lc"
+
 // Check powerpc-ibm-aix7.2.5.3, -fprofile-generate, -flto
 // RUN: %clang -no-canonical-prefixes %s -### 2>&1 \
 // RUN:        -resource-dir=%S/Inputs/resource_dir \
@@ -704,3 +945,53 @@
 // CHECK-PGO-LTO-NOT: "--no-as-needed"
 // CHECK-PGO-LTO-NOT: "-lm"
 // CHECK-PGO-LTO:     "-lc"
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with -bexpfull (no -Wl, variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Wl,-bexpfull \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPFULL %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with -bexpfull (no -Wl, variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -bexpfull \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPFULL %s
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit. -shared with -bexpfull (-Xlinker variant).
+// RUN: %clangxx -x c++ -no-canonical-prefixes %s 2>&1 -### \
+// RUN:        -resource-dir=%S/Inputs/resource_dir \
+// RUN:        -shared \
+// RUN:        -target powerpc64-ibm-aix7.1.0.0 \
+// RUN:        --sysroot %S/Inputs/aix_ppc_tree \
+// RUN:        -ccc-install-dir %T/open_xl_aix_install/opt/IBM/openxlC/%open_xl_vrm/bin \
+// RUN:        -Xlinker -bexpfull \
+// RUN:   | FileCheck --check-prefix=CHECK-LD64-SHARED-EXPFULL %s
+
+// CHECK-LD64-SHARED-EXPFULL:     {{.*}}clang{{.*}}" "-cc1" "-triple" "powerpc64-ibm-aix7.1.0.0"
+// CHECK-LD64-SHARED-EXPFULL:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-LD64-SHARED-EXPFULL:     "-isysroot" "[[SYSROOT:[^"]+]]"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "{{.*}}llvm-nm"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "-X"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "64"
+// CHECK-LD64-SHARED-EXPFULL:     "{{.*}}ld{{(.exe)?}}"
+// CHECK-LD64-SHARED-EXPFULL:     "-bM:SRE"
+// CHECK-LD64-SHARED-EXPFULL:     "-bnoentry"
+// CHECK-LD64-SHARED-EXPFULL:     "-b64"
+// CHECK-LD64-SHARED-EXPFULL:     "-bpT:0x100000000" "-bpD:0x110000000"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crt0_64.o"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "[[SYSROOT]]/usr/lib{{/|\\\\}}crti_64.o"
+// CHECK-LD64-SHARED-EXPFULL:     "-b{{(" ")?}}expfull"
+// CHECK-LD64-SHARED-EXPFULL-NOT: "-bE:{{[^"]+}}"
+// CHECK-LD64-SHARED-EXPFULL:     "-lc++"
+// CHECK-LD64-SHARED-EXPFULL:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}aix{{/|\\\\}}libclang_rt.builtins-powerpc64.a"
+// CHECK-LD64-SHARED-EXPFULL:     "-lm"
+// CHECK-LD64-SHARED-EXPFULL:     "-lc"
Index: clang/lib/Driver/ToolChains/AIX.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -74,6 +74,29 @@
                                          Exec, CmdArgs, Inputs, Output));
 }
 
+// Determine whether there are any linker options that supply an export list
+// (or equivalent information about what to export) being sent to the linker.
+static bool hasExportListLinkerOpts(const ArgStringList &CmdArgs) {
+  for (size_t i = 0; i < CmdArgs.size(); ++i) {
+    llvm::StringRef ArgString(CmdArgs[i]);
+
+    if (ArgString.startswith("-bE:") || ArgString.startswith("-bexport:") ||
+        ArgString == "-bexpall" || ArgString == "-bexpfull")
+      return true;
+
+    // If we split -b option, check the next opt.
+    if (ArgString == "-b" && i + 1 < CmdArgs.size()) {
+      ++i;
+      llvm::StringRef ArgNextString(CmdArgs[i]);
+      if (ArgNextString.startswith("E:") ||
+          ArgNextString.startswith("export:") || ArgNextString == "expall" ||
+          ArgNextString == "expfull")
+        return true;
+    }
+  }
+  return false;
+}
+
 void aix::Linker::ConstructJob(Compilation &C, const JobAction &JA,
                                const InputInfo &Output,
                                const InputInfoList &Inputs, const ArgList &Args,
@@ -167,6 +190,40 @@
   // Specify linker input file(s).
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
+  if (Args.hasArg(options::OPT_shared) && !hasExportListLinkerOpts(CmdArgs)) {
+
+    const char *CreateExportListExec = Args.MakeArgString(
+        llvm::sys::path::parent_path(ToolChain.getDriver().ClangExecutable) +
+        "/llvm-nm");
+    ArgStringList CreateExportCmdArgs;
+
+    auto CreateExportListPath =
+        C.getDriver().GetTemporaryPath("CreateExportList", "exp");
+    const char *ExportList =
+        C.addTempFile(C.getArgs().MakeArgString(CreateExportListPath));
+
+    for (const auto &II : Inputs) {
+      if (II.isFilename())
+        CreateExportCmdArgs.push_back(II.getFilename());
+    }
+
+    CreateExportCmdArgs.push_back("--export-symbols"); 
+    CreateExportCmdArgs.push_back("-X");
+    if (IsArch32Bit) {
+      CreateExportCmdArgs.push_back("32");
+    } else {
+      // Must be 64-bit, otherwise asserted already.
+      CreateExportCmdArgs.push_back("64");
+    }
+
+    std::unique_ptr<Command> ExpCommand = std::make_unique<Command>(
+        JA, *this, ResponseFileSupport::None(), CreateExportListExec,
+        CreateExportCmdArgs, Inputs, Output);
+    ExpCommand->setRedirectFiles({None, std::string(ExportList), None});
+    C.addCommand(std::move(ExpCommand)); 
+    CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-bE:") + ExportList));
+  }
+
   // Add directory to library search path.
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
Index: clang/lib/Driver/Job.cpp
===================================================================
--- clang/lib/Driver/Job.cpp
+++ clang/lib/Driver/Job.cpp
@@ -301,6 +301,10 @@
   Environment.push_back(nullptr);
 }
 
+void Command::setRedirectFiles(std::vector<Optional<std::string>> Redirects) {
+  RedirectFiles = Redirects;
+}
+
 void Command::PrintFileNames() const {
   if (PrintInputFilenames) {
     for (const auto &Arg : InputInfoList)
@@ -352,6 +356,21 @@
   }
 
   auto Args = llvm::toStringRefArray(Argv.data());
+
+  if (!RedirectFiles.empty()) {
+    std::vector<Optional<StringRef>> RedirectFilesOptional;
+    for (const auto &Ele : RedirectFiles)
+      if (Ele)
+        RedirectFilesOptional.push_back(Optional<StringRef>(*Ele));
+      else
+        RedirectFilesOptional.push_back(None);
+
+    return llvm::sys::ExecuteAndWait(Executable, Args, Env,
+                                     makeArrayRef(RedirectFilesOptional),
+                                     /*secondsToWait*/ 0, /*memoryLimit*/ 0,
+                                     ErrMsg, ExecutionFailed, &ProcStat);
+  }
+
   return llvm::sys::ExecuteAndWait(Executable, Args, Env, Redirects,
                                    /*secondsToWait*/ 0, /*memoryLimit*/ 0,
                                    ErrMsg, ExecutionFailed, &ProcStat);
Index: clang/include/clang/Driver/Job.h
===================================================================
--- clang/include/clang/Driver/Job.h
+++ clang/include/clang/Driver/Job.h
@@ -141,6 +141,9 @@
   /// See Command::setEnvironment
   std::vector<const char *> Environment;
 
+  /// Optional redirection for stdin, stdout, stderr.
+  std::vector<Optional<std::string>> RedirectFiles;
+
   /// Information on executable run provided by OS.
   mutable Optional<llvm::sys::ProcessStatistics> ProcStat;
 
@@ -204,6 +207,8 @@
   ///         from the parent process will be used.
   virtual void setEnvironment(llvm::ArrayRef<const char *> NewEnvironment);
 
+  void setRedirectFiles(std::vector<Optional<std::string>> Redirects);
+
   void replaceArguments(llvm::opt::ArgStringList List) {
     Arguments = std::move(List);
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to