On 5/25/26 8:44 AM, Paul Floyd via Valgrind-users wrote:

   [snip]

(older versions of Valgrind used a fixed address, we had a patch submission to make it like the above with a floating address for the mmap using 0 as the base advisory, I didn't know what to do for mips64 so I left that alone).

It looks like this value only gets recorded on Solaris

#     if defined(VGO_solaris)
       /* Record for later use in AT_BASE. */
       info->interp_offset = ebase;
#     endif

When the mmap is done the information will also be recorded in the nsegments - that is how Valgrind will access it. That's just info about a block of memory, you can't easily tell that it is the guest exe.

The right way to map a -pie executable into memory is:

   1. Compute the size in bytes of the convex hull of the PT_LOADs:
      the minimum interval of pages which covers all PT_LOADs.
   2. Call  addr = mmap(0, byte_size_of_convex_hull, PROT_NONE,
        MAP_ANONYMOUS, -1, 0);
      which reserves enough address space to hold all those PT_LOADs
      at appropriate addresses.
   3. Save 'addr' as ElfXX_auxv_t{AT_BASE}.  The auxv is located
      after the array of pointers to shell environment variables.
   4. Using 'addr' as the base address, then  iterate over the PT_LOADs,
      using the appropriate (addr + ElfXX_Phdr.p_vaddr), actual
      protections, (MAP_FIXED | flags), fd, offset.
   5. If the -pie specifies a PT_INTERP, then map it into the same
      process just like another -pie, including changing AT_BASE
      to point to the interpreter.
   6. Of course, the return value from each system call must be checked
      for errors.

It is incorrect for valgrind to assume any particular numerical address
for the first mapping.  The OS kernel is free to pick whatever address
it likes (unless you specify MAP_FIXED for the entire convex hull; but
this is evil and prone to failure), subject only that the whole convex
hull must fit into the address space.  In particular, the kernel may
choose some other address even if the one you picked is available.

--



_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to