Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect polarity on dyn_offset; closes #364 #365

Merged
merged 1 commit into from Feb 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/patchelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
if (shdr) {
auto rld_map_addr = findSectionHeader(".rld_map").sh_addr;
auto dyn_offset = ((char*)dyn) - ((char*)dyn_table);
dyn->d_un.d_ptr = rld_map_addr + dyn_offset - (*shdrDynamic).get().sh_addr;
dyn->d_un.d_ptr = rld_map_addr - dyn_offset - (*shdrDynamic).get().sh_addr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the user of this pointer does dyn->d_un.d_ptr + &dyn->d_un.d_ptr to compute the debug pointer location?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the user of this pointer does dyn->d_un.d_ptr + &dyn->d_un.d_ptr to compute the debug pointer location?

I'd say, it's dyn + dyn->d_un.d_ptr. Here is, for example, the relevant part of the glibc's elf loader code (sysdeps/mips/dl-machine.h):

char *ptr = (char *)(l)->l_info[DT_MIPS (RLD_MAP_REL)]; \
ptr += (l)->l_info[DT_MIPS (RLD_MAP_REL)]->d_un.d_val; \

} else {
/* ELF file with DT_MIPS_RLD_MAP_REL but without .rld_map
is broken, and it's not our job to fix it; yet, we have
Expand Down