3bbb927728
This change adds support for specifying a build ID for kernel modules. This is done by setting PKG_BUILD_ID to a hexadecimal string, which will then be passed to the kernel linker. In addition, when this flag is set, the build ID debug symbol (.note.gnu.build-id) will not be stripped from the kernel module. This symbol is exported in sysfs by the kernel (if the kernel is compiled with CONFIG_KALLSYMS) and so can be used to uniquely identify a version of a kernel module in a running kernel. This is useful for keeping track of different versions of a module when doing experiments and development. Modules that specify the build ID will be ~100 bytes larger (depending on the length of the build ID specified). There is no size difference for kernel modules that do not set this variable. Signed-off-by: Toke Høiland-Jørgensen <toke@toke.dk> SVN-Revision: 47290
54 lines
892 B
Bash
Executable File
54 lines
892 B
Bash
Executable File
#!/usr/bin/env bash
|
|
[ -n "$CROSS" ] || {
|
|
echo "The variable CROSS must be set to point to the cross-compiler prefix"
|
|
exit 1
|
|
}
|
|
|
|
MODULE="$1"
|
|
|
|
[ "$#" -ne 1 ] && {
|
|
echo "Usage: $0 <module>"
|
|
exit 1
|
|
}
|
|
|
|
ARGS=
|
|
if [ -n "$KEEP_SYMBOLS" ]; then
|
|
ARGS="-X --strip-debug"
|
|
else
|
|
ARGS="-x -G __this_module --strip-unneeded"
|
|
fi
|
|
|
|
if [ -z "$KEEP_BUILD_ID" ]; then
|
|
ARGS="$ARGS -R .note.gnu.build-id"
|
|
fi
|
|
|
|
${CROSS}objcopy \
|
|
-R .comment \
|
|
-R .pdr \
|
|
-R .mdebug.abi32 \
|
|
-R .gnu.attributes \
|
|
-R .reginfo \
|
|
$ARGS \
|
|
"$MODULE" "$MODULE.tmp"
|
|
|
|
[ -n "$NO_RENAME" ] && {
|
|
mv "${MODULE}.tmp" "$MODULE"
|
|
exit 0
|
|
}
|
|
|
|
${CROSS}nm "$MODULE.tmp" | awk '
|
|
BEGIN {
|
|
n = 0
|
|
}
|
|
|
|
$3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
|
|
print "--redefine-sym "$3"=_"n;
|
|
n = n + 1
|
|
def[$3] = 1
|
|
}
|
|
' > "$MODULE.tmp1"
|
|
|
|
${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
|
|
mv "${MODULE}.out" "${MODULE}"
|
|
rm -f "${MODULE}".t*
|