[Bug c/66909] New: Internal Compiler Error when #including files from /sys on Linux

2015-07-17 Thread nate at natecraun dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66909

Bug ID: 66909
   Summary: Internal Compiler Error when #including files from
/sys on Linux
   Product: gcc
   Version: 5.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: nate at natecraun dot net
  Target Milestone: ---

Hello,

I have encountered a bug where #including files from /sys causes gcc to have an
internal compiler error:

In file included from bug.c:1:0:

bug.c:1:0: internal compiler error: Aborted
 #include "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.


Ths seems to cause an abort on gcc 5.1.1 and a segfault on gcc 4.8. Clang
manages to #include the file, but produces about 4000 some warnings about null
characters, so this might be a hint about what's going wrong.

Now of course I don't think there is any practical reason to #include files
from /sys. But it still shouldn't cause a compiler crash.

The bug can be reproduced with a source file #including any file from /sys

For example:

bug.c:

#include "/sys/devices/system/cpu/cpu0/cache/index0/coherency_line_size"


Here is the .i file.

bug.i:

# 1 "bug.c"
# 1 ""
# 1 ""
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "" 2
# 1 "bug.c"

Here is gcc -v:

Using built-in specs.
COLLECT_GCC=/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.1.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-linker-hash-style=gnu --enable-plugin --enable-initfini-array
--disable-libgcj --with-default-libstdcxx-abi=c++98 --with-isl --enable-libmpx
--enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686
--build=x86_64-redhat-linux
Thread model: posix
gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC) 


My uname -a:

Linux localhost.localdomain 4.0.6-300.fc22.x86_64 #1 SMP Tue Jun 23 13:58:53
UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


[Bug preprocessor/66909] Internal Compiler Error when #including files from /sys on Linux

2015-07-17 Thread nate at natecraun dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66909

--- Comment #2 from Nate Craun  ---
It seems that clang has a similar issue. I added an entry on their bug tracker
here: https://llvm.org/bugs/show_bug.cgi?id=24168

As mentioned in clang's bug tracker:

I think the problem is related to the use of stat. For example, the manpage for
stat() mentions:

"For  most files under the /proc directory, stat() does not return the file
size in the st_size field; instead the field is returned with the value 0."

To test this out I wrote another test that tries to #include a file from /proc.

#include "/proc/meminfo"

However this did not #include the text from the /proc/meminfo at all. Running
the preprocessor on this produced an empty file. This is presumably because
stat() is saying /proc/meminfo has zero bytes.

I don't know if this #including files from proc bug should have its own issue
or not, as it seems to be related to the same underlying issue of stat()
behaving differently on procfs, sysfs, and maybe others.

Like I said before though, I don't have any practical use for #including files
from /proc or /sys. But the preprocessor should still be able to do this
textual inclusion correctly.

I haven't tried this out yet, but now I'm wondering if #include will have
issues on other special files on Linux: pipes, sockets, dev files, etc.