Bug 11440 - attach to PIE from valgrind if ld.so is unprelinked
Summary: attach to PIE from valgrind if ld.so is unprelinked
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: unknown
: P3 minor
Target Milestone: 7.1
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2010-03-29 13:51 UTC by Jan Kratochvil
Modified: 2010-03-29 13:51 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2010-03-29 13:51:34 UTC
This is a tracker for:

--db-command should support %{auxv address}


valgrind --db-attach pie-executable
does not currently work if /lib64/ld*.so is not prelinked.

FSF GDB support for PIE (Position Independent Executable; built using -fPIE
-pie) debugging has been checked-in to CVS HEAD (->gdb-7.1):

It currently works for all these cases (simplified):
gdb -p normal-executable
gdb -p pie-executable-prelinked
gdb -p pie-executable-unprelinked
valgrind --db-attach normal-executable
valgrind --db-attach pie-executable-prelinked-only-if-ld.so-is-prelinked
valgrind --db-attach pie-executable-unprelinked-only-if-ld.so-is-prelinked

It does not work for:
valgrind --db-attach pie-executable-prelinked-only-if-ld.so-is-unprelinked
valgrind --db-attach pie-executable-unprelinked-only-if-ld.so-is-unprelinked

GDB generally wants to know AUXV of the debugged process.  With AUXV and its
AT_ENTRY value it can find the executable offset and relocate its symbols for

Normally /proc/PID/auxv is read to find the AUXV content.  But with valgrind it
does not match, therefore for attachments it rather uses "_dl_auxv" (located in
ld.so).  GDB cannot use backtrace from main to _start to find the
valgrind-modified auxv there as the initial thread may have exited (+it would
be too fragile anyway).

But to locate "_dl_auxv" we need relocated symbols for ld.so which is a
chicked-and-egg problem.  DT_DEBUG
is in the main executable (which would point us at ld.so load address) but we
need AUXV to find out how to relocate symbols for the PIE main executable.

Therefore we known neither the main executable offset (as it is PIE) and
therefore neither DT_DEBUG and therefore neither ld.so offset (as it is PIC and
not prelinked loaded at arbitrary address) and therefore neither "_dl_auxv"
offset and /proc/PID/auxv is invalid with valgrind attachments.  There is
everything floating.

Therefore suggesting to create besides %f and %p --db-command substitutions
also some %a producing string "0x7fffffffd7e0" which would correspond to
"the_iifii.client_auxv" (or where is the AUXV address stored).  GDB will get
corresponding "--auxv" commandline option / CLI setting.  Thanks.