|
我在编译cubietruck的内核时,出现如下错误,然后编译就停止了- LD arch/arm/mach-sun7i/pm/standby/standby.elf
- arch/arm/mach-sun7i/pm/standby/mem_printk.o: In function `itoa':
- /mnt/build/cubie-kernel-source/arch/arm/mach-sun7i/pm/standby/mem_printk.c:168: undefined reference to `memcpy'
- arch/arm/mach-sun7i/pm/standby/mem_printk.o: In function `utoa':
- /mnt/build/cubie-kernel-source/arch/arm/mach-sun7i/pm/standby/mem_printk.c:214: undefined reference to `memcpy'
- arch/arm/mach-sun7i/pm/standby/mem_printk.o: In function `print_align':
- /mnt/build/cubie-kernel-source/arch/arm/mach-sun7i/pm/standby/mem_printk.c:369: undefined reference to `memcpy'
- make[3]: *** [arch/arm/mach-sun7i/pm/standby/standby.elf] Error 1
- make[2]: *** [arch/arm/mach-sun7i/pm/standby/standby.bin] Error 2
- make[1]: *** [arch/arm/mach-sun7i/pm] Error 2
- make: *** [arch/arm/mach-sun7i] Error 2
- make: *** Waiting for unfinished jobs....
复制代码 定位到arch/arm/mach-sun7i/pm/standby/mem_printk.c的168行,却发现并没有调用到”memcpy“函数。- 162 char *itoa(int value, char *string, int radix)
- 163 {
- 164 char stack[16];
- 165 int negative = 0; //defualt is positive value
- 166 int i;
- 167 int j;
- 168 char digit_string[] = "0123456789ABCDEF";
- 169
复制代码 那么问题出在哪里呢?很可能就是编译器优化出的问题。我是在arm环境下编译的,gcc是debian7 arm源里面安装的。- sing built-in specs.
- COLLECT_GCC=gcc
- COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
- Target: arm-linux-gnueabihf
- Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
- Thread model: posix
- gcc version 4.6.3 (Debian 4.6.3-14)
复制代码 那么好吧!我们就看下优化参数。一般每个模块都有自己的编译参数,所以我们要打开
arch/arm/mach-sun7i/pm/standby/Makefile- 15 KBUILD_CFLAGS := $(LINUXINCLUDE) -I$(srctree)/arch/arm/mach-sun7i/pm -Os -g -c
- 16 KBUILD_CFLAGS += -nostdlib -march=armv7-a -marm -mlittle-endian -D__STANDBY_MODULE__
- 17 KBUILD_CFLAGS += -fno-unwind-tables -fno-asynchronous-unwind-tables
- 18 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
复制代码 看到了第15行的编译优化参数-Os,这个是介于O2和O3之间的优化选项,把-Os改为-O2,编译。没有出错。
所以以后编译内核的时候遇到莫名其妙的问题,很可能就是编译参数出错了。之前大家说的某某版本的gcc编译不了内核,很可能就是因为不同版本的编译优化方式不一样。
|
|