openeuler gcc7.3.0 降级 4.8.5-4008云顶国际网站
在迁移电信某系统,伙伴需要使用openeuler,伙伴工程较旧,使用操作系统自带gcc 7.3.0 编译工程报错,遂决定对gcc降级,以下为gcc降级操作记录
操作系统:openeuler 20.03 gcc 7.3.0
wget
tar xvf gcc-4.8.5.tar.gz
cd gcc-4.8.5
执行下面脚本下载依赖包
./contrib/download_prerequisites
如上述脚本执行失败手动下载安装包到根目录
wget https://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/mpfr-2.4.2.tar.bz2
mkdir build
cd build/
../configure --enable-checking=release --enable-language=c,c --disable-multilib --prefix=/usr/gcc4.8.5
make -j64
由于版本差别较大,正常降级是无法编译通过的
1、报错“const char* libc_name_p(const char*, unsigned int)’”
问题截图
解决方法: 其中红色的是旧代码,绿色的是修改后的代码
a、修改 gcc-4.8.5/gcc/cp/make-lang.in
--- a/gcc/cp/make-lang.in
b/gcc/cp/make-lang.in
# deleting the $(srcdir)/cp/cfns.h file.
$(srcdir)/cp/cfns.h:
endif
- gperf -o -c -e -k '1-6,$$' -j1 -d -n 'libc_name_p' -l ansi-c \
gperf -o -c -e -k '1-6,$$' -j1 -d -n 'libc_name_p' -l c \
$(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h
#\f
如下图:
b、修改gcc-4.8.5/gcc/cp/cfns.gperf
--- a/gcc/cp/cfns.gperf
b/gcc/cp/cfns.gperf
%language=c
�fine class-name libc_name
%{
/* 4008云顶国际网站 copyright (c) 2000-2016 free software foundation, inc.
@@ -16,14 18,6 @@ for more details.
you should have received a copy of the gnu general public license
along with gcc; see the file copying3. if not see
. */
-#ifdef __gnuc__
-__inline
-#endif
-static unsigned int hash (const char *, unsigned int);
-#ifdef __gnuc__
-__inline
-#endif
-const char * libc_name_p (const char *, unsigned int);
%}
%%
# the standard c library functions, for feeding to gperf; the result is used
如下图:
c、修改gcc-4.8.5/gcc/cp/cfns.h
--- a/gcc/cp/cfns.h
b/gcc/cp/cfns.h
-/* ansi-c code produced by gperf version 3.0.3 */
-/* command-line: gperf -o -c -e -k '1-6,$' -j1 -d -n libc_name_p -l ansi-c cfns.gperf */
/* c code produced by gperf version 3.0.4 */
/* command-line: gperf -o -c -e -k '1-6,$' -j1 -d -n libc_name_p -l c --output-file cfns.h cfns.gperf */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -28,7 28,7 @@
#error "gperf generated tables don't work with this execution character set. please report a bug to
#endif
-#line 1 "cfns.gperf"
#line 3 "cfns.gperf"
/* 4008云顶国际网站 copyright (c) 2000-2016 free software foundation, inc.
@@ -47,25 47,18 @@ for more details.
you should have received a copy of the gnu general public license
along with gcc; see the file copying3. if not see
-#ifdef __gnuc__
-__inline
-#endif
-static unsigned int hash (const char *, unsigned int);
-#ifdef __gnuc__
-__inline
-#endif
-const char * libc_name_p (const char *, unsigned int);
/* maximum key range = 391, duplicates = 0 */
-#ifdef __gnuc__
-__inline
-#else
-#ifdef __cplusplus
-inline
-#endif
-#endif
-static unsigned int
-hash (register const char *str, register unsigned int len)
class libc_name
{
private:
static inline unsigned int hash (const char *str, unsigned int len);
public:
static const char *libc_name_p (const char *str, unsigned int len);
};
inline unsigned int
libc_name::hash (register const char *str, register unsigned int len)
{
static const unsigned short asso_values[] =
{
return hval asso_values[(unsigned char)str[len - 1]];
}
-#ifdef __gnuc__
-__inline
-#ifdef __gnuc_stdc_inline__
-__attribute__ ((__gnu_inline__))
-#endif
-#endif
const char *
-libc_name_p (register const char *str, register unsigned int len)
libc_name::libc_name_p (register const char *str, register unsigned int len)
{
enum
{
如下图:
d、修改gcc-4.8.5/gcc/cp/except.c
--- a/gcc/cp/except.c
b/gcc/cp/except.c
unless the system headers are playing rename tricks, and if
they are, we don't want to be confused by them. */
id = decl_name (fn);
- return !!libc_name_p (identifier_pointer (id), identifier_length (id));
return !!libc_name::libc_name_p (identifier_pointer (id),
identifier_length (id));
重新编译查看结果
make -j64
1、报错“error: field ‘uc’ has incomplete type”
问题截图
解决方法:
查找文件 md-unwind-support.h,修改 struct ucontext uc; 为 ucontext_t uc;
重新编译 make -j64,编译成功
make install
还是报错: ../../gcc/gcc.c:5785 0x40d03f do_spec_1 ../../gcc/gcc.c:5269 0x40ea1b process_brace_body ../../gcc/gcc.c:5872 0x40e79b handle_braces ../../gcc/gcc.c:5785 please submit a full bug report, with preprocessed source if appropriate. please include the complete backtrace with any bug report. see for instructions. make[3]: *** [makefile:1059:insn-recog.o] 错误 4 make[3]: *** 正在等待未完成的任务.... make[3]: 离开目录“/root/wangxq/download/gcc-4.8.5/build/gcc” make[2]: *** [makefile:4200:all-stage2-gcc] 错误 2 make[2]: 离开目录“/root/wangxq/download/gcc-4.8.5/build” make[1]: *** [makefile:20845:stage2-bubble] 错误 2 make[1]: 离开目录“/root/wangxq/download/gcc-4.8.5/build” make: *** [makefile:889:all] 错误 2