Red Hat Bugzilla – Bug 291341
gcc fails to find right header file, possibly resulting in silent miscompilation of code
Last modified: 2010-10-22 14:38:03 EDT
Description of problem:
On very rare occasions gcc will fail to open and read the right header file. In
the cases where we've seen it, gcc reports that the header couldn't be found -
but gcc could just as easily read the wrong header if a file with the same name
is found later in the search path, possibly resulting in silent miscompilation
The bug was introduced with this patch:
Here's the whole find_or_create_entry...
find_or_create_entry (pfile, fname)
const char *fname;
struct include_file *file;
char *name = xstrdup (fname);
node = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) name);
file = xcnew (struct include_file);
file->name = name;
file->err_no = errno;
node = splay_tree_insert (pfile->all_include_files,
Note that this code assumes that errno doesn't change between
"_cpp_simplify_pathname (name)" and "file->err_no = errno;".
Unfortunately this is not the case. On very rare occasions it is possible that
the calloc() call wrapped in "file = xcnew (struct include_file);" will set
errno even on successful calls. The strace output of the compiler suggests that
we're expanding the heap (brk/mmap2 system calls) during this calloc() call,
which is one of the conditions under which calloc() may set errno.
gcc later will avoid trying to open the header file based on the value of
I'll submit a patch that simply preserves the value of errno around the calloc()
Version-Release number of selected component (if applicable):
Very rarely, as it depends on the exact memory allocation pattern of the compile
Steps to Reproduce:
1.Only the customer is able to reproduce by compiling their large project.
Created attachment 196041 [details]
A patch to fix the problem.
This bug is filed against RHEL 3, which is in maintenance phase.
During the maintenance phase, only security errata and select mission
critical bug fixes will be released for enterprise products. Since
this bug does not meet that criteria, it is now being closed.
For more information of the RHEL errata support policy, please visit:
If you feel this bug is indeed mission critical, please contact your
support representative. You may be asked to provide detailed
information on how this bug is affecting you.
Marking as fixed in RHEL4+.