Skip to content

Commit a7b75d8

Browse files
authored
Multilib support for libraries with exceptions for BMT llvm-18 (#433)
Co-authored-by: Vrukesh V Panse <[email protected]>
1 parent 8772662 commit a7b75d8

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ set(
266266
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0005-libc-tests-with-picolibc-XFAIL-uses-of-atomics.patch
267267
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0006-libc-tests-with-picolibc-mark-two-more-large-tests.patch
268268
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0007-llvm-objcopy-Support-SREC-output-format-75874.patch
269+
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0008-multilib-support-for-libraries-with-exceptions.patch
269270
)
270271
FetchContent_Declare(llvmproject
271272
GIT_REPOSITORY https://github.com/llvm/llvm-project.git
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
From 78acc1685def3efa6e5af212f4edee7842de28a6 Mon Sep 17 00:00:00 2001
2+
From: Piotr Przybyla <[email protected]>
3+
Date: Wed, 29 Nov 2023 14:05:00 +0000
4+
Subject: [PATCH] Multilib support for libraries with exceptions and rtti
5+
6+
---
7+
clang/include/clang/Driver/ToolChain.h | 10 ++++++++++
8+
clang/lib/Driver/ToolChain.cpp | 23 ++++++++++++++++++++++-
9+
2 files changed, 32 insertions(+), 1 deletion(-)
10+
11+
diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h
12+
index 2d0c1f826c1728..fbe2e8fe8e88d8 100644
13+
--- a/clang/include/clang/Driver/ToolChain.h
14+
+++ b/clang/include/clang/Driver/ToolChain.h
15+
@@ -120,6 +120,11 @@ class ToolChain {
16+
RM_Disabled,
17+
};
18+
19+
+ enum ExceptionsMode {
20+
+ EM_Enabled,
21+
+ EM_Disabled,
22+
+ };
23+
+
24+
struct BitCodeLibraryInfo {
25+
std::string Path;
26+
bool ShouldInternalize;
27+
@@ -141,6 +146,8 @@ class ToolChain {
28+
29+
const RTTIMode CachedRTTIMode;
30+
31+
+ const ExceptionsMode CachedExceptionsMode;
32+
+
33+
/// The list of toolchain specific path prefixes to search for libraries.
34+
path_list LibraryPaths;
35+
36+
@@ -318,6 +325,9 @@ class ToolChain {
37+
// Returns the RTTIMode for the toolchain with the current arguments.
38+
RTTIMode getRTTIMode() const { return CachedRTTIMode; }
39+
40+
+ // Returns the ExceptionsMode for the toolchain with the current arguments.
41+
+ ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; }
42+
+
43+
/// Return any implicit target and/or mode flag for an invocation of
44+
/// the compiler driver as `ProgName`.
45+
///
46+
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
47+
index 388030592b4836..f8c13c86daf9b0 100644
48+
--- a/clang/lib/Driver/ToolChain.cpp
49+
+++ b/clang/lib/Driver/ToolChain.cpp
50+
@@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args,
51+
return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled;
52+
}
53+
54+
+static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) {
55+
+ if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
56+
+ true)) {
57+
+ return ToolChain::EM_Enabled;
58+
+ }
59+
+ return ToolChain::EM_Disabled;
60+
+}
61+
+
62+
ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
63+
const ArgList &Args)
64+
: D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
65+
- CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
66+
+ CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)),
67+
+ CachedExceptionsMode(CalculateExceptionsMode(Args)) {
68+
auto addIfExists = [this](path_list &List, const std::string &Path) {
69+
if (getVFS().exists(Path))
70+
List.push_back(Path);
71+
@@ -264,6 +273,18 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
72+
break;
73+
}
74+
75+
+ // Include fno-exceptions and fno-rtti
76+
+ // to improve multilib selection
77+
+ if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled)
78+
+ Result.push_back("-fno-rtti");
79+
+ else
80+
+ Result.push_back("-frtti");
81+
+
82+
+ if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled)
83+
+ Result.push_back("-fno-exceptions");
84+
+ else
85+
+ Result.push_back("-fexceptions");
86+
+
87+
// Sort and remove duplicates.
88+
std::sort(Result.begin(), Result.end());
89+
Result.erase(std::unique(Result.begin(), Result.end()), Result.end());

0 commit comments

Comments
 (0)