[PATCH] mtrace: Fix output with PIE and ASLR [BZ #22716]
Siddhesh Poyarekar
siddhesh@sourceware.org
Thu Jul 22 15:17:28 GMT 2021
On 7/22/21 8:15 PM, John Ogness wrote:
> Thank you for the clarification. I forgot about non-pie. But then it
> means we are always interested in l_addr. l_map_start is irrelevant.
Not really. The end result we want is an address that points to the
correct symbol in the ELF binary. We may think of that address as the
ELF base address and the offset of the symbol from the base because
regardless of whether the object is relocatable or not, the offset of
the symbol will be constant from the base.
We get the offset of the symbol from base in the MALLOC_TRACE run; I
have modified the output to be the offset instead of the actual address
because for relocatable objects the actual address is practically
useless across multiple runs.
In the second run (i.e. prelinking trace), we want to compute the ELF
base address. We have l_map_start (which is the actual base address in
memory) and l_addr (which is l_map_start - ELF base address). So the
ELF base address is clearly l_map_start - l_addr.
Finally we get the symbol address as ELF base + offset recorded in the
trace.
>> So the (l_addr - l_map_start) is 0 for PIC and PIE, but not for non-pie
>> executables. Adding that relative offset in the binary for addr2line
>> will give you the correct symbol in both pic/pie and non-pie cases.
>
> OK, but settings MALLOC_TRACE will cause the memory addresses to be
> stored. So it is l_addr that must be subtracted for addr2line.
My patch updates the dump to be that of the offset from base and not the
actual address, which is why all of this works.
Siddhesh
More information about the Libc-alpha
mailing list