2026-01-11 22:37:17 +01:00
|
|
|
#!/usr/bin/env bash
|
2026-01-19 20:13:25 +01:00
|
|
|
PREFIX=$1
|
|
|
|
|
INPUT_LIB=$2
|
|
|
|
|
OUTPUT_LIB=$3
|
2026-01-05 04:16:08 +01:00
|
|
|
|
2026-01-19 20:13:25 +01:00
|
|
|
if [ "$#" -ne 3 ]; then
|
|
|
|
|
echo "Usage: $0 <prefix> <input_lib.a> <output_lib.a>"
|
2026-01-05 04:16:08 +01:00
|
|
|
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"
|