-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver] Add LTO support for Haiku and OpenBSD #72047
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Brad Smith (brad0) ChangesFull diff: https://github.com/llvm/llvm-project/pull/72047.diff 7 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index a81c9b6201f8158..5d2cd1959b06925 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -598,7 +598,8 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
const Driver &D = ToolChain.getDriver();
if (llvm::sys::path::filename(Linker) != "ld.lld" &&
- llvm::sys::path::stem(Linker) != "ld.lld") {
+ llvm::sys::path::stem(Linker) != "ld.lld" &&
+ !ToolChain.getTriple().isOSOpenBSD()) {
// Tell the linker to load the plugin. This has to come before
// AddLinkerInputs as gold requires -plugin and AIX ld requires -bplugin to
// come before any -plugin-opt/-bplugin_opt that -Wl might forward.
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp b/clang/lib/Driver/ToolChains/Haiku.cpp
index 1c2d6bcaf9b457d..e0d94035823fd37 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -83,6 +83,20 @@ void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_s, options::OPT_t, options::OPT_r});
ToolChain.AddFilePathLibArgs(Args, CmdArgs);
+ if (D.isUsingLTO()) {
+ assert(!Inputs.empty() && "Must have at least one input.");
+ // Find the first filename InputInfo object.
+ auto Input = llvm::find_if(
+ Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+ if (Input == Inputs.end())
+ // For a very rare case, all of the inputs to the linker are
+ // InputArg. If that happens, just use the first InputInfo.
+ Input = Inputs.begin();
+
+ addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
+ D.getLTOMode() == LTOK_Thin);
+ }
+
addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
diff --git a/clang/lib/Driver/ToolChains/OpenBSD.cpp b/clang/lib/Driver/ToolChains/OpenBSD.cpp
index d9f6b20f43ad854..798b39ce86badce 100644
--- a/clang/lib/Driver/ToolChains/OpenBSD.cpp
+++ b/clang/lib/Driver/ToolChains/OpenBSD.cpp
@@ -195,6 +195,20 @@ void openbsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.addAllArgs(CmdArgs, {options::OPT_T_Group, options::OPT_s,
options::OPT_t, options::OPT_r});
+ if (D.isUsingLTO()) {
+ assert(!Inputs.empty() && "Must have at least one input.");
+ // Find the first filename InputInfo object.
+ auto Input = llvm::find_if(
+ Inputs, [](const InputInfo &II) -> bool { return II.isFilename(); });
+ if (Input == Inputs.end())
+ // For a very rare case, all of the inputs to the linker are
+ // InputArg. If that happens, just use the first InputInfo.
+ Input = Inputs.begin();
+
+ addLTOOptions(ToolChain, Args, CmdArgs, Output, *Input,
+ D.getLTOMode() == LTOK_Thin);
+ }
+
bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
diff --git a/clang/test/Driver/emulated-tls.cpp b/clang/test/Driver/emulated-tls.cpp
index 2044bc89a36634a..3ee901a8358589e 100644
--- a/clang/test/Driver/emulated-tls.cpp
+++ b/clang/test/Driver/emulated-tls.cpp
@@ -39,6 +39,8 @@
// RUN: | FileCheck %s --check-prefix=LTO_EMUTLS
// RUN: %clang -### -flto --target=riscv64-linux-android10000 -fno-emulated-tls %s 2>&1 \
// RUN: | FileCheck %s --check-prefix=LTO_NOEMUTLS
+// RUN: %clang -### -flto --target=amd64-unknown-openbsd %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=LTO_EMUTLS
// Default without -f[no-]emulated-tls, will be decided by the target triple.
// DEFAULT-NOT: "-cc1" {{.*}}"-femulated-tls"
diff --git a/clang/test/Driver/haiku.c b/clang/test/Driver/haiku.c
index 965d3cf97bc36bf..e907c34b29b9955 100644
--- a/clang/test/Driver/haiku.c
+++ b/clang/test/Driver/haiku.c
@@ -75,3 +75,8 @@
// RUN: %clang -### %s 2>&1 --target=arm-unknown-haiku \
// RUN: | FileCheck --check-prefix=CHECK-ARM-CPU %s
// CHECK-ARM-CPU: "-target-cpu" "arm1176jzf-s"
+
+// Check passing LTO flags to the linker
+// RUN: %clang --target=x86_64-unknown-haiku -flto -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
+// CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
diff --git a/clang/test/Driver/openbsd.c b/clang/test/Driver/openbsd.c
index 586c65f502a0d15..68d33c5dd01e227 100644
--- a/clang/test/Driver/openbsd.c
+++ b/clang/test/Driver/openbsd.c
@@ -131,3 +131,8 @@
// RUN: %clang --target=riscv64-unknown-openbsd -### %s 2>&1 \
// RUN: | FileCheck -check-prefix=CHECK-RISCV64-FLAGS %s
// CHECK-RISCV64-FLAGS: "-X"
+
+// Check passing LTO flags to the linker
+// RUN: %clang --target=amd64-unknown-openbsd -flto -### %s 2>&1 \
+// RUN: | FileCheck -check-prefix=CHECK-LTO-FLAGS %s
+// CHECK-LTO-FLAGS: "-plugin-opt=mcpu=x86-64"
diff --git a/clang/test/Driver/save-stats.c b/clang/test/Driver/save-stats.c
index 54f222f3d57abdf..ad7867a9916860b 100644
--- a/clang/test/Driver/save-stats.c
+++ b/clang/test/Driver/save-stats.c
@@ -24,15 +24,18 @@
// RUN: %clang --target=x86_64-unknown-linux -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=x86_64-unknown-freebsd -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-openbsd -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-openbsd -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=x86_64-unknown-fuchsia -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-haiku -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
+// RUN: %clang --target=x86_64-unknown-haiku -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=avr -save-stats -flto -o obj/dir/save-stats.exe %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// RUN: %clang --target=avr -save-stats -flto -o obj/dir/save-stats.exe -Wl,-plugin-opt=-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-LTO
// CHECK-LTO: "-stats-file=save-stats.stats"
// CHECK-LTO: "-o" "obj/dir{{/|\\\\}}save-stats.exe"
// CHECK-LTO: "-plugin-opt=stats-file=save-stats.stats"
-
// RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO
// RUN: %clang --target=powerpc-unknown-aix -save-stats -flto -o obj/dir/save-stats -Wl,-bplugin-opt:-dummy %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-AIX-LTO
|
MaskRay
approved these changes
Nov 13, 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.