New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DynamicLoader+LibC: Link LibC into DynamicLoader --as-sane-people #24129
Conversation
Static libc on Serenity is broken in a more than one way and requires a lot of patches to bring it to a usable and useful state. Therefore, instead of keeping it around (and breaking even more) during the upcoming libc build refactor, let's just delete it.
53b8f19
to
b0bf244
Compare
This is similar to how it is done in sys/arch/regs.h.
b0bf244
to
c807348
Compare
4a2fe43
to
7b1f8da
Compare
I've found a much more elegant solution for only linking required functions from libc. @ADKaster, I think you would love how DynamicLoader/CMakeLists.txt looks now. |
7b1f8da
to
7676581
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me! I do wonder if we could come up with a static list of LibC files or symbols we need for the loader. One concern about your Toolchain change though.
Also, static LibC seems completely removed? How will this affect ports that wanted a fully static LibC? Can/should we add it back? |
Do we have ports that require a static LibC? I don't think so. Even if we have ports that require static compilation somehow, we might just want to get them to use shared libraries like the rest of the system. |
__stack_chk_fail_local, which libssp_nonshared.a provides, is a relic of i386 times and is not used on modern architectures.
LibSystem's source directory is included project-wide in /CMakeLists.txt.
In particular, define a static LibC library *in LibC's CMakeLists* and use it in DynamicLoader. This is similar to the way LibELF is included in DynamicLoader. Additionally, compile DynamicLoader with -ffunction-sections, -fdata-sections, and -Wl,--gc-sections. This brings the loader size from ~2Mb to ~1Mb with debug symbols and from ~500Kb to ~150Kb without. Also, this makes linking DynamicLoader with LibTimeZone unnecessary.
It turns out riscv64 indeed requires -fno-stack-protector for perform_relative_relocations, oopsie :^)
Since DynamicLoader is compiled with -fdata-sections and --gc-sections, unused thread_local variables won't create TLS section in it anymore.
7676581
to
83017c4
Compare
I think this could have worked, if libc's cpp files had had a granularity of functions (like llvm's libc for linux has). But since it doesn't, trying to split a library with a lot of cross-file dependencies into two is just meh. In fact, I originally wanted to do this, and Liav even came up with a not-so-long list of files, but no. If we do that, then every other future libc contribution adding cross-file dependencies would have to figure out how to change these 2 lists. On top of that, it doesn't solve the problem with unnecessary LibTimeZone link by itself, since we need |
This is very false. glibc supports static linking; if it didn't have to, so many things would be easier. You can grep Think of it this way: if glibc didn't support static linking, there is no way the Hurd could boot (well, unless we made this actually work). The first few tasks that get started (the disk driver, the PCI arbiter, the fs server...) just have to be statically linked, since there's no filesystem where the dynamic dependencies could be loaded from. As for actually building static executables with glibc as a user, it's as simple as:
( It's true that static linking is discouraged (so you should not use unless you have a real good reason), and that even the static build of glibc will dlopen NSS/iconv modules if you touch any of the relevant APIs (so: don't touch them until the root filesystem is up). It's not true that glibc doesn't support static linking. |
I know you can pass the Anyway, it's not like we actually care enough about static compilation anyway - I actually see no benefit in our ecosystem for this, except for the fact that you could provide a small rootfs with no dynamic loader, which has no real advantage for anybody here. So it's a non-relevant discussion about the topic, and we should just move on to delete static libc. |
Static libc we "had" didn't even work, it just was there. |
Right. I "fondly" (actually really not) remember me trying to force the |
Even less globs and questionable CMake!
Draft for now since I want to make sure CI is happy before spamming Daniel with emails.