zhouwg / minigcc

customized toolchain for x86-ia32,learning and studying how Linaro create their various toolchain from scratch source code
GNU General Public License v2.0
0 stars 0 forks source link

cc1 segment fault during compile c source code #3

Closed zhouwg closed 4 years ago

zhouwg commented 4 years ago

Host OS:

wgzhou:$ cat /etc/issue Ubuntu 18.04.2 LTS \n \l


Target:

x86-32


Kernel:

wgzhou:$ uname -r 5.4.1


GCC:

wgzhou:$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.4.0-1ubuntu1~18.04.1' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)


Desc:

wgzhou:$ pwd /wgzhou/develop/cdeos/toolchain/minigcc/gcc wgzhou:$ cat hello.c

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("Hello, world\n");

    return 0;
}

wgzhou:$ ./xgcc -o hello hello.c [gcc-main.c,main,44]: enter main [gcc-main.c,main,45]: initialize driver [gcc.c,driver,7223]: enter driver [gcc.c,driver,7225]: leave driver [gcc-main.c,main,49]: calling driver.main() [gcc.c,main,7251]: enter main

env_manager::getenv (GCC_EXEC_PREFIX) -> (null) env_manager::xput (GCC_EXEC_PREFIX=/wgzhou/develop/cdeos/toolchain/minigcc/gcc/../lib/gcc/) env_manager::getenv (COMPILER_PATH) -> (null) env_manager::getenv (LIBRARY_PATH) -> (null) env_manager::getenv (LPATH) -> (null) env_manager::getenv (GCC_COMPARE_DEBUG) -> (null) env_manager::xput (COLLECT_GCC=./xgcc)

[gcc.c,do_spec_on_infiles,8145]: calling do_spec [gcc.c,do_spec_1,5154]: argbuf.length() 17 env_manager::xput (COLLECT_GCC_OPTIONS='-o' 'hello' '-mtune=generic' '-march=x86-64') [gcc.c,do_spec_1,5174]: calling execute [gcc.c,execute,2923]: enter execute

[pex-common.c,pex_run_in_environment,344]: [miniGCC]current exe is :cc1

[pex-unix.c,pex_unix_exec_child,616]: set path ok

cc1 -quiet -imultiarch x86_64-linux-gnu -iprefix /wgzhou/develop/cdeos/toolchain/minigcc/gcc/../lib/gcc/x86_64-pc-linux-gnu/6.4.0/ hello.c -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -o /tmp/ccTXSzH0.s [pex-unix.c,pex_unix_exec_child,626]:

: internal compiler error: Segmentation fault executable file is unexpected ELF class Please submit a full bug report, with preprocessed source if appropriate. See http://gcc.gnu.org/bugs.html for instructions. [gcc.c,execute,3238]: return -1 [gcc.c,execute,3239]: leave execute [gcc.c,do_spec_1,5176]: after calling execute, value -1 [gcc.c,do_spec_1,5179]: return value -1 [gcc.c,do_spec_1,5180]: leave do_spec_1 [gcc.c,do_spec,4823]: value -1 [gcc.c,do_spec_on_infiles,8147]: after calling do_spec [gcc.c,do_spec_on_infiles,8151]: set this_file_error = 1 [gcc.c,do_spec_on_infiles,8213]: errorcount 1 [gcc.c,main,7273]: leave main [gcc-main.c,main,51]: after calling driver.main() [gcc-main.c,main,53]: leave main, return 1 [gcc.c,~driver,7230]: enter ~driver [gcc.c,~driver,7241]: leave ~driver

zhouwg commented 4 years ago

how to reproduce the issue:

the following branch used to reproduce the issue.

https://github.com/zhouwg/minigcc/tree/reproduce_cc1_segment_fault

zhouwg commented 4 years ago

2019-12-20, 01:28 this issue fixed in development branch after 5-6 hours but more efforts was required

wgzhou:$ pwd /cdeos/develop/cdeos/toolchain/minigcc/gcc wgzhou:$ cat hello.c

include

int main(int argc, char *argv[])
{
    printf("hello,world\n");

    return 0;
}

wgzhou:$ ./xgcc -o hello hello.c [gcc-main.c,main,44]: enter main [gcc-main.c,main,45]: initialize driver [gcc.c,driver,7223]: enter driver [gcc.c,driver,7225]: leave driver [gcc-main.c,main,49]: calling driver.main() [gcc.c,main,7251]: enter main

env_manager::getenv (GCC_EXEC_PREFIX) -> (null) env_manager::xput (GCC_EXEC_PREFIX=/cdeos/develop/cdeos/toolchain/minigcc/gcc/../lib/gcc/) env_manager::getenv (COMPILER_PATH) -> (null) env_manager::getenv (LIBRARY_PATH) -> (null) env_manager::getenv (LPATH) -> (null) env_manager::getenv (GCC_COMPARE_DEBUG) -> (null) env_manager::xput (COLLECT_GCC=./xgcc)

[gcc.c,do_spec_on_infiles,8145]: calling do_spec [gcc.c,do_spec_1,5154]: argbuf.length() 15 env_manager::xput (COLLECT_GCC_OPTIONS='-o' 'hello' '-mtune=generic' '-march=pentiumpro') [gcc.c,do_spec_1,5174]: calling execute [gcc.c,execute,2923]: enter execute

cc1 -quiet -iprefix /cdeos/develop/cdeos/toolchain/minigcc/gcc/../lib/gcc/i686-pc-linux-gnu/6.4.0/ hello.c -quiet -dumpbase hello.c -mtune=generic -march=pentiumpro -auxbase hello -o /tmp/ccxAkW86.s In file included from hello.c:2:0: /usr/include/stdio.h:33:20: fatal error: stddef.h: No such file or directory

include

                ^

compilation terminated. [gcc.c,execute,3238]: return -1 [gcc.c,execute,3239]: leave execute [gcc.c,do_spec_1,5176]: after calling execute, value -1 [gcc.c,do_spec_1,5179]: return value -1 [gcc.c,do_spec_1,5180]: leave do_spec_1 [gcc.c,do_spec,4823]: value -1 [gcc.c,do_spec_on_infiles,8147]: after calling do_spec [gcc.c,do_spec_on_infiles,8151]: set this_file_error = 1 [gcc.c,do_spec_on_infiles,8213]: errorcount 1 [gcc.c,main,7273]: leave main [gcc-main.c,main,51]: after calling driver.main() [gcc-main.c,main,53]: leave main, return 1 [gcc.c,~driver,7230]: enter ~driver [gcc.c,~driver,7241]: leave ~driver