Skip to content

Commit 8a98b2f

Browse files
committed
[Driver] Fix -r handling on Solaris
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`.
1 parent 658874e commit 8a98b2f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

clang/lib/Driver/ToolChains/Solaris.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
9696
if (!LinkerIsGnuLd)
9797
CmdArgs.push_back("-C");
9898

99-
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared)) {
99+
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_shared,
100+
options::OPT_r)) {
100101
CmdArgs.push_back("-e");
101102
CmdArgs.push_back("_start");
102103
}
@@ -114,10 +115,8 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
114115
CmdArgs.push_back("-Bstatic");
115116
CmdArgs.push_back("-dn");
116117
} else {
117-
CmdArgs.push_back("-Bdynamic");
118-
if (Args.hasArg(options::OPT_shared)) {
118+
if (!Args.hasArg(options::OPT_r) && Args.hasArg(options::OPT_shared))
119119
CmdArgs.push_back("-shared");
120-
}
121120

122121
// libpthread has been folded into libc since Solaris 10, no need to do
123122
// anything for pthreads. Claim argument to avoid warning.

clang/test/Driver/solaris-ld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
// RUN: | FileCheck %s --check-prefix=CHECK-RELOCATABLE
178178
// CHECK-RELOCATABLE: "-L
179179
// CHECK-RELOCATABLE: "-r"
180+
// CHECK-RELOCATABLE-NOT: "-e"
180181
// CHECK-RELOCATABLE-NOT: "-l
181182
// CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
182183
// CHECK-RELOCATABLE-NOT: /values-{{[^.]+}}.o

0 commit comments

Comments
 (0)