gcc自动阻止malloc并链接到libc

时间:2018-08-23 21:41:35

标签: gcc ld

在链接:)时我遇到了一个大问题,当我实例化这样的结构时,该问题最近出现了:

xTask_t t;
t = xAddCreate(GpsSetMcuUartDefault);
t->State = xRun;

//static xTask_t t;  // the same problem here
//t->Count = 10;

似乎gcc从libc自动链接到malloc,认为该对象需要存在。好的,在注释的代码中可以,但是在第一次调用xAddCreate()时,我已经拥有了自己的malloc,并且t有效!

由于这个原因,它只是吃掉了我的闪光灯

w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-mallocr.o):(.literal+0x2c): undefined reference to `_sbrk_r'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-mallocr.o): In function `malloc_extend_top':
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/stdlib/../../../../../newlib-2.0.0/newlib/libc/stdlib/mallocr.c:2165: undefined reference to `_sbrk_r'
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/stdlib/../../../../../newlib-2.0.0/newlib/libc/stdlib/mallocr.c:2202: undefined reference to `_sbrk_r'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-abort.o):(.literal+0x0): undefined reference to `_exit'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-abort.o): In function `abort':
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/stdlib/../../../../../newlib-2.0.0/newlib/libc/stdlib/abort.c:63: undefined reference to `_exit'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-signal.o):(.literal+0x0): undefined reference to `_getpid_r'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-signal.o):(.literal+0x4): undefined reference to `_kill_r'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-signal.o): In function `_raise_r':
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/signal/../../../../../newlib-2.0.0/newlib/libc/signal/signal.c:163: undefined reference to `_getpid_r'
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/signal/../../../../../newlib-2.0.0/newlib/libc/signal/signal.c:163: undefined reference to `_kill_r'
w:/esp8266/kit/toolchains/sysgcc/esp8266/bin/../lib/gcc/xtensa-lx106-elf/5.2.0/../../../../xtensa-lx106-elf/lib\libc.a(lib_a-freer.o): In function `_malloc_trim_r':
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/stdlib/../../../../../newlib-2.0.0/newlib/libc/stdlib/mallocr.c:3325: undefined reference to `_sbrk_r'
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/stdlib/../../../../../newlib-2.0.0/newlib/libc/stdlib/mallocr.c:3332: undefined reference to `_sbrk_r'
/q/gnu/auto/newlib-bu-2.24+gcc-5.2.0+gmp-5.1.3+mpfr-3.1.2+mpc-1.0.2+newlib-2.0.0-xtensa-lx106-elf/xtensa-lx106-elf/newlib/libc/stdlib/../../../../../newlib-2.0.0/newlib/libc/stdlib/mallocr.c:3340: undefined reference to `_sbrk_r'
collect2.exe: error: ld returned 1 exit status
make: *** [temp.elf] Error 1 

我的一个朋友建议从libc.a中获取ar并剥离malloc。 我该如何预防呢?

0 个答案:

没有答案