Last active
December 20, 2015 00:48
-
-
Save alexanderkjeldaas/6043997 to your computer and use it in GitHub Desktop.
Proof of concept:Combine _info symbols split by ghc back into larger object files.
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
#!/bin/bash | |
# Find which object split includes a given definition | |
findobj () { | |
for a in ${1}_p_o_split.new/*.p_o; do | |
if nm $a | grep --color=auto -q " T $2"; then | |
echo $a; | |
break; | |
fi; | |
done | |
} | |
# Given an "...X_info" symbol, list the other | |
# ...X1_info | |
# ...X2_info etc symbols | |
otherobjs () { | |
nm $1.p_o | grep " T ${2%_info}[0-9]\+_info" | cut -d' ' -f3 | |
} | |
combine () { | |
# echo "# Looking at $2" | |
OTHER=$(otherobjs $1 $2) | |
if [ -z "$OTHER" ]; then | |
# echo "# Nah, didn't find anything" | |
return | |
fi | |
F="" | |
for a in $OTHER; do | |
F="$F `findobj $1 $a`"; | |
done | |
MAIN=$(findobj $1 $2) | |
echo ld -r $F $MAIN -o $MAIN.new.o | |
ld -r $F $MAIN -o $MAIN.new.o | |
echo rm $F $MAIN | |
rm $F $MAIN | |
echo mv $MAIN.new.o $MAIN | |
mv $MAIN.new.o $MAIN | |
} | |
if [ ! -f $UNSPLIT ]; then | |
echo "First argument should be the module name. Can't find $UNSPLIT" | |
fi | |
if [ ! -d $SPLITDIR ]; then | |
echo "Can't find $SPLITDIR. You must run ghc with --split-dirs" | |
fi | |
UNSPLIT=${1}.p_o | |
SPLITDIR=${1}_p_o_split | |
NEWSPLITDIR=${1}_p_o_split.new | |
echo "# Removing $NEWSPLITDIR" | |
rm -rf $NEWSPLITDIR | |
mkdir -p $NEWSPLITDIR | |
cp $SPLITDIR/* $NEWSPLITDIR/ | |
# List the main symbols ending in _info | |
infos () { | |
nm $1.p_o | grep ' T .*[^0-9]_info' | |
} | |
infos $1 | while read a b c; do | |
combine $1 $c | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment