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-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
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2023-02-22  9:02 UTC (permalink / raw)
  To: Josef Wolf, gcc-help

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

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.







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

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

* Re: How to omit libc (newlib) on bare metal (freestanding)?
  2023-02-22  9:02 ` Jonathan Wakely
@ 2023-02-22  9:03   ` Jonathan Wakely
  2023-02-22 11:35     ` Richard Earnshaw
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2023-02-22  9:03 UTC (permalink / raw)
  To: Josef Wolf, gcc-help

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

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

* Re: How to omit libc (newlib) on bare metal (freestanding)?
  2023-02-22  9:03   ` Jonathan Wakely
@ 2023-02-22 11:35     ` Richard Earnshaw
  2023-03-06 14:40       ` Josef Wolf
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Earnshaw @ 2023-02-22 11:35 UTC (permalink / raw)
  To: Jonathan Wakely, Josef Wolf, gcc-help



On 22/02/2023 09:03, Jonathan Wakely via Gcc-help wrote:
> 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.

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

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

* Re: How to omit libc (newlib) on bare metal (freestanding)?
  2023-02-22 11:35     ` Richard Earnshaw
@ 2023-03-06 14:40       ` Josef Wolf
  2023-03-07 11:08         ` Arsen Arsenović
  0 siblings, 1 reply; 7+ messages in thread
From: Josef Wolf @ 2023-03-06 14:40 UTC (permalink / raw)
  To: Richard Earnshaw; +Cc: Jonathan Wakely, gcc-help

Thanks for the replies, and sorry for the delay!

On Wed, Feb 22, 2023 at 11:35:51AM +0000, Richard Earnshaw wrote:
> On 22/02/2023 09:03, Jonathan Wakely via Gcc-help wrote:
> > 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:
> > > >
> > > > 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
> > > 
> > > Do you mean you're trying to build GCC itself, or you're trying to build
> > > your own program?

I am trying to build my own program using GCC which I have built by myself :)

> > > Please show the full commands you're using
> > > 
> > > If you add -v to the gcc command it will show exactly what it's doing.

Appended to the end of this post.

> > Oh actually I see the problem. You're using -lgcc and your gcc was
> > configured to use newlib, so libgcc depends on newlib.

I am irritated about that. I see that libgcc needs malloc() and friends. But I
don't see why libgcc would need sbrk/write/close/lseek/read.

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

Exactly. As a side-note: I provide my own implementations of memcpy() and
friends, So I don't see why gcc would need to pull them from
newlib. Especially when I explicitly provide all those fancy options I
mentioned above to prevent using any libraries.

> Josef, what is the *complete* command line that you issue when you link the
> program?

Here it comes:

$ /usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc \
    lots.o of.o object.o files.o \
    -v -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard \
    -Tcubemx/STM32F429BITx_FLASH.ld  -nostdlib -lm -lnosys -nolibc \
    -nodefaultlibs -nostartfiles -nostdlib -ffreestanding -static-libgcc \
    -Wl,-Map=build/cubemx.map,--cref \
    -Wl,--gc-sections,--exclude-libs,libc.a \
    -o build/cubemx.elf
Using built-in specs.
COLLECT_GCC=/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/lto-wrapper
Target: arm-none-eabi
Configured with: /var/tmp/builds/crossgcc/src/gcc-9.3.0/configure --target=arm-none-eabi --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --enable-languages=c,c++ --with-gnu-ld --with-gnu-as --with-newlib --with-system-zlib --enable-commonbfdlib --enable-interwork --enable-install-libbfd --enable-plugins --enable-multilib --disable-nls --disable-shared --disable-libssp --nfp --gas -v --prefix=/usr/local/crossgcc/arm-none-eabi --enable-languages=c,c++ --with-pkgversion=crossgcc --disable-libstdcxx-verbose --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libstdcxx-pch --disable-threads --disable-tls --with-headers=yes --with-multilib-list=rmprofile
Thread model: single
gcc version 9.3.0 (crossgcc)
COMPILER_PATH=/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/:/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/
LIBRARY_PATH=/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/thumb/v7e-m+fp/hard/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/
COLLECT_GCC_OPTIONS='-v' '-mcpu=cortex-m4' '-mthumb' '-mfpu=fpv4-sp-d16' '-mfloat-abi=hard' '-T' 'cubemx/STM32F429BITx_FLASH.ld' '-nostdlib' '-nolibc' '-nodefaultlibs' '-nostartfiles' '-nostdlib' '-ffreestanding' '-static-libgcc' '-o' 'build/cubemx.elf' '-march=armv7e-m+fp'
 /usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/collect2 -plugin /usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/liblto_plugin.so -plugin-opt=/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccXjRFlS.res -X -o build/cubemx.elf -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/thumb/v7e-m+fp/hard -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0 -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib lots.o of.o object.o files.o -lm -lnosys -Map=build/cubemx.map --cref --gc-sections --exclude-libs libc.a -T cubemx/STM32F429BITx_FLASH.ld
 /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
 /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
 /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
 /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
 /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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
 make[1]: *** [cubemx/Makefile:209: build/cubemx.elf] Error 1
 make[1]: Leaving directory '/m/s/rep/git/siemens/it1010/src'
 make: *** [Makefile:16: all] Error 2


-- 
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-06 14:40       ` Josef Wolf
@ 2023-03-07 11:08         ` Arsen Arsenović
  0 siblings, 0 replies; 7+ messages in thread
From: Arsen Arsenović @ 2023-03-07 11:08 UTC (permalink / raw)
  To: Josef Wolf; +Cc: Richard Earnshaw, Jonathan Wakely, gcc-help

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


Josef Wolf <jw@raven.inka.de> writes:

>> > > Do you mean you're trying to build GCC itself, or you're trying to build
>> > > your own program?
>
> I am trying to build my own program using GCC which I have built by myself :)
>
>> > > Please show the full commands you're using
>> > > 
>> > > If you add -v to the gcc command it will show exactly what it's doing.
>
> Appended to the end of this post.
>
>> > Oh actually I see the problem. You're using -lgcc and your gcc was
>> > configured to use newlib, so libgcc depends on newlib.
>
> I am irritated about that. I see that libgcc needs malloc() and friends. But I
> don't see why libgcc would need sbrk/write/close/lseek/read.
>
>> 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.
>
> Exactly. As a side-note: I provide my own implementations of memcpy() and
> friends, So I don't see why gcc would need to pull them from
> newlib. Especially when I explicitly provide all those fancy options I
> mentioned above to prevent using any libraries.

This is because libgcc was built with newlib.  If you do not want
newlib, I suggest configuring with --without-headers --without-newlib.
I've also added some support code to that configuration recently, but I
don't think it'll match your configuration.  You might have to do some
patching after that for your new target, specifically to set
use_gcc_stdint=provide in config.gcc.

Please try adding those two flags to configure and seeing where that
goes.

Have a lovely day!

>> Josef, what is the *complete* command line that you issue when you link the
>> program?
>
> Here it comes:
>
> $ /usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc \
>     lots.o of.o object.o files.o \
>     -v -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard \
>     -Tcubemx/STM32F429BITx_FLASH.ld  -nostdlib -lm -lnosys -nolibc \
>     -nodefaultlibs -nostartfiles -nostdlib -ffreestanding -static-libgcc \
>     -Wl,-Map=build/cubemx.map,--cref \
>     -Wl,--gc-sections,--exclude-libs,libc.a \
>     -o build/cubemx.elf
> Using built-in specs.
> COLLECT_GCC=/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc
> COLLECT_LTO_WRAPPER=/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/lto-wrapper
> Target: arm-none-eabi
> Configured with: /var/tmp/builds/crossgcc/src/gcc-9.3.0/configure --target=arm-none-eabi --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --enable-languages=c,c++ --with-gnu-ld --with-gnu-as --with-newlib --with-system-zlib --enable-commonbfdlib --enable-interwork --enable-install-libbfd --enable-plugins --enable-multilib --disable-nls --disable-shared --disable-libssp --nfp --gas -v --prefix=/usr/local/crossgcc/arm-none-eabi --enable-languages=c,c++ --with-pkgversion=crossgcc --disable-libstdcxx-verbose --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libstdcxx-pch --disable-threads --disable-tls --with-headers=yes --with-multilib-list=rmprofile
> Thread model: single
> gcc version 9.3.0 (crossgcc)
> COMPILER_PATH=/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/:/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/
> LIBRARY_PATH=/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/thumb/v7e-m+fp/hard/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/
> COLLECT_GCC_OPTIONS='-v' '-mcpu=cortex-m4' '-mthumb' '-mfpu=fpv4-sp-d16' '-mfloat-abi=hard' '-T' 'cubemx/STM32F429BITx_FLASH.ld' '-nostdlib' '-nolibc' '-nodefaultlibs' '-nostartfiles' '-nostdlib' '-ffreestanding' '-static-libgcc' '-o' 'build/cubemx.elf' '-march=armv7e-m+fp'
>  /usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/collect2 -plugin /usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/liblto_plugin.so -plugin-opt=/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccXjRFlS.res -X -o build/cubemx.elf -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/thumb/v7e-m+fp/hard -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0 -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib lots.o of.o object.o files.o -lm -lnosys -Map=build/cubemx.map --cref --gc-sections --exclude-libs libc.a -T cubemx/STM32F429BITx_FLASH.ld
>  /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
>  /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
>  /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
>  /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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'
>  /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: /usr/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
>  make[1]: *** [cubemx/Makefile:209: build/cubemx.elf] Error 1
>  make[1]: Leaving directory '/m/s/rep/git/siemens/it1010/src'
>  make: *** [Makefile:16: all] Error 2


-- 
Arsen Arsenović

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 381 bytes --]

^ 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).