[clang] [Driver] Some adjustments for reloctable linking on OpenBSD (PR #67254)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 23 21:27:46 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
<details>
<summary>Changes</summary>
The entry point symbol handling matches our GCC link spec.. ```%{!shared:%{!nostdlib:%{!r:%{!e*:-e __start}}}}```
Came up in discussion here https://github.com/llvm/llvm-project/pull/65644
---
Full diff: https://github.com/llvm/llvm-project/pull/67254.diff
2 Files Affected:
- (modified) clang/lib/Driver/ToolChains/OpenBSD.cpp (+5-3)
- (modified) clang/test/Driver/openbsd.c (+3-1)
``````````diff
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"
``````````
</details>
https://github.com/llvm/llvm-project/pull/67254
More information about the cfe-commits
mailing list