uclinux 编译心得3:arm-uclinuxeabi-20160831工具链在UBUNTU16下编译中遇到的问题汇总

在编译心得1里提到了arm-uclinuxeabi-20160831工具链的编译以及碰到的一些问题类型。

最近觉得编译过程中问题描述的还是比较简单。想我开始编译工具链碰到这些问题时,也是费了很大的劲,到网上到处找资源。有的问题还是找不到资源,就去分析gcc的man 手册,才找到解决方案。后来发现其实这些问题都可通过gcc的man手册找到解决方案。因此建议若编译遇到问题后,还是沉下心,仔细的去看看编译手册资料吧。

因此又重新编译该工具链,将编译过程中的问题及解决方法汇总后写出来,也许能给其他朋友一些帮助。

这些问题都是因为主机系统的GCC编译检查更加严格,同时编译选项配置了-Werror,将告警按照错误进行处理造成的。

主机GCC:gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0


不多说了,直接上干货:


编译binutils-2.26.tar.bz2

问题1:在逻辑语句里直接使用整数告警。

       ../../opcodes/arm-dis.c:5510:33: error: ‘*’ in boolean context, suggest ‘&&’ instead [-Werror=int-in-bool-context]

      value_in_comment = off * 4 * U ? 1 : -1;
                         ~~~~~~~~^~~
../../opcodes/arm-dis.c:5522:33: error: ‘*’ in boolean context, suggest ‘&&’ instead [-Werror=int-in-bool-context]
      value_in_comment = off * 4 * U ? 1 : -1;
   解决方法:
      因为 off * 4 * U计算结果为整数,因此修改为条件判断,这样的结果就是逻辑值了。
      value_in_comment = (off * 4 * U)>0 ? 1 : -1;
      
../../opcodes/arm-dis.c: In function ‘print_insn_thumb32’:
../../opcodes/arm-dis.c:5510:33: error: ‘*’ in boolean context, suggest ‘&&’ instead [-Werror=int-in-bool-context]
      value_in_comment = off * 4 * U ? 1 : -1;
                         ~~~~~~~~^~~
../../opcodes/arm-dis.c:5522:33: error: ‘*’ in boolean context, suggest ‘&&’ instead [-Werror=int-in-bool-context]
      value_in_comment = off * 4 * U ? 1 : -1;
      


   问题2:switch case 语句没有配对的break;

          比如:
              switch  x:
            {

                case 1:

                case 2:

                    //code;

                break;


             }   
 gcc -DHAVE_CONFIG_H -I. -I../../gas  -I. -I../../gas -I../bfd -I../../gas/config -I../../gas/../include -I../../gas/.. -I../../gas/../bfd -DLOCALEDIR="\"/usr/local/share/locale\""  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I../../gas/../zlib -g -O2 -MT depend.o -MD -MP -MF .deps/depend.Tpo -c -o depend.o ../../gas/depend.c
../../gas/depend.c: In function ‘quote_string_for_make’:
../../gas/depend.c:123:5: error: this statement may fall through [-Werror=implicit-fallthrough=]
    i++;
    ~^~
../../gas/depend.c:126:2: note: here
  default:
   

                              xeabi/binutils/po'
/bin/bash ./libtool --tag=CC   --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I../../binutils/../zlib -g -O2  -static-libstdc++ -static-libgcc  -o size size.o bucomm.o version.o filemode.o ../bfd/libbfd.la ../libiberty/libiberty.a  -ldl
libtool: link: gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I../../binutils/../zlib -g -O2 -static-libstdc++ -static-libgcc -o size size.o bucomm.o version.o filemode.o  ../bfd/.libs/libbfd.a -L/home/dx/tools/build-res/test/binutils-2.26/arm-uclinuxeabi/zlib -lz ../libiberty/libiberty.a -ldl
gcc -DHAVE_CONFIG_H -I. -I../../binutils  -I. -I../../binutils -I../bfd -I../../binutils/../bfd -I../../binutils/../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -I../../binutils/../zlib -g -O2 -MT dwarf.o -MD -MP -MF .deps/dwarf.Tpo -c -o dwarf.o ../../binutils/dwarf.c
../../binutils/dwarf.c: In function ‘dwarf_select_sections_by_letters’:
../../binutils/dwarf.c:7536:25: error: this statement may fall through [-Werror=implicit-fallthrough=]
  do_debug_frames_interp = 1;
  ~~~~~~~~~~~~~~~~~~~~~~~^~~
../../binutils/dwarf.c:7537:7: note: here
       case 'f':
       ^~~~
../../binutils/dwarf.c: In function ‘read_and_display_attr_value’:
../../binutils/dwarf.c:1821:20: error: this statement may fall through [-Werror=implicit-fallthrough=]
    have_frame_base = 1;
    ~~~~~~~~~~~~~~~~^~~
../../binutils/dwarf.c:1822:2: note: here
  case DW_AT_location:
  ^~~~
../../binutils/dwarf.c:2096:23: error: this statement may fall through [-Werror=implicit-fallthrough=]
       have_frame_base = 1;
       ~~~~~~~~~~~~~~~~^~~
../../binutils/dwarf.c:2097:5: note: here
     case DW_AT_location:



gcc -DHAVE_CONFIG_H -I. -I../../binutils  -I. -I../../binutils -I../bfd -I../../binutils/../bfd -I../../binutils/../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -I../../binutils/../zlib -g -O2 -MT stabs.o -MD -MP -MF .deps/stabs.Tpo -c -o stabs.o ../../binutils/stabs.c
../../binutils/stabs.c: In function ‘parse_stab_members’:
../../binutils/stabs.c:2705:31: error: comparison between pointer and zero character constant [-Werror=pointer-compare]
        if (**pp == ';' || *pp == '\0')
 if (**pp == ';' || *pp ==(char *)( '\0'))
 -I../../gprof/../bfd  -I. -DLOCALEDIR="\"/usr/local/share/locale\""  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT gmon_io.o -MD -MP -MF .deps/gmon_io.Tpo -c -o gmon_io.o ../../gprof/gmon_io.c
mv -f .deps/gmon_io.Tpo .deps/gmon_io.Po
gcc -DHAVE_CONFIG_H -I. -I../../gprof  -DDEBUG -I../bfd -I../../gprof/../include -I../../gprof/../bfd  -I. -DLOCALEDIR="\"/usr/local/share/locale\""  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT gprof.o -MD -MP -MF .deps/gprof.Tpo -c -o gprof.o ../../gprof/gprof.c
../../gprof/gprof.c: In function ‘main’:
../../gprof/gprof.c:261:4: error: this statement may fall through [-Werror=implicit-fallthrough=]
    sym_id_add (optarg, EXCL_TIME);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../gprof/gprof.c:262:2: note: here
  case 'e':
  ^~~~
../../gprof/gprof.c:266:4: error: this statement may fall through [-Werror=implicit-fallthrough=]
    sym_id_add (optarg, INCL_TIME);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
GDB
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../bfd -I. -I../../bfd -I../../bfd/../include -DHAVE_bfd_elf32_littlearm_vec -DHAVE_bfd_elf32_bigarm_vec -DHAVE_bfd_elf32_little_generic_vec -DHAVE_bfd_elf32_big_generic_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Werror -g -O2 -MT coffgen.lo -MD -MP -MF .deps/coffgen.Tpo -c ../../bfd/coffgen.c -o coffgen.o
../../bfd/coffgen.c: In function ‘coff_print_symbol’:
../../bfd/coffgen.c:2099:8: error: this statement may fall through [-Werror=implicit-fallthrough=]
     if (combined->u.syment.n_type == T_NULL)
        ^
../../bfd/coffgen.c:2116:3: note: here
   case C_EXT:
   ^~~~
../../bfd/coffgen.c:2118:8: error: this statement may fall through [-Werror=implicit-fallthrough=]
     if (ISFCN (combined->u.syment.n_type))
        ^
../../bfd/coffgen.c:2136:3: note: here
   default:

解决方法:
  修改configure.in文件中的编译选项,增加   -Wimplicit-fallthrough=0 ,可解决这个问题。
另外一种更好的方法是,在case 最后面,增加__attribute__ ((fallthrough))。这样能更严谨的确认是真的不需要break;而不是编写代码的缺陷。
GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0"

问题3:未使用的常量


gcc -DHAVE_CONFIG_H -I. -I../../gas  -I. -I../../gas -I../bfd -I../../gas/config -I../../gas/../include -I../../gas/.. -I../../gas/../bfd -DLOCALEDIR="\"/usr/local/share/locale\""  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -I../../gas/../zlib -g -O2 -MT tc-arm.o -MD -MP -MF .deps/tc-arm.Tpo -c -o tc-arm.o `test -f 'config/tc-arm.c' || echo '../../gas/'`config/tc-arm.c
../../gas/config/tc-arm.c:262:30: error: ‘fpu_neon_ext_v8_1’ defined but not used [-Werror=unused-const-variable=]
 static const arm_feature_set fpu_neon_ext_v8_1 =
                              ^~~~~~~~~~~~~~~~~
../../gas/config/tc-arm.c:213:30: error: ‘arm_arch_full’ defined but not used [-Werror=unused-const-variable=]
 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1, -1);
                              ^~~~~~~~~~~~~
../../gas/config/tc-arm.c:161:30: error: ‘fpu_arch_neon_v1’ defined but not used [-Werror=unused-const-variable=]
 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
                              ^~~~~~~~~~~~~~~~
../../gas/config/tc-arm.c:160:30: error: ‘fpu_arch_vfp_v3’ defined but not used [-Werror=unused-const-variable=]
 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
                              ^~~~~~~~~~~~~~~
../../gas/config/tc-arm.c:158:30: error: ‘fpu_arch_vfp_v1’ defined but not used [-Werror=unused-const-variable=]
 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
 
 
 解决:

将 __attribute__((unused)) 增加到变量名前
                              ^~~~~~~~~~~~~~~
                             
  

  问题4:定义的BUF空间不够

                          

/bin/bash ./libtool --tag=CC   --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -I../../binutils/../zlib -g -O2  -static-libstdc++ -static-libgcc  -o size size.o bucomm.o version.o filemode.o ../bfd/libbfd.la ../libiberty/libiberty.a  -ldl
libtool: link: gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -I../../binutils/../zlib -g -O2 -static-libstdc++ -static-libgcc -o size size.o bucomm.o version.o filemode.o  ../bfd/.libs/libbfd.a -L/home/dx/tools/build-res/test/binutils-2.26/arm-uclinuxeabi/zlib -lz ../libiberty/libiberty.a -ldl
gcc -DHAVE_CONFIG_H -I. -I../../binutils  -I. -I../../binutils -I../bfd -I../../binutils/../bfd -I../../binutils/../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -I../../binutils/../zlib -g -O2 -MT dwarf.o -MD -MP -MF .deps/dwarf.Tpo -c -o dwarf.o ../../binutils/dwarf.c
mv -f .deps/dwarf.Tpo .deps/dwarf.Po
gcc -DHAVE_CONFIG_H -I. -I../../binutils  -I. -I../../binutils -I../bfd -I../../binutils/../bfd -I../../binutils/../include -DLOCALEDIR="\"/usr/local/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -I../../binutils/../zlib -g -O2 -MT prdbg.o -MD -MP -MF .deps/prdbg.Tpo -c -o prdbg.o ../../binutils/prdbg.c
../../binutils/prdbg.c: In function ‘pr_array_type’:
../../binutils/prdbg.c:500:20: error: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
  sprintf (buf, "%ld", (long) vma);
                    ^
In file included from /usr/include/stdio.h:862:0,
                 from ../../binutils/sysdep.h:25,
                 from ../../binutils/prdbg.c:26:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘__builtin___sprintf_chk’ output between 2 and 21 bytes into a destination of size 20
   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       __bos (__s), __fmt, __va_arg_pack ());
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../bfd -I. -I../../bfd -I../../bfd/../include -DHAVE_bfd_elf32_littlearm_vec -DHAVE_bfd_elf32_bigarm_vec -DHAVE_bfd_elf32_little_generic_vec -DHAVE_bfd_elf32_big_generic_vec -DBINDIR=\"/usr/local/bin\" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wimplicit-fallthrough=0 -Wshadow -Werror -g -O2 -MT opncls.lo -MD -MP -MF .deps/opncls.Tpo -c ../../bfd/opncls.c -o opncls.o
In file included from ../../bfd/opncls.c:26:0:
../../bfd/opncls.c: In function ‘bfd_fopen’:
./bfd.h:529:65: error: right-hand operand of comma expression has no effect [-Werror=unused-value]
 #define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = bool), TRUE)
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
../../bfd/opncls.c:263:5: note: in expansion of macro ‘bfd_set_cacheable’
     bfd_set_cacheable (nbfd, TRUE);
./bfd/ihex.c -o ihex.o
../../bfd/ihex.c: In function ‘ihex_bad_byte’:
../../bfd/ihex.c:223:19: error: ‘%03o’ directive writing between 3 and 11 bytes into a region of size 9 [-Werror=format-overflow=]
  sprintf (buf, "\\%03o", (unsigned int) c);
                   ^~~~
../../bfd/ihex.c:223:16: note: directive argument in the range [0, 4294967294]
  sprintf (buf, "\\%03o", (unsigned int) c);
                ^~~~~~~~
In file included from /usr/include/stdio.h:862:0,
                 from ../../bfd/sysdep.h:38,
                 from ../../bfd/ihex.c:123:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘__builtin___sprintf_chk’ output between 5 and 13 bytes into a destination of size 10
   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,



解决方案:   
这个 问题的最根本的原因是什么,我还没有仔细去分析。因为一般来说,这个代码应该没有问题的。可能是因为我是64位操作系统的原因吗?
但这个问题还不能简单的通过修改编译选项的方式来解决。因为这个问题确实是一个BUG。
 需要修改所有传入BUF的定义
还好,仔细看看代码,所有传入的BUF都是20字节的局部数组变量,   xxx[20]。很容易就修改了。

          只有一处是50字节的数组变量。也需要修改。

     

问题5:移位操作的是负数



F .deps/arm-dis.Tpo -c ../../opcodes/arm-dis.c -o arm-dis.o
../../opcodes/arm-dis.c: In function ‘print_insn_coprocessor’:
../../opcodes/arm-dis.c:2106:20: error: left shift of negative value [-Werror=shift-negative-value]
         imm |= (-1 << 7);
      
解决方案:
      因为都是-1的左移操作,因此先强转为无符号数,再将结果转换为有符号数。   
          imm |= (int)((unsigned int)(-1) << 7);
                    ^~

问题6:传入的参数可能是空指针,按照函数定义就会抛出异常 

     
gcc -Werror -Wno-error=unused-label -Wall -g -O2 -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -D__EXTENSIONS__=1 -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D_POSIX_PTHREAD_SEMANTICS=1 -D_TANDEM_SOURCE=1 -DHAVE_LIBZ=1 -DSTDC_HEADERS=1 -DHAVE_FCNTL_H=1 -DHAVE_UNISTD_H=1 -DHAVE_VPRINTF=1 -DHAVE_DCGETTEXT=1 -DHAVE_GETLINE=1 -DHAVE_STRSIGNAL=1 -DTARGET_arm -DTARGET_CPU=\"arm\" -DSYMBOL_PREFIX=\"\" -DBINUTILS_LDSCRIPTDIR=\"/../arm-uclinuxeabi/lib\" -DTARGET_ALIAS=\"arm-uclinuxeabi\" -DNO_GOT_CHECK=1 -DUSE_EMIT_RELOCS=1 -DEMIT_CTOR_DTOR=0 -DALWAYS_RELOC_TEXT=0 -I. -I/home/dx/tools/build-res/test/binutils-2.26/arm-uclinuxeabi/bfd -I/home/dx/tools/build-res/test/binutils-2.26/include   -c -o ld-elf2flt.o ld-elf2flt.c
ld-elf2flt.c: In function ‘main’:
ld-elf2flt.c:571:3: error: argument 1 null where non-null expected [-Werror=nonnull]
   unlink(output_elf);
   ^~~~~~~~~~~~~~~~~~
In file included from ld-elf2flt.c:24:0:
/usr/include/unistd.h:828:12: note: in a call to function ‘unlink’ declared here
 extern int unlink (const char *__name) __THROW __nonnull ((1));

解决方案:

   在调用函数处,检查是否为空指针。若是空指针则不要调用该函数。

   从这个问题,可以看出现在的编译器真的很强大。佩服啊。

   另外,针对这个问题,我浏览了该代码,初步判定应该还是代码不严谨造成的,在变量没有初始化的情况下,存在一种可能的分支调用该函数。


以上就是编译工具链过程中遇到的问题。



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值