hubert.reinterpretcast created this revision.
hubert.reinterpretcast added reviewers: nemanjai, jsji, daltenty, stevewan, 
jasonliu.
Herald added subscribers: atanasyan, jrtc27, mgorny.
Herald added a project: clang.
hubert.reinterpretcast edited the summary of this revision.

Some target toolchains use more than just a default `--sysroot`, but also 
include a default `--dyld-prefix` and an implicitly-added `-rpath`.

For example, using a vanilla build of Clang with the IBM Advance Toolchain for 
Linux on Power would require specifying `--sysroot=/opt/at12.0 
--dyld-prefix=/opt/at12.0 -rpath /opt/at12.0/lib64`. The GCC compiler provided 
with the Advance Toolchain is preconfigured such that adding such options is 
not necessary. This patch adds the configuration hooks that would allow Clang 
to be preconfigured similarly.

Note: The `DEFAULT_RPATH` behaviour has only been implemented for "GNU" 
toolchains.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80300

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/fuchsia.c
  clang/test/Driver/fuchsia.cpp
  clang/test/Driver/hurd.c
  clang/test/Driver/linux-ld.c
  clang/test/Driver/mips-mti.cpp

Index: clang/test/Driver/mips-mti.cpp
===================================================================
--- clang/test/Driver/mips-mti.cpp
+++ clang/test/Driver/mips-mti.cpp
@@ -5,6 +5,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -mhard-float -mabi=32 \
 // RUN:   | FileCheck --check-prefix=EB-HARD-O32 %s
@@ -34,6 +35,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -mhard-float -mabi=n32 \
 // RUN:   | FileCheck --check-prefix=EB-HARD-N32 %s
@@ -63,6 +65,7 @@
 // RUN:        --target=mips64-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -mhard-float -mabi=64 \
 // RUN:   | FileCheck --check-prefix=EB-HARD-N64 %s
@@ -92,6 +95,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -mabi=32 \
 // RUN:   | FileCheck --check-prefix=EL-HARD-O32 %s
@@ -121,6 +125,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -mabi=n32 \
 // RUN:   | FileCheck --check-prefix=EL-HARD-N32 %s
@@ -150,6 +155,7 @@
 // RUN:        --target=mips64-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -mabi=64 \
 // RUN:   | FileCheck --check-prefix=EL-HARD-N64 %s
@@ -179,6 +185,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -msoft-float \
 // RUN:   | FileCheck --check-prefix=EB-SOFT %s
@@ -208,6 +215,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -msoft-float \
 // RUN:   | FileCheck --check-prefix=EL-SOFT %s
@@ -237,6 +245,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -mhard-float -muclibc \
 // RUN:   | FileCheck --check-prefix=EB-HARD-UCLIBC %s
@@ -266,6 +275,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -muclibc \
 // RUN:   | FileCheck --check-prefix=EL-HARD-UCLIBC %s
@@ -295,6 +305,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -mhard-float -mnan=2008 \
 // RUN:   | FileCheck --check-prefix=EB-HARD-NAN2008 %s
@@ -324,6 +335,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -mnan=2008 \
 // RUN:   | FileCheck --check-prefix=EL-HARD-NAN2008 %s
@@ -353,6 +365,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EB -mhard-float -muclibc -mnan=2008 \
 // RUN:   | FileCheck --check-prefix=EB-HARD-UCLIBC-NAN2008 %s
@@ -382,6 +395,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -muclibc -mnan=2008 \
 // RUN:   | FileCheck --check-prefix=EL-HARD-UCLIBC-NAN2008 %s
@@ -411,6 +425,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -msoft-float -mmicromips \
 // RUN:   | FileCheck --check-prefix=EL-SOFT-MICRO %s
@@ -440,6 +455,7 @@
 // RUN:        --target=mips-mti-linux-gnu \
 // RUN:        --gcc-toolchain=%S/Inputs/mips_mti_tree \
 // RUN:        --sysroot="" \
+// RUN:        --dyld-prefix="" \
 // RUN:        -stdlib=libstdc++ \
 // RUN:        -EL -mhard-float -mmicromips -mnan=2008 \
 // RUN:   | FileCheck --check-prefix=EL-SOFT-MICRO-NAN2008 %s
Index: clang/test/Driver/linux-ld.c
===================================================================
--- clang/test/Driver/linux-ld.c
+++ clang/test/Driver/linux-ld.c
@@ -662,6 +662,7 @@
 // RUN:     --target=arm-linux-gnueabihf -rtlib=platform \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/x86-64_ubuntu_13.10 \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-X86-64-UBUNTU-13-10-ARM-HF %s
 // CHECK-X86-64-UBUNTU-13-10-ARM-HF: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-X86-64-UBUNTU-13-10-ARM-HF: "-dynamic-linker" "{{(/usr/arm--linux-gnueabihf)?}}/lib/ld-linux-armhf.so.3"
@@ -681,6 +682,7 @@
 // RUN:     --target=arm-linux-gnueabi -rtlib=platform \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/x86-64_ubuntu_13.10 \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-X86-64-UBUNTU-13-10-ARM %s
 // CHECK-X86-64-UBUNTU-13-10-ARM: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-X86-64-UBUNTU-13-10-ARM: "-dynamic-linker" "{{(/usr/arm--linux-gnueabi)?}}/lib/ld-linux.so.3"
@@ -1123,6 +1125,7 @@
 //
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=sparc-unknown-linux-gnu \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARCV8 %s
 // CHECK-SPARCV8: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV8: "-m" "elf32_sparc"
@@ -1130,6 +1133,7 @@
 //
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=sparcel-unknown-linux-gnu \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARCV8EL %s
 // CHECK-SPARCV8EL: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV8EL: "-m" "elf32_sparc"
@@ -1137,6 +1141,7 @@
 //
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=sparcv9-unknown-linux-gnu \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARCV9 %s
 // CHECK-SPARCV9: "{{.*}}ld{{(.exe)?}}"
 // CHECK-SPARCV9: "-m" "elf64_sparc"
@@ -1565,41 +1570,49 @@
 // RUN:     --target=arm-linux-androideabi \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-32 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=arm-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-32 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=mipsel-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-32 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=aarch64-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-64 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=arm64-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-64 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=mips64el-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-64 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=i686-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-32 %s
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     --target=x86_64-linux-android \
 // RUN:     --gcc-toolchain="" \
 // RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-ANDROID-64 %s
 // CHECK-ANDROID-32: "-dynamic-linker" "/system/bin/linker"
 // CHECK-ANDROID-64: "-dynamic-linker" "/system/bin/linker64"
@@ -1995,69 +2008,91 @@
 // Check dynamic-linker for musl-libc
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=i386-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-X86 %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=x86_64-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-X86_64 %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=mips-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-MIPS %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=mipsel-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-MIPSEL %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=mips64-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-MIPS64 %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=mips64el-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-MIPS64EL %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=powerpc-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-PPC %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=powerpc64-pc-linux-musl \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-PPC64 %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=thumb-pc-linux-musleabi \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARM %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=thumb-pc-linux-musleabihf \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=thumbv7-pc-linux-musleabi -mhard-float \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=thumbeb-pc-linux-musleabi \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=thumbeb-pc-linux-musleabihf \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=thumbv7eb-pc-linux-musleabi -mhard-float \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=arm-pc-linux-musleabi \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARM %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=arm-pc-linux-musleabihf \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=armv7-pc-linux-musleabi -mhard-float \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=armeb-pc-linux-musleabi \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=armeb-pc-linux-musleabihf \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=armv7eb-pc-linux-musleabi -mhard-float \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=aarch64-pc-linux-musleabi \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-AARCH64 %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN:     --target=aarch64_be-pc-linux-musleabi \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-AARCH64_BE %s
 // CHECK-MUSL-X86:        "-dynamic-linker" "/lib/ld-musl-i386.so.1"
 // CHECK-MUSL-X86_64:     "-dynamic-linker" "/lib/ld-musl-x86_64.so.1"
Index: clang/test/Driver/hurd.c
===================================================================
--- clang/test/Driver/hurd.c
+++ clang/test/Driver/hurd.c
@@ -1,6 +1,7 @@
 // RUN: %clang -no-canonical-prefixes %s -### 2>&1 \
 // RUN:     --target=i386-pc-gnu \
 // RUN:     --sysroot=%S/Inputs/basic_hurd_tree \
+// RUN:     --dyld-prefix="" \
 // RUN:   | FileCheck --check-prefix=CHECK %s
 // CHECK-NOT: warning:
 // CHECK: "-cc1"
Index: clang/test/Driver/fuchsia.cpp
===================================================================
--- clang/test/Driver/fuchsia.cpp
+++ clang/test/Driver/fuchsia.cpp
@@ -1,17 +1,17 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-fuchsia \
 // RUN:     -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     --sysroot=%S/platform --dyld-prefix="" -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=aarch64-fuchsia \
 // RUN:     -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     --sysroot=%S/platform --dyld-prefix="" -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=riscv64-fuchsia \
 // RUN:     -ccc-install-dir %S/Inputs/basic_fuchsia_tree/bin \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     --sysroot=%S/platform --dyld-prefix="" -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
Index: clang/test/Driver/fuchsia.c
===================================================================
--- clang/test/Driver/fuchsia.c
+++ clang/test/Driver/fuchsia.c
@@ -1,14 +1,14 @@
 // RUN: %clang %s -### -no-canonical-prefixes --target=x86_64-fuchsia \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     --sysroot=%S/platform --dyld-prefix="" -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-X86_64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=aarch64-fuchsia \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     --sysroot=%S/platform --dyld-prefix="" -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-AARCH64 %s
 // RUN: %clang %s -### -no-canonical-prefixes --target=riscv64-fuchsia \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN:     --sysroot=%S/platform -fuse-ld=lld 2>&1 \
+// RUN:     --sysroot=%S/platform --dyld-prefix="" -fuse-ld=lld 2>&1 \
 // RUN:     | FileCheck -check-prefixes=CHECK,CHECK-RISCV64 %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
 // CHECK-X86_64: "-triple" "x86_64-unknown-fuchsia"
@@ -96,6 +96,7 @@
 // RUN:     -fsanitize=address 2>&1 \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:     -fuse-ld=lld \
+// RUN:     --dyld-prefix="" \
 // RUN:     | FileCheck %s -check-prefix=CHECK-ASAN-X86
 // CHECK-ASAN-X86: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-ASAN-X86: "-fsanitize=address"
@@ -108,6 +109,7 @@
 // RUN:     -fsanitize=address 2>&1 \
 // RUN:     -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
 // RUN:     -fuse-ld=lld \
+// RUN:     --dyld-prefix="" \
 // RUN:     | FileCheck %s -check-prefix=CHECK-ASAN-AARCH64
 // CHECK-ASAN-AARCH64: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-ASAN-AARCH64: "-fsanitize=address,shadow-call-stack"
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -448,10 +448,9 @@
       CmdArgs.push_back("-export-dynamic");
 
     if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) {
-      const std::string Loader =
-          D.DyldPrefix + ToolChain.getDynamicLinker(Args);
       CmdArgs.push_back("-dynamic-linker");
-      CmdArgs.push_back(Args.MakeArgString(Loader));
+      CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) +
+                                           ToolChain.getDynamicLinker(Args)));
     }
   }
 
@@ -527,6 +526,12 @@
   // The profile runtime also needs access to system libraries.
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
+  if (!IsStatic && !IsStaticPIE && !StringRef(DEFAULT_RPATH).empty() &&
+      !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+    CmdArgs.push_back("-rpath");
+    CmdArgs.push_back(DEFAULT_RPATH);
+  }
+
   if (D.CCCIsCXX() &&
       !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
     if (ToolChain.ShouldLinkCXXStdlib(Args)) {
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -125,13 +125,13 @@
     : Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode),
       SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None),
       ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
-      DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr),
-      CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
-      CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false),
-      CCLogDiagnostics(false), CCGenDiagnostics(false),
-      TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc),
-      CheckInputsExist(true), GenReproducer(false),
-      SuppressMissingInputWarning(false) {
+      DyldPrefix(DEFAULT_DYLD_PREFIX), DriverTitle("clang LLVM compiler"),
+      CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr),
+      CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false),
+      CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false),
+      CCGenDiagnostics(false), TargetTriple(TargetTriple),
+      CCCGenericGCCName(""), Saver(Alloc), CheckInputsExist(true),
+      GenReproducer(false), SuppressMissingInputWarning(false) {
   // Provide a sane fallback if no VFS is specified.
   if (!this->VFS)
     this->VFS = llvm::vfs::getRealFileSystem();
Index: clang/include/clang/Config/config.h.cmake
===================================================================
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -51,6 +51,12 @@
 #cmakedefine CLANG_CONFIG_FILE_SYSTEM_DIR "${CLANG_CONFIG_FILE_SYSTEM_DIR}"
 #cmakedefine CLANG_CONFIG_FILE_USER_DIR "${CLANG_CONFIG_FILE_USER_DIR}"
 
+/* Default <path> to all compiler invocations for --dyld-prefix=<path>. */
+#define DEFAULT_DYLD_PREFIX "${DEFAULT_DYLD_PREFIX}"
+
+/* Default <path> to all compiler invocations appended as -rpath <path>. */
+#define DEFAULT_RPATH "${DEFAULT_RPATH}"
+
 /* Default <path> to all compiler invocations for --sysroot=<path>. */
 #define DEFAULT_SYSROOT "${DEFAULT_SYSROOT}"
 
Index: clang/CMakeLists.txt
===================================================================
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -226,6 +226,10 @@
   "Colon separated list of directories clang will search for headers.")
 
 set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
+set(DEFAULT_DYLD_PREFIX "" CACHE STRING
+  "Default <path> to all compiler invocations for --dyld-prefix=<path>." )
+set(DEFAULT_RPATH "" CACHE STRING
+  "Default <path> to all compiler invocations appended as -rpath <path>." )
 set(DEFAULT_SYSROOT "" CACHE STRING
   "Default <path> to all compiler invocations for --sysroot=<path>." )
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to