Correct usage of nosys

Sven Pauli <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <10631115.nUPlyArG6x@sven-21k9cto1ww>
Hi Niklas,

what you're describing looks good, I'm currently doing it exactly that way 
with the most recent toolchain and newlib.

The functions you observe (_fstat, ...) are a basic set of syscalls that you 
might want to provide to adapt newlib to your platform/board/processor/
environment. A bit of information about this is
- https://sourceware.org/newlib/libc.html#Syscalls and
- a bit is here: https://sourceware.org/newlib/libgloss.html#Libc

When you use `--specs=nosys.specs` it will link against `libnosys` from 
`libgloss` (find it in libgloss/libnosys/) that provides stubs for these 
functions. They usually 'fail', that is, do nothing and return an error. Also 
they are attributed so that the compiler emits a symbol in a special section 
(`.gnu.warning....` for gcc IIRC) that hints a recent linker to emit the 
warnings you're seeing ('not implemented and will always fail').

Can you reduce your project to a minimum code example and show the command 
lines you use for compilation and linking?
Something seems to be off there.

Kind regards,
Sven


Am Dienstag, 18. Februar 2025, 09:18:47 CET schrieb Niklas Dusenlund:
> Hi!
> 
> I'm compiling for ARM cortex-m0. When I enable the nosys specs I get the
> following warnings:
> 
> ```
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin
> /ld:
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/li
> b/libc_nano.a(libc_a-fstatr.o): in function `_fstat_r':
> fstatr.c:(.text._fstat_r+0x1c): warning: _fstat is not implemented and will
> always fail
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin
> /ld:
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/li
> b/libc_nano.a(libc_a-fstatr.o): note: the message above does not take linker
> garbage collection into account
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bi
> n/ld:
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/li
> b/libc_nano.a(libc_a-isattyr.o): in function `_isatty_r':
> isattyr.c:(.text._isatty_r+0x18): warning: _isatty is not implemented and
> will always fail
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin
> /ld:
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/li
> b/libc_nano.a(libc_a-isattyr.o): note: the message above does not take
> linker garbage collection into account ```
> 
> I have no intention of using fstat or isatty. But if I implement the
> missing functions like this:
> 
> ```
> int _fstat(int fildes, struct stat *st) {
>   errno = ENOSYS;
>   return -1;
> }
> int _isatty(int file) { return -1; }
> ```
> 
> I get the following errors:
> 
> ```
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin
> /ld:
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/li
> b/libc_nano.a(libc_a-isattyr.o): in function `_isatty_r':
> isattyr.c:(.text._isatty_r+0x18): undefined reference to `_isatty'
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin
> /ld:
> /usr/local/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/li
> b/libc_nano.a(libc_a-fstatr.o): in function `_fstat_r':
> fstatr.c:(.text._fstat_r+0x1c): undefined reference to `_fstat'
> ```
> 
> If I remove the nosys specs I also get undefined references to _exit and
> _sbrk.
> 
> In older versions of newlib I could use nano+nosys without warnings. What
> is the appropriate way with the latest newlib? If I need to link in my own
> stubs, how do I actually do that?
> 
> - Niklas
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> <https://sourceware.org/pipermail/newlib/attachments/20250218/27b44c77/atta
> chment.htm>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.