Page MenuHomeFreeBSD

Simplify the RISC-V kernel linker invocation
ClosedPublic

Authored by mhorne on Tue, May 19, 1:06 AM.

Details

Summary

Remove our custom SYSTEM_LD definition. This generates program headers
that are more consistent with other architectures, and more importantly,
are in line with what loader(8) expects when loading a kernel.

As noted in https://reviews.freebsd.org/D22920, there is no apparent
reason why the kernel would need a writable text segment, so removal of
the -N flag isn't likely to cause issue.

Test Plan

Compilation succeeds with clang and GCC.

Program header layout before:

Entry point 0xffffffc000000000
There are 4 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flg    Align
  LOAD           0x0000000000001000 0xffffffc000000000 0x0000000080200000
                 0x0000000000751108 0x00000000008706d8  RWE    0x1000
  DYNAMIC        0x0000000000712690 0xffffffc000711690 0x0000000080911690
                 0x00000000000000c0 0x00000000000000c0  RW     0x8
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0
  NOTE           0x0000000000685898 0xffffffc000684898 0x0000000080884898
                 0x0000000000000024 0x0000000000000024  R      0x4

And after:

Entry point 0xffffffc000000000
There are 8 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flg    Align
  INTERP         0x00000000005f0270 0xffffffc0005ef270 0x00000000807ef270
                 0x000000000000000d 0x000000000000000d  R      0x1
      [Requesting program interpreter: /red/herring]
  LOAD           0x0000000000001000 0xffffffc000000000 0x0000000080200000
                 0x000000000068418c 0x000000000068418c  R E    0x1000
  LOAD           0x0000000000686000 0xffffffc000686000 0x0000000080886000
                 0x00000000000ca718 0x00000000000ca718  RW     0x1000
  LOAD           0x0000000000750718 0xffffffc000750718 0x0000000080950718
                 0x000000000000095d 0x000000000011ff40  RW     0x1000
  DYNAMIC        0x0000000000747b78 0xffffffc000747b78 0x0000000080947b78
                 0x00000000000000c0 0x00000000000000c0  RW     0x8
  GNU_RELRO      0x0000000000744c00 0xffffffc000744c00 0x0000000080944c00
                 0x000000000000bb18 0x000000000000bb18  R      0x1
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0
  NOTE           0x0000000000685168 0xffffffc000684168 0x0000000080884168
                 0x0000000000000024 0x0000000000000024  R      0x4

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

mhorne requested review of this revision.Tue, May 19, 1:06 AM
mhorne created this revision.
mhorne edited the test plan for this revision. (Show Details)Tue, May 19, 2:58 PM
kp accepted this revision as: kp.Tue, May 19, 4:50 PM
kp added a subscriber: kp.

Works for me (as in: I've tested this in my setup, and this works just fine).

This revision is now accepted and ready to land.Tue, May 19, 4:50 PM

This should be fine for QEMU. @jrtc27 will this work for our FPGAs?

Yeah they don't need anything special, other than the ability to override KERNEL_LMA, which is kept here.

br accepted this revision.Thu, May 21, 3:03 PM
br added a subscriber: br.

Looks good

This revision was automatically updated to reflect the committed changes.