On 22/02/2023 09:03, Jonathan Wakely via Gcc-help wrote:
On Wed, 22 Feb 2023, 09:02 Jonathan Wakely, <jwakely.gcc@xxxxxxxxx> wrote:
On Tue, 21 Feb 2023, 23:32 Josef Wolf, <jw@xxxxxxxxxxxxx> wrote:
Hello all,
I am trying to build for a bare metal target without any OS support and I
want
to omit libc (newlib).
Do you mean you're trying to build GCC itself, or you're trying to build
your own program?
So I add
-ffunction-sections -nostdlib -ffreestanding
flags to assembler/compiler and
-lnosys -nolibc -nodefaultlibs -nostartfiles -nostdlib -ffreestanding
-static-libgcc -lgcc -lnosys -nolibc -nodefaultlibs -nostartfiles
-nostdlib -ffreestanding -static-libgcc -lgcc
to linker
Please show the full commands you're using
If you add -v to the gcc command it will show exactly what it's doing.
Oh actually I see the problem. You're using -lgcc and your gcc was
configured to use newlib, so libgcc depends on newlib.
Whilst there are functions in libgcc that depend on newlib (not many and
probably none that you'd need in this instance), I wouldn't have
expected -lgcc to cause -lc to be added to the link set.
Josef, what is the *complete* command line that you issue when you link
the program?
R.
But gcc still tries to pull newlib:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-init.o):
in function `__libc_init_array':
/var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/misc/init.c:40:
undefined reference to `_init'
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-sbrkr.o):
in function `_sbrk_r':
/var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/sbrkr.c:51:
undefined reference to `_sbrk'
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-writer.o):
in function `_write_r':
/var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/writer.c:49:
undefined reference to `_write'
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-closer.o):
in function `_close_r':
/var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/closer.c:47:
undefined reference to `_close'
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-lseekr.o):
in function `_lseek_r':
/var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/lseekr.c:49:
undefined reference to `_lseek'
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld:
/m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc.a(lib_a-readr.o):
in function `_read_r':
/var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/readr.c:49:
undefined reference to `_read'
collect2: error: ld returned 1 exit status
So what is the magic option to tell gcc not to mess around with libc
(newlib)?
Thanks!