Repository navigation
Fix DT_MIPS_RLD_MAP_REL on --remove-rpath - #645
Merged
Merged
Conversation
removeRpath() uses a simple technique to remove the DT_RPATH/DT_RUNPATH entries from the dynamic section: it removes the elements from the array and moves following tags down. This works well. Mostly, except when the tag DT_MIPS_RLD_MAP_REL appears. This is a unique tag because its value is a relative offset to the tag's address itself. Thus, when moving the tag down, the offset must be patched as well to componsate for that. We observed Bus Errors on certain binaries on our MIPS-based products. I used AI (Claude Sonnet 4.6) to analyze the problem because I'm not a MIPS expert at all. The patch was written by hand once I understood the root cause.-
Contributor
Author
|
@amaanq you might be interested in this one, I saw your other MIPS fix (thanks for that!) |
Member
|
Wow, neat to see other MIPS users out there, and this looks good. I have a comment though. |
amaanq
approved these changes
Jun 20, 2026
Co-authored-by: Amaan Qureshi <[email protected]>
Contributor
Author
|
@edolstra can you please have a look at this "yet another MIPS fix"? |
Member
|
cc @Mic92 |
edolstra
approved these changes
Jun 24, 2026
edolstra
enabled auto-merge
June 24, 2026 20:33
Mic92
added a commit
that referenced
this pull request
Jun 25, 2026
PR #645 fixed --remove-rpath but --remove-needed has the same in-place compaction and the same bug: DT_MIPS_RLD_MAP_REL stores the offset to .rld_map relative to its own .dynamic slot, so when the slot moves the value must be adjusted, and rewriteSections() does not run because no section was replaced. Factor the shared compact-and-adjust loop into compactDynamic() and use it from both callers. The regression test recomputes the loader's invariant from readelf output, so it does not need to execute the binary and runs on any host with a MIPS toolchain.
Mic92
added a commit
that referenced
this pull request
Jun 25, 2026
PR #645 fixed --remove-rpath but --remove-needed has the same in-place compaction and the same bug: DT_MIPS_RLD_MAP_REL stores the offset to .rld_map relative to its own .dynamic slot, so when the slot moves the value must be adjusted, and rewriteSections() does not run because no section was replaced. Factor the shared compact-and-adjust loop into compactDynamic() and use it from both callers. The regression test recomputes the loader's invariant from readelf output, so it does not need to execute the binary and runs on any host with a MIPS toolchain.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem description
removeRpath() uses a simple technique to remove the DT_RPATH/DT_RUNPATH entries from the dynamic section: it removes the elements from the array and moves following tags down.
This works well. Mostly, except when the tag DT_MIPS_RLD_MAP_REL appears. This is a unique tag because its value is a relative offset to the tag's address itself. Thus, when moving the tag down, the offset must be patched as well to componsate for that.
We observed Bus Errors on certain binaries on our MIPS-based products that we could nail down to the introduction of
patchelf --remove-rpathcalls in the build system.I used AI (Claude Sonnet 4.6) to analyze the problem because I'm not a MIPS expert at all. The patch was written by hand once I understood the root cause. Also I could find "prior art" after the fact in other related software like chrpath and cmake (see [1])
References
[1] debian ports