Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 266911 - g++ 4.3.3 may generate buggy code with -D_FORTIFY_SOURCE=X when X>0
Summary: g++ 4.3.3 may generate buggy code with -D_FORTIFY_SOURCE=X when X>0
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: AMD64 Linux
: High minor (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-20 22:37 UTC by Gert Wollny
Modified: 2009-04-22 14:41 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gert Wollny 2009-04-20 22:37:04 UTC
When using very heavily templated code and _FORTIFY_SOURCE, gcc-4.3.3 may generate buggy code: 

Specifically from "/usr/include/bits/string3.h"

 __extern_always_inline void *
__NTH (memset (void *__dest, int __ch, size_t __len))
{
  if (__builtin_constant_p (__len) && __len == 0)
    {
      __warn_memset_zero_len ();
      return __dest;
    }
  return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
}

the last line is compiled to: 

Dump of assembler code for function memset:
    0x0000000000439860 <memset+0>:  jmp    0x439860 <memset>
End of assembler dump.


Reproducible: Always

Steps to Reproduce:
Unfortunately, I don't have a small one-file test case because the buggy code is called during the initialization phase of the program, calling global constructors.
All I know so far is, that using boost::mpl::vector and BOOST_AUTO_TEST_CASE_TEMPLATE triggers the bug somehow, but not always, i.e. my first try to create a test case resulted in good code, but it may also be that it just didn't call memset during initialization.



Actual Results:  
Endless loop in memset

Expected Results:  
code that does what it should. 

The problem is not Gentoo nor x86_64 specific, I also hit it when I compile the code on Ubuntu with the same compiler version and on x86 too. It can be avoided by compiling with -D_FORTIFY_SOURCE=0  

I have tried to isolate a test case but so far to no avail. 
The project that triggers the bug is available at 
https://mia.svn.sourceforge.net/svnroot/mia/mia2/
but if someone has a lot of time and really want to dig into it then we should probably communicate privately.
Comment 1 Harald van Dijk (RETIRED) gentoo-dev 2009-04-22 04:30:41 UTC
This looks like a non-bug. mia/core/defines.hh defines __attribute__ to be ignored if __GCC__ is not defined. (GCC does not define __GCC__ itself.) When __attribute__ is redefined, standard headers don't work as expected; the inline definition of memset is just one thing that breaks.
Comment 2 Gert Wollny 2009-04-22 14:29:06 UTC
Indeed, checking for  __GNUC__ instead of __GCC__ made the problem go away. Thanks for digging through the code.
In addition, I tested g++-4.4 and there the issue didn't show up at all.