This is the mail archive of the
mailing list for the binutils project.
Archive (library) which overrides syscalls from toolchain's archive?
- From: Freddie Chopin <freddie dot chopin at gmail dot com>
- To: binutils at sourceware dot org
- Date: Fri, 25 Sep 2015 08:52:29 +0200
- Subject: Archive (library) which overrides syscalls from toolchain's archive?
- Authentication-results: sourceware.org; auth=none
I'm trying to archive the majority of my RTOS project (
https://github.com/DISTORTEC/distortos ) as a static library. It works with
every single source/object file except for the files where I override (or
provide) newlib's syscalls (
). The toolchain I am using is targeting ARM microcontrollers (arm-none-
eabi-). Newlib's syscalls are functions like _sbrk_r(), _write_r(), _open_r()
that are used internally by various other functions (malloc(), printf(),
fopen(), ...). There are maybe a dozen syscalls that need to be overridden.
If I link with my syscalls files as objects (not archived) and the archive
with rest of the code, then everything is fine - my own syscalls get
precedence and replace the stubs from the toolchain's archives.
If I want to link with my syscalls archived I get the following error:
> 3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-signalr.o): In
> function `_kill_r':
> c:61: undefined reference to `_kill'
> .3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-signalr.o): In
> function `_getpid_r':
> c:96: undefined reference to `_getpid'
> .3/../../../../arm-none-eabi/lib/armv7e-m/fpu/libg.a(lib_a-sbrkr.o): In
> function `_sbrk_r':
> 58: undefined reference to `_sbrk'
> collect2: error: ld returned 1 exit status
The problem is that my own _sbrk_r() from the archive is discarded and the
function from libg.a is used (a stub for _sbrk())... Is there any (possibly
simple and generic) way to solve it? Maybe I'm missing some command line
switch or a command in linker script? I've tried grouping (via command line
and in linker script) or forcing _sbrk_r() to be initially undefined with
EXTERN(_sbrk_r) in the linker script, but this didn't change much. However - I
might have done something wrong...
It works if I explicitly call any of the functions from the code that is
linked as objects (so not from any source that goes into the archive), but
that can hardly be considered a solution...
Basically I'm looking for a way to just force some functions to be taken from
Thanks in advance for any help!