[clang] [flang] [driver] Generalize the code that adds the path of libflang_rt.runtime.a. (PR #134362)

Daniel Chen via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 11 09:12:50 PDT 2025


================
@@ -7,35 +7,100 @@
 !! LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON, use 
 !! resource_dir_with_per_target_subdir as inputs.
 
-! Check powerpc64-ibm-aix 64-bit linking to static flang-rt
-! RUN: %flang %s -### 2>&1 \
+! Check powerpc64-ibm-aix 64-bit linking to static flang-rt by default
+! RUN: %flang -Werror %s -### 2>&1 \
 ! RUN:        --target=powerpc64-ibm-aix \
 ! RUN:        -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_per_target_subdir \
-! RUN:   | FileCheck %s --check-prefix=AIX64-LD-PER-TARGET
+! RUN:   | FileCheck %s --check-prefix=AIX64-LD-PER-TARGET-DEFAULT
 
-! AIX64-LD-PER-TARGET-NOT: warning:
-! AIX64-LD-PER-TARGET:     "-fc1" "-triple" "powerpc64-ibm-aix"
-! AIX64-LD-PER-TARGET-SAME:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-! AIX64-LD-PER-TARGET:     "{{.*}}ld{{(.exe)?}}"
-! AIX64-LD-PER-TARGET-NOT: "-bnso"
-! AIX64-LD-PER-TARGET-SAME:     "-b64"
-! AIX64-LD-PER-TARGET-SAME:     "-bpT:0x100000000" "-bpD:0x110000000"
-! AIX64-LD-PER-TARGET-SAME:     "-lc"
-! AIX64-LD-PER-TARGET-SAME:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64-ibm-aix{{/|\\\\}}libflang_rt.runtime.a"
-! AIX64-LD-PER-TARGET-SAME:     "-lm"
-! AIX64-LD-PER-TARGET-SAME:     "-lpthread"
-
-! Check powerpc64le-unknown-linux-gnu 64-bit linking to static flang-rt
-! RUN: %flang %s -### 2>&1 \
+! AIX64-LD-PER-TARGET-DEFAULT:     "-fc1" "-triple" "powerpc64-ibm-aix"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+! AIX64-LD-PER-TARGET-DEFAULT:     "{{.*}}ld{{(.exe)?}}"
+! AIX64-LD-PER-TARGET-DEFAULT-NOT: "-bnso"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "-b64"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "-bpT:0x100000000" "-bpD:0x110000000"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "-lc"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64-ibm-aix{{/|\\\\}}libflang_rt.runtime.a"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "-lm"
+! AIX64-LD-PER-TARGET-DEFAULT-SAME:     "-lpthread"
+
+
+! Check powerpc64-ibm-aix 64-bit linking to static flang-rt by option 
+! RUN: %flang -static-libflangrt -Werror %s -### 2>&1 \
+! RUN:        --target=powerpc64-ibm-aix \
+! RUN:        -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_per_target_subdir \
+! RUN:   | FileCheck %s --check-prefix=AIX64-LD-PER-TARGET-STATIC
+
+! AIX64-LD-PER-TARGET-STATIC:     "-fc1" "-triple" "powerpc64-ibm-aix"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+! AIX64-LD-PER-TARGET-STATIC:     "{{.*}}ld{{(.exe)?}}"
+! AIX64-LD-PER-TARGET-STATIC-NOT: "-bnso"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "-b64"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "-bpT:0x100000000" "-bpD:0x110000000"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "-lc"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64-ibm-aix{{/|\\\\}}libflang_rt.runtime.a"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "-lm"
+! AIX64-LD-PER-TARGET-STATIC-SAME:     "-lpthread"
+
+
+! Check powerpc64-ibm-aix 64-bit linking to shared flang-rt by option 
+! RUN: %flang -shared-libflangrt -Werror %s -### 2>&1 \
+! RUN:        --target=powerpc64-ibm-aix \
+! RUN:        -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_per_target_subdir \
+! RUN:   | FileCheck %s --check-prefix=AIX64-LD-PER-TARGET-SHARED
+
+! AIX64-LD-PER-TARGET-SHARED:     "-fc1" "-triple" "powerpc64-ibm-aix"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+! AIX64-LD-PER-TARGET-SHARED:     "{{.*}}ld{{(.exe)?}}"
+! AIX64-LD-PER-TARGET-SHARED-NOT: "-bnso"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "-b64"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "-bpT:0x100000000" "-bpD:0x110000000"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "-lc"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64-ibm-aix{{/|\\\\}}libflang_rt.runtime.a"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "-lm"
+! AIX64-LD-PER-TARGET-SHARED-SAME:     "-lpthread"
+
+
+! Check powerpc64le-unknown-linux-gnu 64-bit linking to shared flang-rt by default
+! RUN: %flang -Werror %s -### 2>&1 \
 ! RUN:        --target=powerpc64le-unknown-linux-gnu \
 ! RUN:        -resource-dir=%S/../../../clang/test/Driver/Inputs/resource_dir_with_per_target_subdir \
-! RUN:   | FileCheck %s --check-prefixes=LOP64-LD-PER-TARGET
-
-! LOP64-LD-PER-TARGET-NOT: warning:
-! LOP64-LD-PER-TARGET:     "-fc1" "-triple" "powerpc64le-unknown-linux-gnu"
-! LOP64-LD-PER-TARGET-SAME:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-! LOP64-LD-PER-TARGET:     "{{.*}}ld{{(.exe)?}}"
-! LOP64-LD-PER-TARGET-NOT: "-bnso"
-! LOP64-LD-PER-TARGET-SAME:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64le-unknown-linux-gnu{{/|\\\\}}libflang_rt.runtime.a"
-! LOP64-LD-PER-TARGET-SAME:     "-lm"
-! LOP64-LD-PER-TARGET-SAME:     "-lc"
+! RUN:   | FileCheck %s --check-prefixes=LOP64-LD-PER-TARGET-DEFAULT
+
+! LOP64-LD-PER-TARGET-DEFAULT:     "-fc1" "-triple" "powerpc64le-unknown-linux-gnu"
+! LOP64-LD-PER-TARGET-DEFAULT-SAME:     "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+! LOP64-LD-PER-TARGET-DEFAULT:     "{{.*}}ld{{(.exe)?}}"
+! LOP64-LD-PER-TARGET-DEFAULT-NOT: "-bnso"
+! LOP64-LD-PER-TARGET-DEFAULT-SAME:     "[[RESOURCE_DIR]]{{/|\\\\}}lib{{/|\\\\}}powerpc64le-unknown-linux-gnu{{/|\\\\}}libflang_rt.runtime.so"
----------------
DanielCChen wrote:

> Thank you for waiting!
> 
> I believe linking the shared library with the full path does not allow any relocation of LLVM/Flang's redistributable libraries. If you link the library in such a way to an executable, the dynamic linker will look for this library only at the full path location. So how do we suggest the application providers that use Flang to distribute their apps?
> 
> If we keep using `-lflang_rt.runtime`, then they will be able to distribute Flang's redistributables with their apps and either embed proper `rpath` relying on the final installation or set proper environment vars at the installation host.

Thanks for the comment!

This may not be an issue at least on Linux. No matter if it is `-lflang_rt.runtime` or the full path to `libflang_rt.runtime.so`, users still need to use either `LD_LIBRARY_PATH` or `-rpath` to specify where the library is at loading time. As long as it points to the correct path after relocation, it should be OK. The path specified by `-rpath` is written into the executable.  I am not sure about other platforms though. 

https://github.com/llvm/llvm-project/pull/134362


More information about the cfe-commits mailing list