From 6385c1df919f237d4149fabf542a158f61010bf8 Mon Sep 17 00:00:00 2001 From: Leonard Chan Date: Wed, 13 Sep 2023 23:11:50 +0000 Subject: [clang] Add experimental option to omit the RTTI component from the vtable when -fno-rtti is used For programs that don't use RTTI, the rtti component is just replaced with a zero. This way, vtables that don't use RTTI can still cooperate with vtables that use RTTI since offset calculations on the ABI level would still work. However, if throughout your whole program you don't use RTTI at all (such as the embedded case), then this is just an unused pointer-sized component that's wasting space. This adds an experimental option for removing the RTTI component from the vtable. Some notes: - This is only allowed when RTTI is disabled, so we don't have to worry about things like `typeid` or `dynamic_cast`. - This is a "use at your own risk" since, similar to relative vtables, everything must be compiled with this since it's an ABI breakage. That is, a program compiled with this is not guaranteed to work with a program compiled without this, even if RTTI is disabled for both programs. Note that this is a completely different ABI flavor orthogonal to the relative-vtables ABI. That is, they can be enabled/disabled independently. Differential Revision: https://reviews.llvm.org/D152405 --- clang/lib/Frontend/CompilerInvocation.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 730db8e..2dd299b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4109,6 +4109,14 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, options::OPT_fno_experimental_relative_cxx_abi_vtables, TargetCXXABI::usesRelativeVTables(T)); + // RTTI is on by default. + bool HasRTTI = Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti, true); + Opts.OmitVTableRTTI = + Args.hasFlag(options::OPT_fexperimental_omit_vtable_rtti, + options::OPT_fno_experimental_omit_vtable_rtti, false); + if (Opts.OmitVTableRTTI && HasRTTI) + Diags.Report(diag::err_drv_using_omit_rtti_component_without_no_rtti); + for (const auto &A : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ)) { auto Split = StringRef(A).split('='); Opts.MacroPrefixMap.insert( -- cgit v1.1