On Fri, Oct 2, 2026 at 3:37 PM Hakan Candar <[email protected]> wrote:
> On Friday, 2 October 2026 at 15:15, Sergey Bugaev <[email protected]> wrote:
> > some memory read/write primitive. You can search for KASR (e.g. in
> > Linux and XNU) online.

Typo: I mean KASLR, kernel address space layout randomization. That
involves more than PIC -- it's also about kernel stacks and heap(s) --
but PIC is an essential part of it.

> It makes sense to me, with these in mind, I think the port should aim
> to support the PIC image eventually. I will take a look at the matter.
>
> If it turns out to be a trivial fix indeed, I have no objections to
> re-enable PIC support right away. If it turns out to be a fairly involved
> change, then I will hold off on that a bit because it is not my first
> priority at the moment. I am just speculating though, I can't know for
> certain what it'll require before I sit down and do the actual work.

Sure, understood.

> Also, I must mention that we compile with mcmodel=medany, and pretty
> much every dereference is made PC-relative, save for pointers stored in
> statically initialized file-scope/global variables.

Yes, and those you can fairly simply relocate yourself (once you
switch to high memory). You might have seen my
'apply_runtime_relocations', that's all there is to it.

> We still assume
> a kernel placed at KERNEL_MAP_BASE though, our paging implementation
> makes use of that assumption currently.
>
> This raises another question, who is going to patch GOT entries if we
> enable -fPIC? How does your port do this -- do you patch dynamic
> relocations during early kernel init?

I don't think you should have a GOT in the first place. GOT is useful
in two cases:
* referencing symbols from another DSO
* ifuncs

But GNU Mach is its own statically linked "DSO", there is no other DSO
to reference, and we're not using ifuncs. So you should always be
doing PC-relative accesses, and there should not be any need for a
GOT.

For AArch64, I had

AM_CFLAGS += -static-pie -mcmodel=tiny -mgeneral-regs-only
gnumach_LINKFLAGS += -T '$(srcdir)'/aarch64/ldscript -static -pie
--no-dynamic-linker

and that seems to have been enough. Alternatively, look into
-fvisibility=hidden. In manually written assembly code, make sure
you're not using any GOT-producing relocation types.

Sergey

Reply via email to