Skip to content

[Driver] Fix -r handling on Solaris #70322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2023
Merged

Conversation

rorth
Copy link
Collaborator

@rorth rorth commented Oct 26, 2023

As discussed in [Driver] Link Flang runtime on Solaris, clang -r incorrectly passes both -Bdynamic and -e _start to ld which lets the linker choke.

This patch fixes this, omitting -Bdynamic completely which is the linker default.

Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11.

As discussed in [[Driver] Link Flang runtime on
Solaris](llvm#65644), `clang -r`
incorrectly passes both `-Bdynamic` and `-e _start` to `ld` which lets the
linker choke.

This patch fixes this, omitting `-Bdynamic` completely which is the linker
default.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
@rorth rorth requested review from MaskRay and brad0 October 26, 2023 12:07
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Oct 26, 2023
@llvmbot
Copy link
Member

llvmbot commented Oct 26, 2023

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Rainer Orth (rorth)

Changes

As discussed in [Driver] Link Flang runtime on Solaris, clang -r incorrectly passes both -Bdynamic and -e _start to ld which lets the linker choke.

This patch fixes this, omitting -Bdynamic completely which is the linker default.

Tested on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11.


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

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Solaris.cpp (+3-4)
  • (modified) clang/test/Driver/solaris-ld.c (+1)
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp
index ecff8ddc4ee766f..2b1ac5a7f475c5a 100644
--- a/clang/lib/Driver/ToolChains/Solaris.cpp
+++ b/clang/lib/Driver/ToolChains/Solaris.cpp
@@ -96,7 +96,8 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
   if (!LinkerIsGnuLd)
     CmdArgs.push_back("-C");
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared,
+                   options::OPT_r)) {
     CmdArgs.push_back("-e");
     CmdArgs.push_back("_start");
   }
@@ -114,10 +115,8 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-Bstatic");
     CmdArgs.push_back("-dn");
   } else {
-    CmdArgs.push_back("-Bdynamic");
-    if (Args.hasArg(options::OPT_shared)) {
+    if (!Args.hasArg(options::OPT_r) && Args.hasArg(options::OPT_shared))
       CmdArgs.push_back("-shared");
-    }
 
     // libpthread has been folded into libc since Solaris 10, no need to do
     // anything for pthreads. Claim argument to avoid warning.
diff --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 09e6e8b4f07cf91..8f7f168c387214d 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/clang/test/Driver/solaris-ld.c
@@ -177,6 +177,7 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
 // CHECK-RELOCATABLE:     "-L
 // CHECK-RELOCATABLE:     "-r"
+// CHECK-RELOCATABLE-NOT: "-e"
 // CHECK-RELOCATABLE-NOT: "-l
 // CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
 // CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o

@rorth rorth merged commit 183158b into llvm:main Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants