public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Josef Wolf <jw@raven.inka.de>
To: gcc-help@gcc.gnu.org
Subject: How to omit libc (newlib) on bare metal (freestanding)?
Date: Wed, 22 Feb 2023 00:31:25 +0100	[thread overview]
Message-ID: <20230221233125.GA2142@raven.inka.de> (raw)

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

             reply	other threads:[~2023-02-21 23:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 23:31 Josef Wolf [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230221233125.GA2142@raven.inka.de \
    --to=jw@raven.inka.de \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).