-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
Fixes for MIPS binaries #180
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#! /bin/sh -e | ||
|
||
if ! objdump -p main | grep -q MIPS_RLD_MAP_REL; then | ||
echo "No MIPS_RLD_MAP_REL dynamic section entry, skipping" | ||
exit 0 | ||
fi | ||
|
||
SCRATCH=scratch/$(basename $0 .sh) | ||
|
||
rm -rf ${SCRATCH} | ||
mkdir -p ${SCRATCH} | ||
mkdir -p ${SCRATCH}/libsA | ||
mkdir -p ${SCRATCH}/libsB | ||
|
||
cp main ${SCRATCH}/ | ||
cp libfoo.so ${SCRATCH}/libsA/ | ||
cp libbar.so ${SCRATCH}/libsB/ | ||
|
||
# break the main executable by removing .rld_map section | ||
objcopy --remove-section .rld_map ${SCRATCH}/main | ||
|
||
oldRPath=$(../src/patchelf --print-rpath ${SCRATCH}/main) | ||
if test -z "$oldRPath"; then oldRPath="/oops"; fi | ||
../src/patchelf --force-rpath --set-rpath $oldRPath:$(pwd)/${SCRATCH}/libsA:$(pwd)/${SCRATCH}/libsB ${SCRATCH}/main | ||
|
||
if test "$(uname)" = FreeBSD; then | ||
export LD_LIBRARY_PATH=$(pwd)/${SCRATCH}/libsB | ||
fi | ||
|
||
exitCode=0 | ||
|
||
(cd ${SCRATCH} && ./main) || exitCode=$? | ||
|
||
if test "$exitCode" != 46; then | ||
echo "bad exit code!" | ||
exit 1 | ||
fi |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the
.rld_map
section be stripped just likeDT_JMPREL
orDT_REL
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I am asking is, is it possible to that someone has binaries where this section was stripped.
I fixed a similar issue here: #296
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mic92, thank you for the review.
I understood what you're asking, and I need to give it some thought and run a couple of experiments.
I used to believe that elf with
DT_MIPS_RLD_MAP_REL
in dynamic section but without.rld_map
is simply broken, but maybe patchelf needs to handle such files. If that's the case, I'll update the code here and add a test for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, elf file with
DT_MIPS_RLD_MAP_REL
in dynamic section but without.rld_map
is indeed broken: dynamic loader (I've checked glibc 2.32) just writes the debug pointer to the address it calculates fromDT_MIPS_RLD_MAP_REL
entry. I guess no tool produces such binaries.But when I just removed
.rtld_map
section withobjcopy
, the resulting binaries mostly worked -- out of sheer luck probably, but still most of them did not crash.So I rewrote the code to handle such case. Removing
DT_MIPS_RLD_MAP_REL
might have been a cleaner solution, butpatchelf
does not remove any dynamic section entries yet and I don't think supporting binaries that were broken in the fist place worth the burden of starting to do so.And @Mic92, thank you for pointing this case out.