[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla created https://github.com/llvm/llvm-project/pull/75031 For better multilib matching explicitly match -fno-rtti and -fno-exceptions >From 79ad1933ae0c3589ef05c95f73aea9889fefc94e Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions --- clang/include/clang/Driver/ToolChain.h| 10 ++ clang/lib/Driver/ToolChain.cpp| 13 - clang/lib/Driver/ToolChains/BareMetal.cpp | 6 ++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c1728..fbe2e8fe8e88d8 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ab19166f18c2dc..6ab651861196b7 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,21 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + + Arg *exceptionsArg = Args.getLastArg(options::OPT_fno_exceptions); + if (exceptionsArg && + exceptionsArg->getOption().matches(options::OPT_fno_exceptions)) { +return ToolChain::EM_Disabled; + } + return ToolChain::EM_Enabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 42c8336e626c7b..c62b1edbf6bcb8 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -179,6 +179,12 @@ static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D, if (!MB) return; Multilib::flags_list Flags = TC.getMultilibFlags(Args); + if (TC.getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Flags.push_back("-fno-rtti"); + } + if (TC.getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) { +Flags.push_back("-fno-exceptions"); + } llvm::ErrorOr ErrorOrMultilibSet = MultilibSet::parseYaml(*MB.get()); if (ErrorOrMultilibSet.getError()) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: None (pwprzybyla) Changes For better multilib matching explicitly match -fno-rtti and -fno-exceptions --- Full diff: https://github.com/llvm/llvm-project/pull/75031.diff 3 Files Affected: - (modified) clang/include/clang/Driver/ToolChain.h (+10) - (modified) clang/lib/Driver/ToolChain.cpp (+12-1) - (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+6) ``diff diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c172..fbe2e8fe8e88d 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ab19166f18c2d..6ab651861196b 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,21 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + + Arg *exceptionsArg = Args.getLastArg(options::OPT_fno_exceptions); + if (exceptionsArg && + exceptionsArg->getOption().matches(options::OPT_fno_exceptions)) { +return ToolChain::EM_Disabled; + } + return ToolChain::EM_Enabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index 42c8336e626c7..c62b1edbf6bcb 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -179,6 +179,12 @@ static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D, if (!MB) return; Multilib::flags_list Flags = TC.getMultilibFlags(Args); + if (TC.getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Flags.push_back("-fno-rtti"); + } + if (TC.getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) { +Flags.push_back("-fno-exceptions"); + } llvm::ErrorOr ErrorOrMultilibSet = MultilibSet::parseYaml(*MB.get()); if (ErrorOrMultilibSet.getError()) `` https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -179,6 +179,12 @@ static void findMultilibsFromYAML(const ToolChain &TC, const Driver &D, if (!MB) return; Multilib::flags_list Flags = TC.getMultilibFlags(Args); + if (TC.getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Flags.push_back("-fno-rtti"); + } + if (TC.getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) { +Flags.push_back("-fno-exceptions"); + } mplatings wrote: This belongs in `getMultilibFlags()` https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla updated https://github.com/llvm/llvm-project/pull/75031 >From 536e2f694f662d688cdbb8a0c5487a5a0d8d3aaf Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions --- clang/include/clang/Driver/ToolChain.h | 10 ++ clang/lib/Driver/ToolChain.cpp | 22 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c1728..fbe2e8fe8e88d8 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ab19166f18c2dc..e4afaa20130856 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,21 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + + Arg *exceptionsArg = Args.getLastArg(options::OPT_fno_exceptions); + if (exceptionsArg && + exceptionsArg->getOption().matches(options::OPT_fno_exceptions)) { +return ToolChain::EM_Disabled; + } + return ToolChain::EM_Enabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); @@ -264,6 +275,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Result.push_back("-fno-rtti"); + } + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) { +Result.push_back("-fno-exceptions"); + } + // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/mplatings edited https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/mplatings commented: I'd be disinclined to add `CachedExceptionsMode`: * It's more code to maintain. * Most toolchains will never use it so for them it's a small extra runtime cost with no benefit. I think you could calculate the exceptions mode in `getMultilibFlags` when needed. I'm not actively working on LLVM any more so I'm going to remove myself as reviewer now. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -77,10 +77,21 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + + Arg *exceptionsArg = Args.getLastArg(options::OPT_fno_exceptions); + if (exceptionsArg && + exceptionsArg->getOption().matches(options::OPT_fno_exceptions)) { +return ToolChain::EM_Disabled; + } + return ToolChain::EM_Enabled; mplatings wrote: This is incorrect. There are plenty of examples across the clang code of how to check whether exceptions should be enabled or not. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
mplatings wrote: > I'm not actively working on LLVM any more so I'm going to remove myself as > reviewer now. Or at least I would if GitHub would let me! https://github.com/orgs/community/discussions/23054 https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/domin144 approved this pull request. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/amilendra approved this pull request. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla updated https://github.com/llvm/llvm-project/pull/75031 >From ea4d54f574bbceafcd45a108a8688b0a5cfeb0a4 Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions and rtti --- clang/include/clang/Driver/ToolChain.h | 10 ++ clang/lib/Driver/ToolChain.cpp | 23 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c1728..fbe2e8fe8e88d8 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 657577cea6c7d8..15f8294a8785dd 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, + true)) { +return ToolChain::EM_Enabled; + } + return ToolChain::EM_Disabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); @@ -264,6 +273,18 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) +Result.push_back("-fno-rtti"); + else +Result.push_back("-frtti"); + + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) +Result.push_back("-fno-exceptions"); + else +Result.push_back("-fexceptions"); + // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla updated https://github.com/llvm/llvm-project/pull/75031 >From 78acc1685def3efa6e5af212f4edee7842de28a6 Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions and rtti --- clang/include/clang/Driver/ToolChain.h | 10 ++ clang/lib/Driver/ToolChain.cpp | 23 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c1728..fbe2e8fe8e88d8 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index 388030592b4836..f8c13c86daf9b0 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, + true)) { +return ToolChain::EM_Enabled; + } + return ToolChain::EM_Disabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); @@ -264,6 +273,18 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) +Result.push_back("-fno-rtti"); + else +Result.push_back("-frtti"); + + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) +Result.push_back("-fno-exceptions"); + else +Result.push_back("-fexceptions"); + // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/amilendra closed https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
amilendra wrote: Merged because Piotr does not have merge permissions. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { amilendra wrote: You probably do not need braces for these two if conditions. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Result.push_back("-fno-rtti"); amilendra wrote: Aren't RTTI and Exceptions separate functionality? If so why is `fno-rtti` checked in a patch that is related to exceptions? https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Result.push_back("-fno-rtti"); voltur01 wrote: RTTI is required for exceptions support, e.g. a relevant discussion https://stackoverflow.com/questions/10320072/is-there-a-relation-between-rtti-and-exceptions Equally, we can update the title of the PR to reflect both options. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla updated https://github.com/llvm/llvm-project/pull/75031 >From d01eff925a3daeb5d0bde9bd733152b18a55793e Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions and rtti --- clang/include/clang/Driver/ToolChain.h | 10 ++ clang/lib/Driver/ToolChain.cpp | 19 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c172..fbe2e8fe8e88d 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ab19166f18c2d..f8006887f4b93 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, + true)) { +return ToolChain::EM_Enabled; + } + return ToolChain::EM_Disabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); @@ -264,6 +273,14 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) +Result.push_back("-fno-rtti"); + + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) +Result.push_back("-fno-exceptions"); + // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { pwprzybyla wrote: Thank you for pointing this out. Clang format did not argue about it. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Result.push_back("-fno-rtti"); amilendra wrote: Thanks for the explanation. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/amilendra approved this pull request. LGTM from me. https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/amilendra edited https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,14 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) +Result.push_back("-fno-rtti"); + + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) +Result.push_back("-fno-exceptions"); domin144 wrote: And a positive one here, too? https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
@@ -264,6 +273,14 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) +Result.push_back("-fno-rtti"); domin144 wrote: Could we have a positive flag, too? I know it is not useful for now, as we are not able to say, that some feature of a standard library is available - only that it is allowed. However, if in the future such mechanism was added, than I think it would be more natural to say: "If user specifies '-frtti', then the library candidate also needs '-frtti'" than to say: "If user specifies '-fno-rtti', than the library is allowed to have '-fno-rtti'". https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/domin144 edited https://github.com/llvm/llvm-project/pull/75031 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla updated https://github.com/llvm/llvm-project/pull/75031 >From 6057334fd63f97ff8882a39db8aa2d4fb9686506 Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions and rtti --- clang/include/clang/Driver/ToolChain.h | 10 ++ clang/lib/Driver/ToolChain.cpp | 23 ++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c1728..fbe2e8fe8e88d8 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ab19166f18c2dc..351f2f813a989a 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, + true)) { +return ToolChain::EM_Enabled; + } + return ToolChain::EM_Disabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); @@ -264,6 +273,18 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) +Result.push_back("-fno-rtti"); + else +Result.push_back("-frtti"); + + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) +Result.push_back("-fno-exceptions"); + else +Result.push_back("-fexceptions"); + // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Multilib support for libraries with exceptions (PR #75031)
https://github.com/pwprzybyla updated https://github.com/llvm/llvm-project/pull/75031 >From 45db788f730d37cc12b54104dd91175553c367b2 Mon Sep 17 00:00:00 2001 From: Piotr Przybyla Date: Wed, 29 Nov 2023 14:05:00 + Subject: [PATCH] Multilib support for libraries with exceptions --- clang/include/clang/Driver/ToolChain.h | 10 ++ clang/lib/Driver/ToolChain.cpp | 20 +++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 2d0c1f826c1728a..fbe2e8fe8e88d85 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -120,6 +120,11 @@ class ToolChain { RM_Disabled, }; + enum ExceptionsMode { +EM_Enabled, +EM_Disabled, + }; + struct BitCodeLibraryInfo { std::string Path; bool ShouldInternalize; @@ -141,6 +146,8 @@ class ToolChain { const RTTIMode CachedRTTIMode; + const ExceptionsMode CachedExceptionsMode; + /// The list of toolchain specific path prefixes to search for libraries. path_list LibraryPaths; @@ -318,6 +325,9 @@ class ToolChain { // Returns the RTTIMode for the toolchain with the current arguments. RTTIMode getRTTIMode() const { return CachedRTTIMode; } + // Returns the ExceptionsMode for the toolchain with the current arguments. + ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; } + /// Return any implicit target and/or mode flag for an invocation of /// the compiler driver as `ProgName`. /// diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index ab19166f18c2dcf..f80a9e78a16b065 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -77,10 +77,19 @@ static ToolChain::RTTIMode CalculateRTTIMode(const ArgList &Args, return NoRTTI ? ToolChain::RM_Disabled : ToolChain::RM_Enabled; } +static ToolChain::ExceptionsMode CalculateExceptionsMode(const ArgList &Args) { + if (Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions, + true)) { +return ToolChain::EM_Enabled; + } + return ToolChain::EM_Disabled; +} + ToolChain::ToolChain(const Driver &D, const llvm::Triple &T, const ArgList &Args) : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)), - CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) { + CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)), + CachedExceptionsMode(CalculateExceptionsMode(Args)) { auto addIfExists = [this](path_list &List, const std::string &Path) { if (getVFS().exists(Path)) List.push_back(Path); @@ -264,6 +273,15 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const { break; } + // Include fno-exceptions and fno-rtti + // to improve multilib selection + if (getRTTIMode() == ToolChain::RTTIMode::RM_Disabled) { +Result.push_back("-fno-rtti"); + } + if (getExceptionsMode() == ToolChain::ExceptionsMode::EM_Disabled) { +Result.push_back("-fno-exceptions"); + } + // Sort and remove duplicates. std::sort(Result.begin(), Result.end()); Result.erase(std::unique(Result.begin(), Result.end()), Result.end()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits