Use elfwrap :-)

This commit is contained in:
Igor Pashev 2012-11-28 21:46:19 +00:00
parent 7738020554
commit e3d00d4584
2 changed files with 105 additions and 0 deletions

101
uts/debian/elfwrap Executable file
View File

@ -0,0 +1,101 @@
#!/bin/sh
set -e
set -u
# Default output file name:
outputfile="a.wrap.o"
# --32 or --64. Empty by default. To pass to GNU as.
bitness=""
# Print assembler source code to stdout
# instead of compiling to ELF object
show_source="no"
fatal () {
echo "$0: $@" >&2
echo "$0: Type \`$0 -h' to get help" >&2
exit 2
}
usage () {
echo "$0 [ -64 | -32 ] [ -o outputfile ] [ -s ] files ..."
exit 1
}
files=""
collect() {
files="$files$1|"
}
processing_options="yes"
while [ $# != 0 ]; do
opt="$1"
shift
if [ "$processing_options" = yes ]; then
case "$opt" in
--)
processing_options="no"
;;
-s)
show_source="yes"
;;
-h|--help)
usage
;;
-32|--32)
bitness="--32"
;;
-64|--64)
bitness="--64"
;;
-o)
[ $# != 0 ] || fatal "Option -o requires an argument"
outputfile="$1"
shift
;;
-*)
fatal "Invalid option: $opt"
;;
*)
collect "$opt"
;;
esac
else
collect "$opt"
fi
done
if [ -z "$files" ]; then
fatal "No files given."
fi
(
IFS='|'
set -- $files
for f in "$@"; do
base=`basename -- "$f" | sed -e 's,[^0-9a-zA-Z_],_,g' -e 's,^\([0-9]\),_\1,'`
echo ".section .${base}, \"a\", @progbits"
echo ".global ${base}_start"
echo ".global ${base}_end"
echo ".type ${base}_start, @object"
echo ".type ${base}_end, @object"
echo "${base}_start:"
echo ".incbin \"$f\""
echo "${base}_end:"
echo
done
) | (
if [ "$show_source" = yes ]; then
cat
else
as $bitness -o "$outputfile" --
fi
)
exit 0

View File

@ -11,6 +11,10 @@ unpack-stamp:
dh_illumos_gate --build \
usr/src/uts \
usr/src/common
# this a shell script generating assembler source files
# and passing that source to as.
# Default output format is expected to be 32-bit:
echo "export ELFWRAP='$(CURDIR)/debian/elfwrap -32'" >> usr/env.sh
touch $@
patch: patch-stamp