-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver] Corrections for linker flags passed with relocatable linking on OpenBSD #67254
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
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang ChangesThe entry point symbol handling matches our GCC link spec.. Came up in discussion here #65644 Full diff: https://github.com/llvm/llvm-project/pull/67254.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index 91fe3837b813333..8d88379ef4c10e7 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -121,6 +121,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
bool Profiling = Args.hasArg(options::OPT_pg);
bool Pie = Args.hasArg(options::OPT_pie);
bool Nopie = Args.hasArg(options::OPT_nopie);
+ bool Relocatable = Args.hasArg(options::OPT_r);
// Silence warning for "clang -g foo.o -o foo"
Args.ClaimAllArgs(options::OPT_g_Group);
@@ -138,7 +139,7 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
else if (Arch == llvm::Triple::mips64el)
CmdArgs.push_back("-EL");
- if (!Args.hasArg(options::OPT_nostdlib) && !Shared) {
+ if (!Args.hasArg(options::OPT_nostdlib) && !Shared && !Relocatable) {
CmdArgs.push_back("-e");
CmdArgs.push_back("__start");
}
@@ -149,10 +150,11 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
} else {
if (Args.hasArg(options::OPT_rdynamic))
CmdArgs.push_back("-export-dynamic");
- CmdArgs.push_back("-Bdynamic");
+ if (!Relocatable)
+ CmdArgs.push_back("-Bdynamic");
if (Shared) {
CmdArgs.push_back("-shared");
- } else if (!Args.hasArg(options::OPT_r)) {
+ } else if (!Relocatable) {
CmdArgs.push_back("-dynamic-linker");
CmdArgs.push_back("/usr/libexec/ld.so");
}
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 05d290a309c40c0..a8db20200cd473d 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -36,10 +36,12 @@
// RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s
// RUN: %clang --target=mips64el-unknown-openbsd -### %s 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s
-// CHECK-LD-R: "-r"
+// CHECK-LD-R-NOT: "-e" "__start"
+// CHECK-LD-R-NOT: "-Bdynamic"
// CHECK-LD-R-NOT: "-dynamic-linker"
// CHECK-LD-R-NOT: "-l
// CHECK-LD-R-NOT: crt{{[^./\\]+}}.o
+// CHECK-LD-R: "-r"
// CHECK-LD-S: "-cc1" "-triple" "i686-pc-openbsd"
// 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"
// CHECK-LD-T: "-cc1" "-triple" "i686-pc-openbsd"
|
reloctable→relocatable Just a fly-by, but IMO the commit message ought to describe the change – "some changes" doesn't give much insight. |
688d4e9
to
fdcdea6
Compare
fdcdea6
to
c638c2f
Compare
@MaskRay Can you comment on the -Bdynamic part? Is that appropriate for relocatable linking? |
@MaskRay ping. |
|
… on OpenBSD 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.
c638c2f
to
d16c447
Compare
Local branch amd-gfx 13ef517 Merged main:71bdd2c2380d into amd-gfx:319c66a13c02 Remote branch main 1d4601a [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 #65644