[cfe-dev] Disallow rtti

Martin J. O'Riordan via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 24 10:48:13 PDT 2017

Darn - email lost the 'cfe-dev'

-----Original Message-----
From: Martin J. O'Riordan [mailto:MartinO at theheart.ie] 
Sent: 24 October 2017 18:47
To: 'John McCall' <rjmccall at apple.com>; 'Andreas Bergmeier' <abergmeier at gmx.net>
Subject: RE: [cfe-dev] Disallow rtti

Hi Andreas,

I have not found the overhead of RTTI to be a significant burden (even for embedded with a 128KB memory size constraint), but even so I have defaulted to '-fno-rtti' just in case it is an issue for my users.  I handled this in 'AddMyTargetTargetArgs()' by looking for the last of the options '-frtti' or '-fno-rtti' (using 'getLastArg()'), and if neither was found, passing '-fno-rtti' by default to LLVM (overriding LLVM's normal defaults, but in a target specific way).

You could similarly intercept if the last argument passed was '-frtti' and emit a diagnostic to say that it is not supported, but always pass '-fno-rtti' onto LLVM.

For EH I was a lot more strict.  We do not (and cannot reasonably) support EH in the context of our embedded target, so I simply changed:


from LibC++ to include the following check (I predefine '__mytarget__'):

    #ifdef __mytarget__
    // MYTARGET does not support exception handling
    # if (__has_feature(cxx_exceptions))
    #  error Exception handling is not supported on MYTARGET
    # endif

This way, if the programmer uses EH they get a hard and meaningful compile time error that informs them what is going on.

You could do something similar for RTTI.

I chose to use '__config' because only the most trivial/contrived programs do not include at least one C++ header, and '__config' is included by them all ;-)

It is worth noting that LibC++ states that while it supports programs using LibC++ without RTTI, it does not support building LibC++ with RTTI disabled, so you would probably have to qualify your RTTI feature check with a test to see if '_LIBCPP_BUILDING_LIBRARY' is defined or not.

All the best,


-----Original Message-----
From: cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] On Behalf Of John McCall via cfe-dev
Sent: 24 October 2017 18:21
To: Andreas Bergmeier <abergmeier at gmx.net>
Cc: cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] Disallow rtti

> On Oct 24, 2017, at 9:28 AM, Andreas Bergmeier via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> I am currently starting implementing a new toolchain and want to disable rtti there.
> Now saw CalculateRTTIMode in lib/Driver/ToolChain.cpp. Now I would like to warn the user that rtti is actually no supported on that platform (for -frtti). Currently it seems like all rtti handling in Toolchain is hard coded.
> What is the best way to indicate missing rtti on a platform?

How is it "missing"?  You just want to have a policy that those language features don't work on your target?  We don't have any existing targets that do that, so it's not surprising that you might need to provide some customization hook for it.

cfe-dev mailing list
cfe-dev at lists.llvm.org

More information about the cfe-dev mailing list