acid/firmware2/libxkbcommon-redefine-syms.sh

25 lines
902 B
Bash
Raw Permalink Normal View History

2026-01-11 22:37:17 +01:00
#!/usr/bin/env bash
2026-01-05 04:16:08 +01:00
INPUT_LIB=$1
OUTPUT_LIB=$2
PREFIX="__xkbc_"
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <input_lib.a> <output_lib.a>"
exit 1
fi
echo "Redefining symbols from $INPUT_LIB into $OUTPUT_LIB..."
xtensa-esp-elf-objcopy --redefine-syms=<(
2026-01-11 22:37:17 +01:00
# Perform set subtraction of undefined symbols and defined symbols, to get globally undefined symbols.
2026-01-05 04:16:08 +01:00
comm -23 \
2026-01-11 22:37:17 +01:00
<(xtensa-esp-elf-nm --undefined-only "$INPUT_LIB" | awk '{print $NF}' | sort -u) \
2026-01-05 04:16:08 +01:00
<(xtensa-esp-elf-nm --defined-only "$INPUT_LIB" | awk '{print $NF}' | sort -u) | \
2026-01-11 22:37:17 +01:00
# Do not prefix already prefixed symbols (idempotency)
grep -v "^${PREFIX}" | \
# Print each symbol followed by the symbol with the prefix
awk -v p="$PREFIX" '{print $1 " " p $1}'
2026-01-05 04:16:08 +01:00
) "$INPUT_LIB" "$OUTPUT_LIB"
2026-01-11 22:37:17 +01:00
echo "Prefixed all externally linked symbols in $INPUT_LIB with $PREFIX, and written the result to: $OUTPUT_LIB"