Skip to content

Fix DT_MIPS_RLD_MAP_REL on --remove-rpath - #645

Merged
edolstra merged 2 commits into
NixOS:masterfrom
tma-fritz:remove_rpath_mips
Jun 24, 2026
Merged

edolstra merged 2 commits into
NixOS:masterfrom
tma-fritz:remove_rpath_mips

Conversation

@tma-fritz

Copy link
Copy Markdown
Contributor

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-rpath calls 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

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.-
@tma-fritz

tma-fritz commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@amaanq you might be interested in this one, I saw your other MIPS fix (thanks for that!)

@tma-fritz tma-fritz changed the title patchelf: fix DT_MIPS_RLD_MAP_REL on --remove-rpath Fix DT_MIPS_RLD_MAP_REL on --remove-rpath Jun 19, 2026
@amaanq

amaanq commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

Wow, neat to see other MIPS users out there, and this looks good. I have a comment though.

Comment thread src/patchelf.cc Resolved
Co-authored-by: Amaan Qureshi <[email protected]>
@tma-fritz

Copy link
Copy Markdown
Contributor Author

@edolstra can you please have a look at this "yet another MIPS fix"?

@domenkozar

Copy link
Copy Markdown
Member

cc @Mic92

@edolstra
edolstra enabled auto-merge June 24, 2026 20:33
@edolstra
edolstra added this pull request to the merge queue Jun 24, 2026
Merged via the queue into NixOS:master with commit bf772b6 Jun 24, 2026
14 checks passed
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.
@domenkozar domenkozar mentioned this pull request Jun 26, 2026
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.

4 participants