[clang] d2eec93 - replace the extension with the right functions (#141110)

via cfe-commits cfe-commits at lists.llvm.org
Sun May 25 12:07:23 PDT 2025


Author: Sean Perry
Date: 2025-05-25T15:07:20-04:00
New Revision: d2eec93f7c652946e98b4c872ddf1d353b28dabe

URL: https://github.com/llvm/llvm-project/commit/d2eec93f7c652946e98b4c872ddf1d353b28dabe
DIFF: https://github.com/llvm/llvm-project/commit/d2eec93f7c652946e98b4c872ddf1d353b28dabe.diff

LOG: replace the extension with the right functions (#141110)

Using a relative path name for the shared library name was causing the
side deck name to be incorrect. Fixed the code by using the
`replace_exentsion()` function.

Added: 
    clang/test/Driver/zos-ld-sidedeck.c

Modified: 
    clang/lib/Driver/ToolChains/ZOS.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/ZOS.cpp b/clang/lib/Driver/ToolChains/ZOS.cpp
index c5ad3ef1b00f1..263e1e3c68d53 100644
--- a/clang/lib/Driver/ToolChains/ZOS.cpp
+++ b/clang/lib/Driver/ToolChains/ZOS.cpp
@@ -153,11 +153,10 @@ void zos::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     StringRef OutputName = Output.getFilename();
     // Strip away the last file suffix in presence from output name and add
     // a new .x suffix.
-    size_t Suffix = OutputName.find_last_of('.');
-    const char *SideDeckName =
-        Args.MakeArgString(OutputName.substr(0, Suffix) + ".x");
+    SmallString<128> SideDeckName = OutputName;
+    llvm::sys::path::replace_extension(SideDeckName, "x");
     CmdArgs.push_back("-x");
-    CmdArgs.push_back(SideDeckName);
+    CmdArgs.push_back(Args.MakeArgString(SideDeckName));
   } else {
     // We need to direct side file to /dev/null to suppress linker warning when
     // the object file contains exported symbols, and -shared or

diff  --git a/clang/test/Driver/zos-ld-sidedeck.c b/clang/test/Driver/zos-ld-sidedeck.c
new file mode 100644
index 0000000000000..1b7c711cd788e
--- /dev/null
+++ b/clang/test/Driver/zos-ld-sidedeck.c
@@ -0,0 +1,19 @@
+// Try using various forms of output file name to see what side deck file name looks like
+// RUN: %clang -### --shared --target=s390x-ibm-zos %s -o foo.out 2>&1 \
+// RUN:   | FileCheck --check-prefix=SD-BASE %s
+// RUN: %clang -### --shared --target=s390x-ibm-zos %s -o foo 2>&1 \
+// RUN:   | FileCheck --check-prefix=SD-BASE %s
+// SD-BASE: "-x" "foo.x"
+
+// RUN: %clang -### --shared --target=s390x-ibm-zos %s -o lib/foo.out 2>&1 \
+// RUN:   | FileCheck --check-prefix=SD-SUBDIR %s
+// RUN: %clang -### --shared --target=s390x-ibm-zos %s -o lib/foo 2>&1 \
+// RUN:   | FileCheck --check-prefix=SD-SUBDIR %s
+// SD-SUBDIR: "-x" "lib/foo.x"
+
+
+// RUN: %clang -### --shared --target=s390x-ibm-zos %s -o ../lib/foo.out 2>&1 \
+// RUN:   | FileCheck --check-prefix=SD-REL %s
+// RUN: %clang -### --shared --target=s390x-ibm-zos %s -o ../lib/foo 2>&1 \
+// RUN:   | FileCheck --check-prefix=SD-REL %s
+// SD-REL: "-x" "../lib/foo.x"


        


More information about the cfe-commits mailing list