On 10/13/2026 7:53 AM, Richard Henderson wrote:
>
>> FreeBSD can't link static PIE, so qemu-*-static is always linked at
>> 0x200000.
>
> That's unfortunate.  We could explicitly link somewhere high in the address 
> space, perhaps.  E.g.
>
>   -Wl,--image-base,0x80000000000
>
I tried that, but on FreeBSD amd64 it won't link above 2G.

The static libc and crtbeginT.o aren't PIC, so they're full of
R_X86_64_32 and R_X86_64_32S relocations:

  ld: error: /usr/lib/crtbeginT.o:(function __do_global_dtors_aux: .text+0x8):
    relocation R_X86_64_32 out of range: 8796093721768 is not in [0, 4294967295]

  ld: error: /usr/lib/libc.a(libc_start1.o):(function __libc_start1: 
.text+0xb7):
    relocation R_X86_64_32S out of range: 2415920304 is not in [-2147483648, 
2147483647]

0x70000000 works though. I linked qemu-aarch64 there with no other
changes, and guest_base stays 0. ldd on perl and the other packaged
programs I tried work fine with this.

It's not really safe though, it just moves qemu out of the way. A
guest MAP_FIXED can still land on qemu's memory and crash it, even
with a non-zero guest_base, since the heap and code buffer are still
in reach. Maybe target_mmap should refuse that and give the guest an
error instead?

If you want to go with the link address, I can add it to qemu's
meson.build for static non-PIE builds.

Reply via email to