|
|
Subscribe / Log in / New account

Nolibc: a minimal C-library replacement shipped with the kernel

Nolibc: a minimal C-library replacement shipped with the kernel

Posted Jan 22, 2023 15:40 UTC (Sun) by eru (subscriber, #2753)
Parent article: Nolibc: a minimal C-library replacement shipped with the kernel

If Nolibc consists only of headers containing macros and static functions, doesn't this mean that if an application consists of more than one C file, it may contain multiple copies of a library function called by both files?


to post comments

Nolibc: a minimal C-library replacement shipped with the kernel

Posted Jan 22, 2023 22:23 UTC (Sun) by wtarreau (subscriber, #51152) [Link] (2 responses)

> doesn't this mean that if an application consists of more than one C file, it may contain multiple copies of a library function called by both files?

In case of multiple files, yes definitely, but most of them are quite small, and multi-file projects relying on something like nolibc are rare.

A few functions had to be exported and we found how to do it by declaring them with the weak attribute (e.g. raise(), memcpy() and a few other ones that libgcc may depend on). In this case it's during the linking stage that the linker decides to keep a single copy of each. That's also how we dealt with errno/environ/etc lately. Eventually we could imagine replacing all static functions with weak ones if it proves to provide any benefit (not convinced at the moment).

Nolibc: a minimal C-library replacement shipped with the kernel

Posted Feb 1, 2023 5:45 UTC (Wed) by remexre (subscriber, #138784) [Link] (1 responses)

I thought that was what the inline keyword "actually means" -- or is that only for C++?

Nolibc: a minimal C-library replacement shipped with the kernel

Posted Feb 1, 2023 13:11 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

`inline` (at least for C++ and AFAIK) is mostly a linking behavior change these days. The optimizer will inline or not as it sees fit anyways. `inline` means that if you do stamp out the full function, don't export a symbol for it. I don't know that the linker can optimize these because it might be different instances of the same function (though looking and seeing that they're the same object code could work I suppose). A weak symbol "exists" and can be exported.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds