I'm using ChibiOS 16.1.4 on an STM32F303. I am attempting to use va_list, va_args, etc. in a function, but whenever I include <stdargs.h> and use those functions, I get the following linker errors:
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-mallocr.o): In function `_malloc_r':
mallocr.c:(.text._malloc_r+0x232): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_r+0x292): undefined reference to `_sbrk_r'
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-freer.o): In function `_malloc_trim_r':
mallocr.c:(.text._malloc_trim_r+0x30): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_trim_r+0x4a): undefined reference to `_sbrk_r'
mallocr.c:(.text._malloc_trim_r+0x72): undefined reference to `_sbrk_r'
I have included ChibiOS/os/various/syscalls.c in the Makefile. Without it, the error is much simpler:
/opt/homebrew-cask/Caskroom/gcc-arm-embedded/5_2-2015q4,20151219/gcc-arm-none-eabi-5_2-2015q4/bin/../lib/gcc/arm-none-eabi/5.2.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
I see _sbrk_r defined in syscalls.c, so why can it still not find it after I include it? If I delete all references to va_list, va_args, etc., the compiler is successful again. How can I use variadic arguments in ChibiOS? I know chprintf uses it, so it must be possible.
Undefined reference to _sbrk_r for variadic arguments Topic is solved
-
raphaelchang
- Posts: 6
- Joined: Sat Jul 23, 2016 7:50 am
- Been thanked: 1 time
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Undefined reference to _sbrk_r for variadic arguments
Hi,
Note that chprintf () does not require syscalls.c, so it could be something else requiring _sbrk_r() not va_list.
Is syscall.c actually compiled? it could be an error in the makefile. Anyway, I am unable to duplicate the problem, chprintf does it. Best way is if you could post a small minimal project.
Giovanni
Note that chprintf () does not require syscalls.c, so it could be something else requiring _sbrk_r() not va_list.
Is syscall.c actually compiled? it could be an error in the makefile. Anyway, I am unable to duplicate the problem, chprintf does it. Best way is if you could post a small minimal project.
Giovanni
-
raphaelchang
- Posts: 6
- Joined: Sat Jul 23, 2016 7:50 am
- Been thanked: 1 time
Re: Undefined reference to _sbrk_r for variadic arguments
Thank you for your reply. I found that the problem is actually in calling vsnprintf, not va_list. If I just comment out that one line, the project compiles. I think syscalls.c is being compiled, because the error changes when I add it to the makefile.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Undefined reference to _sbrk_r for variadic arguments
Is it printed in console while compiling? all files are listed there.
Giovanni
Giovanni
-
raphaelchang
- Posts: 6
- Joined: Sat Jul 23, 2016 7:50 am
- Been thanked: 1 time
Re: Undefined reference to _sbrk_r for variadic arguments
Yes, it is printed. I have resolved the issue by adding --specs=nosys.specs to the compiler options, and not including syscalls.c. If I include syscalls.c the error remains.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Undefined reference to _sbrk_r for variadic arguments
It must be a conflict with the default implementation of syscalls.c.
Note that the error disappearing does not mean it works correctly, you need to use the syscalls.c for ChibiOS.
I'll give it a try tomorrow.
Giovanni
Note that the error disappearing does not mean it works correctly, you need to use the syscalls.c for ChibiOS.
I'll give it a try tomorrow.
Giovanni
Re: Undefined reference to _sbrk_r for variadic arguments
Did you solve this?
I am trying to build an old project; I installed the latest GNU ARM Embedded Tools (5.4 2016q3) and upgraded from ChibiOS 2.6.7 to 2.6.8 and without adding --specs=nosys.specs to the compiler options, it fails with the same undefined reference.
I am trying to build an old project; I installed the latest GNU ARM Embedded Tools (5.4 2016q3) and upgraded from ChibiOS 2.6.7 to 2.6.8 and without adding --specs=nosys.specs to the compiler options, it fails with the same undefined reference.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Undefined reference to _sbrk_r for variadic arguments
I haven't tried this yet, moving this thread to bug reports so it will not be lost.
Giovanni
Giovanni
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: Undefined reference to _sbrk_r for variadic arguments
Hi,
Fixed as bug #789.
The GCC garbage collector does not see as used the functions in syscalls.c because there is nothing in the code calling them, the call happens from within the library and apparently the linker does not consider those. It is a GCC bug I think but I worked around it by declaring functions as "used".
Giovanni
Fixed as bug #789.
The GCC garbage collector does not see as used the functions in syscalls.c because there is nothing in the code calling them, the call happens from within the library and apparently the linker does not consider those. It is a GCC bug I think but I worked around it by declaring functions as "used".
Giovanni