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

fix incorrect polarity on dyn_offset; closes #364 #365

merged 1 commit into from Feb 5, 2022

Conversation

ghost
Copy link

@ghost ghost commented Jan 22, 2022

This fixes #364 and I have verified that --set-interpreter now works correctly on mips64el-linux-gnuabin32.

However --set-rpath is still broken (produces corrupted binaries); fortunately for that task chrpath can be used instead (it works properly).

@Mic92
Copy link
Member

Mic92 commented Jan 22, 2022

cc @iv-m

@@ -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; \

@Mic92
Copy link
Member

Mic92 commented Jan 31, 2022

ping

@iv-m
Copy link
Contributor

iv-m commented Jan 31, 2022

cc @iv-m

Sorry for slow reply, I'm checking this out.

@iv-m
Copy link
Contributor

iv-m commented Jan 31, 2022

This patch is correct -- I checked on my MIPS32 LE system that with this patch applied, both before and after applying patchelf --set-rpath to a test binary, address of .dynamic section, offset of MIPS_RLD_MAP_REL tag in that section and the contents of MIPS_RLD_MAP_REL add up to __RLD_MAP symbol address, as they should (the numbers taken from readelf).

Apparently I screwed up the signs in #180 and did not notice that: on my mipsel system both + and - for dyn_offset produce working binaries -- all tests of the patchelf test suite pass, gdb works on patched binaries, and suchlike. I'm really sorry for not double checking the math back than.

So, please merge this pull request. @a-m-joseph, thanks for fixing this.

@ghost
Copy link
Author

ghost commented Feb 4, 2022

@a-m-joseph, thanks for fixing this.

No problem.

Once this is merged and patchelf makes a release, I would like to upstream all the work I've done on getting nixpkgs to bootstrap on mips64el and mips64el-n32, so it doesn't bitrot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

patchelf still corrupting binaries on mips64el-linux-gnuabin32
2 participants