Page MenuHomeFreeBSD

i386: Link kernel against libcompiler_rt when using GCC.
AbandonedPublic

Authored by jhb on Jun 30 2023, 4:44 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jun 4 2024, 1:35 AM
Unknown Object (File)
May 2 2024, 3:00 PM
Unknown Object (File)
May 2 2024, 3:00 PM
Unknown Object (File)
May 2 2024, 1:21 PM
Unknown Object (File)
Mar 15 2024, 1:11 AM
Unknown Object (File)
Mar 14 2024, 5:28 AM
Unknown Object (File)
Feb 13 2024, 2:45 AM
Unknown Object (File)
Jan 29 2024, 4:45 AM
Subscribers

Details

Reviewers
kib
markj
Summary

This provides additional compiler builtins divmoddi4, udivmoddi4,
and __floatundidf required by GCC.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 52365
Build 49256: arc lint + arc unit

Event Timeline

jhb requested review of this revision.Jun 30 2023, 4:44 PM

This change combined with the previous two in the stack are enough to build and link an i386 kernel with GCC 12. (World already builds.)

sys/conf/Makefile.i386
37

A bare /usr/lib? Isn't there some symbol for this? And doesn't this pollute the kernel build with whatever is on the host? We've often put things like this in libkern.a to avoid this issue.

sys/conf/Makefile.i386
37

The = means "use sysroot", so =/usr/lib is not the same thing as /usr/lib. I don't think we have macros anywhere for the string "/usr/lib". It's hardcoded that way in ldscripts, compiler sources, etc. Normally your compiler driver passes it, but we still link the kernel with ld rather than cc.

We don't currently have libkern variants of these builtins, and I wasn't sure if it was worth adding them just for i386 kernels built with GCC (I'm also not even sure what these builtins do). For rtld we linked with libcompiler_rt as well. The root issue being that clang is happy to generate a short sequence of instructions for certain operations whereas GCC always wants to call out to an intrinsic.

sys/conf/Makefile.i386
37

Humm, so divmoddi4 and udivmoddi4 are in fact not too hard, they are just like [u]divdi3 except they also return the remainder.

__floatundidf is more of a pain. It needs to convert a quad to a double. It turns out there's one place in the kernel we are using floating point (sys/kern/subr_clockcalib.c) and GCC emits calls to this for the conversions from uint64_t to double. :(

sys/conf/Makefile.i386
37

Humm, so using -std=gnu99 instead of -std=c99 (see D40646) eliminates the __floatundidf. GCC was still using floating point instructions for math (so not full-on soft-float), it was just using the intrinsic for conversions when using -std=c99. I have no idea why.

I have created D40817 to add [u]divmoddi4, and together with D40646 those supplant this review.