在 http://ftp.gnu.org/gnu/gcc 下载需要的 gcc.tar.gz
源码文件,按照下面的步骤进行安装:
cd gcc-5.4.0 //进入解压后的gcc文件夹
./contrib/download_prerequisites //下载依赖项
cd ..
mkdir gcc-build-5.4.0
cd gcc-build-5.4.0
../gcc-5.4.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make
make install
报错1:
# If this is the top-level multilib, build all the other
# multilibs.
/data2/zyy/code/PAConv/gcc-build-5.4.0/./gcc/xgcc -B/data2/zyy/code/PAConv/gcc-build-5.4.0/./gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include -g -O2 -O2 -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wno-format -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -fpic -mlong-double-80 -I. -I. -I../.././gcc -I../../../gcc-5.4.0/libgcc -I../../../gcc-5.4.0/libgcc/. -I../../../gcc-5.4.0/libgcc/../gcc -I../../../gcc-5.4.0/libgcc/../include -I../../../gcc-5.4.0/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_TLS -o unwind-dw2.o -MT unwind-dw2.o -MD -MP -MF unwind-dw2.dep -fexceptions -c ../../../gcc-5.4.0/libgcc/unwind-dw2.c -fvisibility=hidden -DHIDE_EXPORTS
In file included from ../../../gcc-5.4.0/libgcc/unwind-dw2.c:401:0:
./md-unwind-support.h: 在函数‘x86_64_fallback_frame_state’中:
./md-unwind-support.h:65:47: 错误: dereferencing pointer to incomplete type ‘struct ucontext’
sc = (struct sigcontext *) (void *) &uc_->uc_mcontext;
^
../../../gcc-5.4.0/libgcc/shared-object.mk:14: recipe for target 'unwind-dw2.o' failed
make[3]: *** [unwind-dw2.o] Error 1
make[3]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libgcc”
Makefile:19233: recipe for target 'all-stage1-target-libgcc' failed
make[2]: *** [all-stage1-target-libgcc] Error 2
make[2]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0”
Makefile:23131: recipe for target 'stage1-bubble' failed
make[1]: *** [stage1-bubble] Error 2
make[1]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0”
Makefile:910: recipe for target 'all' failed
make: *** [all] Error 2
In file included from ../../../gcc-5.4.0/libgcc/unwind-dw2.c:401:0:
./md-unwind-support.h: 在函数‘x86_64_fallback_frame_state’中:
./md-unwind-support.h:65:47: 错误: dereferencing pointer to incomplete type ‘struct ucontext’
sc = (struct sigcontext *) (void *) &uc_->uc_mcontext;
解决方法: 修改文件 md-unwind-support.h
第61行
struct ucontext *uc_ = context->cfa;
修改为
struct ucontext_t *uc_ = context->cfa;
不知道文件位置可以用 find -name
进行查找:
>>> find -name md-unwind-support.h
./x86_64-unknown-linux-gnu/libgcc/md-unwind-support.h
报错2:
../../../../gcc-5.4.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc: 在函数‘int __sanitizer::TracerThread(void*)’中:
../../../../gcc-5.4.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc:237:22: 错误: 聚合‘sigaltstack handler_stack’类型不完全,无法被定义
struct sigaltstack handler_stack;
^
Makefile:449: recipe for target 'sanitizer_stoptheworld_linux_libcdep.lo' failed
make[4]: *** [sanitizer_stoptheworld_linux_libcdep.lo] Error 1
make[4]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libsanitizer/sanitizer_common”
Makefile:437: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libsanitizer”
Makefile:307: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libsanitizer”
Makefile:16925: recipe for target 'all-target-libsanitizer' failed
make[1]: *** [all-target-libsanitizer] Error 2
make[1]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0”
Makefile:910: recipe for target 'all' failed
make: *** [all] Error 2
解决方法:
修改文件 sanitizer_stoptheworld_linux_libcdep.cc
第 237 行。
文件位置:../gcc-5.4.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
struct sigaltstack handler_stack;
修改为
stack_t handler_stack;
修改文件 sanitizer_linux.h
第 31-32 行,删除第 21 行。
文件位置:../gcc-5.4.0/libsanitizer/sanitizer_common/sanitizer_linux.h
uptr internal_sigaltstack(const struct sigaltstack* ss,
struct sigaltstack* oss);
修改为
uptr internal_sigaltstack(const void* ss, void* oss);
修改文件 sanitizer_linux.cc
第 517-518 行。
文件位置:../gcc-5.4.0/libsanitizer/sanitizer_common/sanitizer_linux.cc
uptr internal_sigaltstack(const struct sigaltstack *ss,
struct sigaltstack *oss) {
修改为
uptr internal_sigaltstack(const void *ss, void *oss) {
修改文件 tsan_platform_linux.cc
第 380 行。
文件位置:../gcc-5.4.0/libsanitizer/tsan/tsan_platform_linux.cc
__res_state *statp = (__res_state*)state;
修改为
struct __res_state *statp = (struct __res_state*)state;
参考:https://reviews.llvm.org/D35246
报错3:
../../../../gcc-5.4.0/libsanitizer/asan/asan_linux.cc: 在函数‘bool __asan::AsanInterceptsSignal(int)’中:
../../../../gcc-5.4.0/libsanitizer/asan/asan_linux.cc:222:20: 错误: ‘SIGSEGV’在此作用域中尚未声明
return signum == SIGSEGV && common_flags()->handle_segv;
^
Makefile:461: recipe for target 'asan_linux.lo' failed
make[4]: *** [asan_linux.lo] Error 1
make[4]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libsanitizer/asan”
Makefile:437: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libsanitizer”
Makefile:307: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0/x86_64-unknown-linux-gnu/libsanitizer”
Makefile:16925: recipe for target 'all-target-libsanitizer' failed
make[1]: *** [all-target-libsanitizer] Error 2
make[1]: 离开目录“/data2/zyy/code/PAConv/gcc-build-5.4.0”
Makefile:910: recipe for target 'all' failed
make: *** [all] Error 2
解决方法: 在文件 asan_linux.cc
中添加头文件 #include
。文件位置:../gcc-5.4.0/libsanitizer/asan/asan_linux.cc
#include
#include
#include
#include
#include
#include
#include
#include
+ #include
#include
#include
#include