MT7628学习笔记(29)——ubuntu18.04 OpenWrt编译出错问题解决

编译环境:ubuntu18.04
芯片:MT7628
系统:openwrt
使用 ubuntu16.04 编译不会出错,使用 ubuntu18.04 就出现以下问题:

问题一:

error: format not a string literal, format string not checked [-Werror=format-nonliteral]

gdate.c: In function 'g_date_strftime':
gdate.c:2497:7: error: format not a string literal, format string not checked [-Werror=format-nonliteral]
       tmplen = strftime (tmpbuf, tmpbufsize, locale_format, &tm);
       ^~~~~~
cc1: some warnings being treated as errors
Makefile:1386: recipe for target 'libglib_2_0_la-gdate.lo' failed
make[10]: *** [libglib_2_0_la-gdate.lo] Error 1
make[10]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/glib/glib'
Makefile:1933: recipe for target 'all-recursive' failed
make[9]: *** [all-recursive] Error 1
make[9]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/glib/glib'
Makefile:952: recipe for target 'all' failed
make[8]: *** [all] Error 2
make[8]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/glib/glib'
Makefile:1045: recipe for target 'all-recursive' failed
make[7]: *** [all-recursive] Error 1
make[7]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/glib'
Makefile:769: recipe for target 'all' failed
make[6]: *** [all] Error 2
make[6]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/glib'
Makefile:697: recipe for target 'all-recursive' failed
make[5]: *** [all-recursive] Error 1
make[5]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29'
Makefile:456: recipe for target 'all' failed
make[4]: *** [all] Error 2
make[4]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29'
Makefile:39: recipe for target '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/.built' failed
make[3]: *** [/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/pkg-config-0.29/.built] Error 2
make[3]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/tools/pkg-config'
tools/Makefile:122: recipe for target 'tools/pkg-config/compile' failed
make[2]: *** [tools/pkg-config/compile] Error 2
make[2]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya'
tools/Makefile:121: recipe for target '/home/pjw/MT7628/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy' failed
make[1]: *** [/home/pjw/MT7628/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya'
/home/pjw/MT7628/openwrt-hiwooya/include/toplevel.mk:181: recipe for target 'world' failed
make: *** [world] Error 2

原因:

与编译器版本有关

查找出问题的函数:

tmplen = strftime (tmpbuf, tmpbufsize, locale_format, &tm);

路径:/build_dir/host/pkg-config-0.29/glib/glib/gdate.c


解决:

改变该函数的报错级别,使用补丁的方式修改源码:

# 创建补丁文件夹
mkdir tools/pkg-config/patches/&&cd tools/pkg-config/patches/
# 创建补丁文件
vim 001-glib-gdate-suppress-string-format-literal-warning.patch

001-glib-gdate-suppress-string-format-literal-warning.patch内容:

--- a/glib/glib/gdate.c
+++ b/glib/glib/gdate.c
@@ -2439,6 +2439,9 @@ win32_strftime_helper (const GDate     *d,
  *
  * Returns: number of characters written to the buffer, or 0 the buffer was too small
  */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
 gsize     
 g_date_strftime (gchar       *s, 
                  gsize        slen, 
@@ -2549,3 +2552,5 @@ g_date_strftime (gchar       *s,
   return retval;
 #endif
 }
+
+#pragma GCC diagnostic pop

问题二:

recipe for target '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/automake-1.15/.configured' failed

Makefile:50: recipe for target '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/automake-1.15/.configured' failed
make[3]: *** [/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/automake-1.15/.configured] Error 255
make[3]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/tools/automake'
tools/Makefile:122: recipe for target 'tools/automake/compile' failed
make[2]: *** [tools/automake/compile] Error 2
make[2]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya'
tools/Makefile:121: recipe for target '/home/pjw/MT7628/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy' failed
make[1]: *** [/home/pjw/MT7628/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya'
/home/pjw/MT7628/openwrt-hiwooya/include/toplevel.mk:181: recipe for target 'world' failed
make: *** [world] Error 2

原因:

# 查询 perl 版本
perl -version

This is perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux-gnu-thread-multi

新版本perl对一些写法不支持


解决:

# 创建补丁文件
vim tools/automake/patches/210_automake_perl_5.26.1_ver.patch

210_automake_perl_5.26.1_ver.patch内容:

diff --git a/bin/automake.in b/bin/automake.in
index a3a0aa318..2c8f31e14 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -3878,7 +3878,7 @@ sub substitute_ac_subst_variables_worker
 sub substitute_ac_subst_variables
 {
   my ($text) = @_;
-  $text =~ s/\${([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;
+  $text =~ s/\$[{]([^ \t=:+{}]+)}/substitute_ac_subst_variables_worker ($1)/ge;
   return $text;
 }

问题三:

fatal error: linux/compiler-gcc7.h: No such file or directory

In file included from include/linux/compiler.h:54:0,
                 from /home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10/arch/sandbox/include/asm/bitops.h:20,
                 from include/linux/bitops.h:110,
                 from /home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10/include/common.h:20:
include/linux/compiler-gcc.h:114:1: fatal error: linux/compiler-gcc7.h: No such file or directory
 #include gcc_header(__GNUC__)
 ^~~~
compilation terminated.
/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10/scripts/Makefile.autoconf:64: recipe for target 'include/autoconf.mk' failed
make[6]: *** [include/autoconf.mk] Error 1
/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10/Makefile:464: recipe for target 'silentoldconfig' failed
make[5]: *** [silentoldconfig] Error 1
make[4]: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/uboot.release'.  Stop.
make[4]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10'
Makefile:46: recipe for target '/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10/.built' failed
make[3]: *** [/home/pjw/MT7628/openwrt-hiwooya/build_dir/host/u-boot-2014.10/.built] Error 2
make[3]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya/tools/mkimage'
tools/Makefile:122: recipe for target 'tools/mkimage/compile' failed
make[2]: *** [tools/mkimage/compile] Error 2
make[2]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya'
tools/Makefile:121: recipe for target '/home/pjw/MT7628/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy' failed
make[1]: *** [/home/pjw/MT7628/openwrt-hiwooya/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/pjw/MT7628/openwrt-hiwooya'
/home/pjw/MT7628/openwrt-hiwooya/include/toplevel.mk:181: recipe for target 'world' failed
make: *** [world] Error 2

原因:

查询GCC版本:

gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 

版本是7.5.0,则compiler-gcc7.h肯定是对应的gcc的 7 版本的。
搜索发现 compiler-gcc*.h 文件在以下位置:build_dir/host/u-boot-2014.10/include/linux/"
里面只有compiler-gcc3.hcompiler-gcc4.hcompiler-gcc5.h、没有compiler-gcc7.h,所以报错了。


解决:

方法1:
拷贝一份compiler-gcc3.h或者compiler-gcc4.h等文件,将其中一个重命名为compiler-gcc7.h

cp build_dir/host/u-boot-2014.10/include/linux/compiler-gcc3.h build_dir/host/u-boot-2014.10/include/linux/compiler-gcc7.h

方法2:
发现tools/mkimage/patches目录下有200-gcc5_compat.patch,拷贝一份并重命名,然后把里面的gcc5全部替换成gcc7

cp 200-gcc5_compat.patch 201-gcc7_compat.patch

201-gcc7_compat.patch内容:

From 478b02f1a7043b673565075ea5016376f3293b23 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Sat, 7 Feb 2015 22:52:40 +0100
Subject: [PATCH] Add linux/compiler-gcc7.h to fix builds with gcc7

Add linux/compiler-gcc7/h from the kernel sources at:

commit 5631b8fba640a4ab2f8a954f63a603fa34eda96b
Author: Steven Noonan <steven@uplinklabs.net>
Date:   Sat Oct 25 15:09:42 2014 -0700

    compiler/gcc4+: Remove inaccurate comment about 'asm goto' miscompiles

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 include/linux/compiler-gcc7.h |   65 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 include/linux/compiler-gcc7.h

diff --git a/include/linux/compiler-gcc7.h b/include/linux/compiler-gcc7.h
new file mode 100644
index 0000000..c8c5659
--- /dev/null
+++ b/include/linux/compiler-gcc7.h
@@ -0,0 +1,65 @@
+#ifndef __LINUX_COMPILER_H
+#error "Please don't include <linux/compiler-gcc7.h> directly, include <linux/compiler.h> instead."
+#endif
+
+#define __used				__attribute__((__used__))
+#define __must_check			__attribute__((warn_unused_result))
+#define __compiler_offsetof(a, b)	__builtin_offsetof(a, b)
+
+/* Mark functions as cold. gcc will assume any path leading to a call
+   to them will be unlikely.  This means a lot of manual unlikely()s
+   are unnecessary now for any paths leading to the usual suspects
+   like BUG(), printk(), panic() etc. [but let's keep them for now for
+   older compilers]
+
+   Early snapshots of gcc 4.3 don't support this and we can't detect this
+   in the preprocessor, but we can live with this because they're unreleased.
+   Maketime probing would be overkill here.
+
+   gcc also has a __attribute__((__hot__)) to move hot functions into
+   a special section, but I don't see any sense in this right now in
+   the kernel context */
+#define __cold			__attribute__((__cold__))
+
+#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
+
+#ifndef __CHECKER__
+# define __compiletime_warning(message) __attribute__((warning(message)))
+# define __compiletime_error(message) __attribute__((error(message)))
+#endif /* __CHECKER__ */
+
+/*
+ * Mark a position in code as unreachable.  This can be used to
+ * suppress control flow warnings after asm blocks that transfer
+ * control elsewhere.
+ *
+ * Early snapshots of gcc 4.5 don't support this and we can't detect
+ * this in the preprocessor, but we can live with this because they're
+ * unreleased.  Really, we need to have autoconf for the kernel.
+ */
+#define unreachable() __builtin_unreachable()
+
+/* Mark a function definition as prohibited from being cloned. */
+#define __noclone	__attribute__((__noclone__))
+
+/*
+ * Tell the optimizer that something else uses this function or variable.
+ */
+#define __visible __attribute__((externally_visible))
+
+/*
+ * GCC 'asm goto' miscompiles certain code sequences:
+ *
+ *   http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
+ *
+ * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
+ *
+ * (asm goto is automatically volatile - the naming reflects this.)
+ */
+#define asm_volatile_goto(x...)	do { asm goto(x); asm (""); } while (0)
+
+#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
+#define __HAVE_BUILTIN_BSWAP32__
+#define __HAVE_BUILTIN_BSWAP64__
+#define __HAVE_BUILTIN_BSWAP16__
+#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
-- 
1.7.10.4

问题四:

cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute

In file included from /home/pjw/MTK/MY_openwrt_mt7628/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/cp/except.c:1008:0:
cfns.gperf: In function 'const char* libc_name_p(const char*, unsigned int)':
cfns.gperf:101:1: error: 'const char* libc_name_p(const char*, unsigned int)' redeclared inline with 'gnu_inline' attribute
cfns.gperf:26:14: note: 'const char* libc_name_p(const char*, unsigned int)' previously declared here
cfns.gperf: At global scope:
cfns.gperf:26:14: warning: inline function 'const char* libc_name_p(const char*, unsigned int)' used but never defined
Makefile:1058: recipe for target 'cp/except.o' failed

原因:

自从gperf的3.0.3版本(2007年5月发布)以来,生成的func应用了gnu_inline属性,尚未更新以包含导致不匹配的内容。

实际上,这不是一个问题,原因有两个:
(1) 在gcc-5之前,默认标准是(gnu)C89,而gcc没有在此模式下发出警告或抛出错误。
(2) 从gcc-4.8开始,用于构建gcc的编译器驱动程序是更改为C++,并且在这种模式下g++不会发出警告或抛出错误。

使用gcc-5构建gcc-4.7或默认值为(gnu)C11 和 C编译器驱动程序会失败:

In file included from .../gcc-4.7.4/gcc/cp/except.c:990:0:
cfns.gperf: At top level:
cfns.gperf:101:1: error: 'gnu_inline' attribute present on 'libc_name_p'
cfns.gperf:26:14: error: but not here

总的来说就是用高版本的gcc编译了低版本的gcc的程序。


解决:

修改 /build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/gcc/cp/cfns.gperfcfns.h 两个文件

在gcc补丁目录下创建一个补丁:

# /package/feeds/packages/gcc/patches 链接的 /feeds/packages/devel/gcc/patches
touch /feeds/packages/devel/gcc/patches/930-cfns_fix_mismatch_in-gnu_inline-attributes.patch

# 或者在 gcc 上层目录即 /build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/gcc-linaro-4.8-2014.04/ 下直接打补丁
patch -p1 < 930-cfns_fix_mismatch_in-gnu_inline-attributes.patch 

930-cfns_fix_mismatch_in-gnu_inline-attributes.patch

Since the 3.0.3 release of gperf (made in May 2007), the generated func
has had the gnu_inline attribute applied to it.  The gcc source however
has not been updated to include that which has lead to a mismatch.

In practice, this hasn't been an issue for two reasons:
(1) Before gcc-5, the default standard was (gnu) C89, and gcc does not
warn or throw an error in this mode.
(2) Starting with gcc-4.8, the compiler driver used to build gcc was
changed to C++, and g++ does not warn or throw an error in this mode.

This error does show up though when using gcc-5 to build gcc-4.7 or
older as then the default is (gnu) C11 and the C compiler driver is
used.  That failure looks like:
In file included from .../gcc-4.7.4/gcc/cp/except.c:990:0:
cfns.gperf: At top level:
cfns.gperf:101:1: error: 'gnu_inline' attribute present on 'libc_name_p'
cfns.gperf:26:14: error: but not here

Whether the compiler should always emit this error regardless of the
active standard or compiler driver is debatable (I think it should be
consistent -- either always do it or never do it).

2015-08-06  Mike Frysinger  <vapier@gentoo.org>

	* cfns.gperf [__GNUC__, __GNUC_STDC_INLINE__]: Apply the
	__gnu_inline__ attribute.
	* cfns.h: Regenerated.
---
 gcc/cp/cfns.gperf | 3 +++
 gcc/cp/cfns.h     | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/gcc/cp/cfns.gperf b/gcc/cp/cfns.gperf
index 68acd3d..953262f 100644
--- a/gcc/cp/cfns.gperf
+++ b/gcc/cp/cfns.gperf
@@ -22,6 +22,9 @@ __inline
 static unsigned int hash (const char *, unsigned int);
 #ifdef __GNUC__
 __inline
+#ifdef __GNUC_STDC_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
 #endif
 const char * libc_name_p (const char *, unsigned int);
 %}
diff --git a/gcc/cp/cfns.h b/gcc/cp/cfns.h
index 1c6665d..6d00c0e 100644
--- a/gcc/cp/cfns.h
+++ b/gcc/cp/cfns.h
@@ -53,6 +53,9 @@ __inline
 static unsigned int hash (const char *, unsigned int);
 #ifdef __GNUC__
 __inline
+#ifdef __GNUC_STDC_INLINE__
+__attribute__ ((__gnu_inline__))
+#endif
 #endif
 const char * libc_name_p (const char *, unsigned int);
 /* maximum key range = 391, duplicates = 0 */
-- 
2.4.4

参考:
error: format not a string literal, format string not checked [-Werror=format-nonlit]
【OpenWRT】(linkit7688) 从源码编译和问题解决
Ubuntu18.04交叉编译glib
openwrt编译时automake.tmp错误
【问题解决】linux/compiler-gcc7.h:没有那个文件或目录
[PATCH] cfns: fix mismatch in gnu_inline attributes

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值