On 2026-05-22 01:57, Mark Roberts wrote:
Reminder: Our Daikon tool set uses Valgrind to allow us to monitor program
execution. We have been telling our clients that the must build their
programs with -no-pie. We would like to remove that restriction. Given an
IRStmt with tag = Ist_IMark, we look at the IMark.addr. With -no-pie this
matches the pc addresses in the DWARF debug info. We would like to know how
to do the mapping in a pie executable. Presumably, we need to add a load
address of some kind. How do we find that?
Hi Mark
Please can you explain a bit more about what Daikon does?
The code that does this in Valgrind is in coregrind/m_ume/elf.c
Function VG_(load_ELF)
/* The kernel maps position-independent executables at TASK_SIZE*2/3;
for us it's good enough to just load it somewhere with enough
free space. */
if (e->e.e_type == ET_DYN && ebase == 0) {
/* We really don't want to load PIEs at zero or too close. It
works, but it's unrobust (NULL pointer reads and writes
become legit, which is really bad) and causes problems for
exp-ptrcheck, which assumes all numbers below 1MB are
nonpointers. So, hackily, move it above 1MB. */
/* Later .. it appears ppc32-linux tries to put [vdso] at 1MB,
which totally screws things up, because nothing else can go
there. The size of [vdso] is around 2 or 3 pages, so bump
the hacky load address along by 8 * VKI_PAGE_SIZE to be safe. */
/* Later .. on mips64 we can't use 0x108000, because mapelf will
fail. */
# if defined(VGP_mips64_linux)
ebase = VG_PGROUNDDN(info->exe_base
+ (info->exe_end - info->exe_base) * 2 / 3);
if (ebase < 0x100000)
ebase = 0x100000;
# else
Bool ok = False;
ebase = VG_(am_get_advisory_client_simple)( 0, e->p->p_filesz, &ok );
if (!ok) {
VG_(printf)( "Cannot find segment large enough to contain %llx
bytes\n", (ULong)e->p->p_filesz );
return VKI_ENOMEM;
}
(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.
A+
Paul
_______________________________________________
Valgrind-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/valgrind-users