[Picolibc] Why -nostdlib is necessary

R. Diez rdiezmail-newlib at yahoo.de
Fri Apr 8 01:47:58 PDT 2022


Hallo Keith:

>> I still feel uneasy about this work-around. The reason why -nostdlib is necessary
>> is because the user is using a GCC which already has a built-in libc.
>> I am building a toolchain from scratch and that flag is not necessary.
>> Picolibc documentation does not mention that C++ will not work with such a GCC
>> and "external" Picolibc, because libstdc++ is not being rebuilt.

> That's not actually the case -- you need this flag when bootstrapping a
> system to use picolibc as the native C library -- the compiler will be
> built to use picolibc, and until it has been installed, you'll have
> to use -nostdlib to keep it from failing until picolibc has been installed the first time.

I would like to understand more about this matter. Let's look at my toolchain makefile again:

https://github.com/rdiez/JtagDue/tree/master/Toolchain

That makefile is building a "phase 1" GCC cross-compiler without a libc by using '--without-headers'. Then it is cross-compiling Newlib or Picolibc with that phase 1 GCC, and afterwards it is building the final ("phase 2") GCC cross-compiler that uses the already-installed Newlib/Picolibc. I mean "installed" as in "installed on the toolchain bin etc. directories", and not "installed system wide".

The GCC phase 1 compiler is discarded in the end.

I am saying that the final GCC has a "built-in Newlib/Picolibc" because, to the user, GCC and the libc feels like a unit, and because you cannot really replace Newlib/Picolibc freely, for GCC's libstdc++ and libgcc depend on it.

This technique is a kind of bootstrapping, and it does not need '-nostdlib'. It is not actually mine, I stole it from somewhere else. I think OpenWrt uses the same approach.

You probably mean that you can optimise away phase 1 compiler, right? That would mean "installing" only the Picolibc headers so that GCC sees them, before actually building the Picolibc library. Is that approach documented somewhere?

Are the installed headers always the same, or are some files generated so that you would need to configure them first?

Regards,
   rdiez


More information about the Picolibc mailing list