On 03/24/2016 05:32 AM, Martin Richtarsky wrote:
Hi all, we are using the -fstack-protector compiler option with gcc 5.x to detect stack smashing. While analyzing a performance regression resulting from this I found the instrumentation is also done for our STL string implementation which has an interned buffer for short strings. So basically a function having an object of that string class on the stack would incur some performance overhead due to checking, although it can be argued that the string class is pretty safe. Is there a way of excluding either a class or a class member from triggering the instrumentation? I have noticed that switching to wchar_t (e.g. unsigned short on x86) already removes the checking, which means that STL wstring is not checked. However, there is no 1 byte type I could use for string which avoids the checking. Any ideas?
Florian's response made this thread bubble up in my Inbox. Although I haven't tested it on an example like you describe, its possible that #pragma GCC optimize ("-fno-stack-protector") or the equivalent attribute might do what you're looking for (it can be used with functions, not whole classes). One caveat to keep in mind is that there have been problems with the #pragma (the FAQ on the Wiki has some details: https://gcc.gnu.org/wiki/FAQ#optimize_attribute_broken). Martin