builtools: Make abi_gen.sh less prone to errors
authorAndreas Schneider <asn@samba.org>
Mon, 14 Feb 2022 06:59:52 +0000 (07:59 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 15 Feb 2022 11:35:31 +0000 (11:35 +0000)
The mold linker has more hidden symbols and we would need to filter them out
with nm, where objdump tells us which symbols are actually hidden. So we just
need to filter out whatever is hidden.

The use of awk makes it also easier to get what we want.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
buildtools/scripts/abi_gen.sh

index 6dd6d321f7756895c63f2c41886ca908962f5236..ddb0a7cc36fd11936e5176c02b25f23b148d86b2 100755 (executable)
@@ -10,9 +10,14 @@ cat <<EOF
 set height 0
 set width 0
 EOF
-nm "$SHAREDLIB" | cut -d' ' -f2- | egrep '^[BDGTRVWS]' | grep -v @ | egrep -v ' (__bss_start|_edata|_init|_fini|_end)' | cut -c3- | sort | while read s; do
+
+# On older linker versions _init|_fini symbols are not hidden.
+objdump --dynamic-syms "${SHAREDLIB}" | \
+    awk '$0 !~ /.hidden/ {if ($2 == "g" && $3 ~ /D(F|O)/ && $4 ~ /(.bss|.rodata|.text)/) print $NF}' | \
+    sort | \
+    while read -r s; do
     echo "echo $s: "
-    echo p $s
+    echo p "${s}"
 done
 ) > $GDBSCRIPT