Skip to content

Conversation

@perry-ca
Copy link
Contributor

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.

@perry-ca perry-ca self-assigned this May 22, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:SystemZ clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels May 22, 2025
@llvmbot
Copy link
Member

llvmbot commented May 22, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-systemz

Author: Sean Perry (perry-ca)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/141110.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/ZOS.cpp (+3-4)
  • (added) clang/test/Driver/zos-ld-sidedeck.c (+19)
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"

@perry-ca perry-ca requested review from abhina-sree, redstar and zibi2 May 22, 2025 17:42
Copy link
Member

@uweigand uweigand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@abhina-sree abhina-sree left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@zibi2 zibi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@perry-ca perry-ca merged commit d2eec93 into llvm:main May 25, 2025
15 checks passed
@perry-ca perry-ca deleted the perry/correct-sidedeck-name branch June 27, 2025 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:SystemZ clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants