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
lld sets x86_64 MAXPAGESIZE to 0x1000, not 0x200000 as ld.bfd does #30239
Comments
From the description it looks like the linker script should just say kernphys = 0x200000; or maybe kernphys = 0xa0000 Since it is not really trying to reason about the page size. It is trying to make sure there is some free memory before the kernel. |
It's actually trying to do both - a driver panics if there is no low (below 640K) memory available which happens as a side effect of kernphys = 0x1000, but the reason it's currently MAXPAGESIZE is so that the kernel physical address is large-page aligned. |
Related FreeBSD bug for the driver panic: https://bugs.freebsd.org/214718 |
Some discussion in https://reviews.llvm.org/D24987 and in the review thread on llvm-commits (some of which seems to be missing from the archives) Linking a "hello world" with one int in .data using default ld 2.17.50 settings on FreeBSD gives me (omitting PHDR, INTERP, DYNAMIC, etc. sections): Type Offset VirtAddr PhysAddr With ld.bfd from the binutils package, 2.25.1: LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 With ld.gold 2.25.1: LOAD 0x0000000000000000 0x0000000000400000 0x0000000000400000 With ld.lld HEAD: LOAD 0x0000000000000000 0x0000000000010000 0x0000000000010000 |
So both use a 2MB page, merge read and executable sections and overlap PT_LOAD.
Same as bfd, but with a 4k page. You can get the 3 LOADs with --rosegment.
4k pages, --rosegment, don't overlap segments. |
Interesting: the PT_LOAD overlaps on disk, but the run-time page permissions are applied on a 4K page boundary. PID START END PRT RES PRES REF SHD FL TP PATH
The net result ends up the same though, some overlapping content and 4K run-time permissions. 22108 0x400000 0x401000 r-x 1 0 1 0 C--- vn /home/emaste/a.out
Do you know if ld.gold defaults to enabling this on Linux, out of curiosity? |
Proposed FreeBSD change is in https://reviews.freebsd.org/D8610 |
Looks 2MiB to me, no?
It does not. |
I mean they are aligned to 2MiB from ld.bfd's MAXPAGESIZE, but are 4KiB runtime mappings (END-START), and they have the same content. |
Extended Description
FreeBSD's amd64 (x86_64) kernel linker script uses MAXPAGESIZE to set the physical and virtual addresses for the kernel.
See https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?annotate=303442#l9
After r282560 (https://reviews.llvm.org/rL282560) lld sets MAXPAGESIZE to 0x1000 not 0x200000. The FreeBSD kernel then occupies the physical memory under 640K and the kernel panics on boot when a device that requires a low memory allocation fails.
The text was updated successfully, but these errors were encountered: