[PATCH] D152405: [WIP][clang] Add experimental option to omit the RTTI component from the vtable when -fno-rtti is used

Leonard Chan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 7 15:48:47 PDT 2023


leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
leonardchan added a project: clang.
Herald added a project: All.
leonardchan requested review of this revision.
Herald added a subscriber: MaskRay.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152405

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/VTableBuilder.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/OmitRTTIComponentABI/simple-vtable-definition.cpp
  clang/test/CodeGenCXX/OmitRTTIComponentABI/vbase-offset.cpp
  clang/test/CodeGenCXX/OmitRTTIComponentABI/vtable-layout.cpp
  clang/test/Driver/omit-rtti-component-flag.cpp
  clang/test/Driver/omit-rtti-component-without-no-rtti.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152405.529457.patch
Type: text/x-patch
Size: 12665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230607/6b0aef09/attachment-0001.bin>


More information about the cfe-commits mailing list