public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to omit libc (newlib) on bare metal (freestanding)?
@ 2023-02-21 23:31 Josef Wolf
  2023-02-22  9:02 ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: Josef Wolf @ 2023-02-21 23:31 UTC (permalink / raw)
  To: gcc-help

Hello all,

I am trying to build for a bare metal target without any OS support and I want
to omit libc (newlib).

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

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!

-- 
Josef Wolf
jw@raven.inka.de

^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: How to omit libc (newlib) on bare metal (freestanding)?
@ 2023-03-11 22:59 unlvsur unlvsur
  0 siblings, 0 replies; 7+ messages in thread
From: unlvsur unlvsur @ 2023-03-11 22:59 UTC (permalink / raw)
  To: gcc-help, jw

[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]

"FFreestanding" doesn't imply that you should build your C or C++ program using a freestanding approach. Additionally, it's worth noting that GCC 9.3 is outdated and will soon be deprecated, so it's recommended that you upgrade to the latest native GCC version first. Then, use this new GCC version to build a new cross toolchain for the latest GCC 13 (which will soon be updated to GCC 14). It's important to keep in mind that freestanding C++ is not supported by GCC versions prior to GCC 12. To create a new cross compiler, you can use the following configure options: --without-headers --disable-shared --disable-threads --disable-nls --disable-werror --disable-libssp --disable-libquadmath --disable-libbacktarce --enable-languages=c,c++ --enable-multilib --disable-bootstrap --disable-libstdcxx-verbose --with-libstdcxx-eh-pool-obj-count=0 --disable-sjlj-exceptions --disable-hosted-libstdcxx. Once this is complete, you will have a new cross freestanding GCC toolchain that doesn't rely on newlib dependencies. Finally, you can use an x86_64-w64-mingw32 target GCC cross compiler for Canadian compilation to obtain a toolchain that runs on Windows.


Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-11 22:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 23:31 How to omit libc (newlib) on bare metal (freestanding)? Josef Wolf
2023-02-22  9:02 ` Jonathan Wakely
2023-02-22  9:03   ` Jonathan Wakely
2023-02-22 11:35     ` Richard Earnshaw
2023-03-06 14:40       ` Josef Wolf
2023-03-07 11:08         ` Arsen Arsenović
2023-03-11 22:59 unlvsur unlvsur

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).