This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
'what' and 'mcs' in binutils?
- From: "Nisbach T., DP ITS, SCC, D" <Thomas dot Nisbach at dp-itsolutions dot de>
- To: <binutils at sources dot redhat dot com>
- Date: Thu, 15 Jan 2004 09:35:12 +0100
- Subject: 'what' and 'mcs' in binutils?
Hi,
i am missing the tools 'what' and 'mcs'. Both are
common in the SysV world (e.g. Sun Solaris).
'what' searches an object/binary file for the SCCS
versioning tag '@(#)' and displays the string following.
'mcs' (manipulate comment section) can add/delete/...
arbitrary string to/from the '.comment' section of ELF.
This is useful to add any kind of release
information to an existing binary. 'what' lets you
display this information.
Details can be found on Solaris man pages:
what
====
http://docs.sun.com/db/doc/816-0210/6m6nb7mpv?a=view
mcs
====
http://docs.sun.com/db/doc/816-0210/6m6nb7men?a=view
My question:
=========
Is it intended to implement these commands?
I wrote two bash-scripts to emulate 'mcs -a ...'
and 'what' with the existing binutils tools.
'mcs' will be more complicated if applied to archives (libs).
In this case 'mcs' will be applied to any object-file
contained in the archive.
#!/bin/bash
#
# Emulate 'mcs' (Manipulate Comment Section)
#
# Only 'mcs -a <string> <binary>' is supported.
# Archives (libs) ARE NOT SUPPORTET.
#
# Short description:
# 1) find the position of the '.comment'-section using 'objdump'
# 2) write out the raw '.comment'-section using 'dd'
# (i am missing this option in objdump/objcopy)
# 3) replace (remove/add) the '.comment'-section using 'objcopy'
#
emu_mcs()
{
if [ $# -eq 3 -a "$1" = "-a" ]; then
string="$2"
bin="$3"
size=`objdump --section-headers "$bin" | fgrep .comment | awk '{ print $3 }'`
offset=`objdump --section-headers "$bin" | fgrep .comment | awk '{ print $6 }'`
if [ -n "$size" -a -n "$offset" ]; then
# use bash hex-conversion
size=$((0x$size))
# skip=offset - 1
skip=$((0x$offset - 1))
# temporary file
temp_comment=/tmp/emu_mcs_$$
if [ $size -gt 0 ]; then
dd if="$bin" of="$temp_comment" bs=1 skip=$skip count=$size 2>/dev/null
fi
echo "$string" >> "$temp_comment"
objcopy --remove-section=.comment "$bin"
objcopy --add-section .comment="$temp_comment" "$bin"
rm -f "$temp_comment"
fi
else
echo "Usage: emu_mcs -a <string> <binary>" >&2
return 1
fi
}
# Emulate 'what' (show SCCS version information)
emu_what()
{
# scan all file sections (-a)
strings -a "$1" | sed 's/\(@(#)\)/\n\1/g' | fgrep '@(#)' | cut -c 5-
}
Regards,
Thomas
This email is confidential. If you are not the intended recipient,
you must not disclose or use the information contained in it. If
you have received this mail in error, please tell us immediately
by return email and delete the document.
DP ITSolutions GmbH