public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Josef Wolf <jw@raven.inka.de>, gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: How to omit libc (newlib) on bare metal (freestanding)?
Date: Wed, 22 Feb 2023 09:03:52 +0000	[thread overview]
Message-ID: <CAH6eHdQa-AD+yJ=NT=DNwGbwTw72tEe5M-9d-wXjJr5GE88gjw@mail.gmail.com> (raw)
In-Reply-To: <CAH6eHdQLUzfWo-HoSzZUL=YF4K_bMqQ2vaNwnX+C_zBEj52g1Q@mail.gmail.com>

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

On Wed, 22 Feb 2023, 09:02 Jonathan Wakely, <jwakely.gcc@gmail.com> wrote:

>
>
> On Tue, 21 Feb 2023, 23:32 Josef Wolf, <jw@raven.inka.de> 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.



>
>
>
>
>
>
>>
>>
>> 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!
>>
>>
>>

  reply	other threads:[~2023-02-22  9:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 23:31 Josef Wolf
2023-02-22  9:02 ` Jonathan Wakely
2023-02-22  9:03   ` Jonathan Wakely [this message]
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='CAH6eHdQa-AD+yJ=NT=DNwGbwTw72tEe5M-9d-wXjJr5GE88gjw@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jw@raven.inka.de \
    /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).