Skip to content

Commit 1d4601a

Browse files
authored
[Driver] Corrections for linker flags passed with relocatable linking on OpenBSD (llvm#67254)
The entry point symbol handling matches our GCC link spec.. ```%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}}``` Remove usage of -Bdynamic as it is the default for the linker anyway. Came up in discussion here llvm#65644
1 parent a95d4b7 commit 1d4601a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clang/lib/Driver/ToolChains/OpenBSD.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
121121
bool Profiling = Args.hasArg(options::OPT_pg);
122122
bool Pie = Args.hasArg(options::OPT_pie);
123123
bool Nopie = Args.hasArg(options::OPT_nopie);
124+
const bool Relocatable = Args.hasArg(options::OPT_r);
124125

125126
// Silence warning for "clang -g foo.o -o foo"
126127
Args.ClaimAllArgs(options::OPT_g_Group);
@@ -138,7 +139,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
138139
else if (Arch == llvm::Triple::mips64el)
139140
CmdArgs.push_back("-EL");
140141

141-
if (!Args.hasArg(options::OPT_nostdlib) && !Shared) {
142+
if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) {
142143
CmdArgs.push_back("-e");
143144
CmdArgs.push_back("__start");
144145
}
@@ -149,10 +150,9 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
149150
} else {
150151
if (Args.hasArg(options::OPT_rdynamic))
151152
CmdArgs.push_back("-export-dynamic");
152-
CmdArgs.push_back("-Bdynamic");
153153
if (Shared) {
154154
CmdArgs.push_back("-shared");
155-
} else if (!Args.hasArg(options::OPT_r)) {
155+
} else if (!Relocatable) {
156156
CmdArgs.push_back("-dynamic-linker");
157157
CmdArgs.push_back("/usr/libexec/ld.so");
158158
}

clang/test/Driver/openbsd.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// RUN: %clang --target=i686-pc-openbsd -pg -pthread -### %s 2>&1 \
99
// RUN: | FileCheck --check-prefix=CHECK-PG %s
1010
// CHECK-PG: "-cc1" "-triple" "i686-pc-openbsd"
11-
// CHECK-PG: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-nopie" "-o" "a.out" "{{.*}}gcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lcompiler_rt" "-lpthread_p" "-lc_p" "-lcompiler_rt" "{{.*}}crtend.o"
11+
// CHECK-PG: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld.so" "-nopie" "-o" "a.out" "{{.*}}gcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lcompiler_rt" "-lpthread_p" "-lc_p" "-lcompiler_rt" "{{.*}}crtend.o"
1212

1313
// Check CPU type for i386
1414
// RUN: %clang --target=i386-unknown-openbsd -### -c %s 2>&1 \
@@ -34,18 +34,19 @@
3434
// RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s
3535
// RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \
3636
// RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
37-
// CHECK-LD-R: "-r"
37+
// CHECK-LD-R-NOT: "-e"
3838
// CHECK-LD-R-NOT: "-dynamic-linker"
3939
// CHECK-LD-R-NOT: "-l
4040
// CHECK-LD-R-NOT: crt{{[^./\\]+}}.o
41+
// CHECK-LD-R: "-r"
4142
// CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
42-
// CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
43+
// CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
4344
// CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd"
44-
// CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
45+
// CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
4546
// CHECK-MIPS64-LD: "-cc1" "-triple" "mips64-unknown-openbsd"
46-
// CHECK-MIPS64-LD: ld{{.*}}" "-EB" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
47+
// CHECK-MIPS64-LD: ld{{.*}}" "-EB" "-e" "__start" "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
4748
// CHECK-MIPS64EL-LD: "-cc1" "-triple" "mips64el-unknown-openbsd"
48-
// CHECK-MIPS64EL-LD: ld{{.*}}" "-EL" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
49+
// CHECK-MIPS64EL-LD: ld{{.*}}" "-EL" "-e" "__start" "--eh-frame-hdr" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lcompiler_rt" "-lc" "-lcompiler_rt" "{{.*}}crtend.o"
4950

5051
// Check that --sysroot is passed to the linker
5152
// RUN: %clang --target=i686-pc-openbsd -### %s 2>&1 \

0 commit comments

Comments
 (0)