|
| 1 | +#!/bin/bash |
| 2 | +if [ "$#" -ne 2 ]; then |
| 3 | + echo "Usage: $0 old_library.so new_library.so" |
| 4 | + exit 1 |
| 5 | +fi |
| 6 | + |
| 7 | +OLD_LIB=$1 |
| 8 | +NEW_LIB=$2 |
| 9 | + |
| 10 | +OLD_FUNCS=_old_funcs.txt |
| 11 | +NEW_FUNCS=_new_funcs.txt |
| 12 | +OLD_VARS=_old_vars.txt |
| 13 | +NEW_VARS=_new_vars.txt |
| 14 | + |
| 15 | +# Extract function symbols from the old and new libraries |
| 16 | +nm -C --defined-only $OLD_LIB | c++filt | awk '$2 ~ /[TW]/ {print substr($0, index($0,$3))}' | sort > $OLD_FUNCS |
| 17 | +nm -C --defined-only $NEW_LIB | c++filt | awk '$2 ~ /[TW]/ {print substr($0, index($0,$3))}' | sort > $NEW_FUNCS |
| 18 | + |
| 19 | +# Extract variable symbols from the old and new libraries |
| 20 | +nm -C --defined-only $OLD_LIB | c++filt | awk '$2 ~ /[BDG]/ {print substr($0, index($0,$3))}' | sort > $OLD_VARS |
| 21 | +nm -C --defined-only $NEW_LIB | c++filt | awk '$2 ~ /[BDG]/ {print substr($0, index($0,$3))}' | sort > $NEW_VARS |
| 22 | + |
| 23 | +# Initialize error flag and message |
| 24 | +error_flag=0 |
| 25 | +error_message="" |
| 26 | + |
| 27 | +# Check for removed function symbols |
| 28 | +removed_funcs=$(comm -23 $OLD_FUNCS $NEW_FUNCS) |
| 29 | +if [ -n "$removed_funcs" ]; then |
| 30 | + error_flag=1 |
| 31 | + error_message+="[Removed Functions]\n$removed_funcs\n" |
| 32 | +fi |
| 33 | + |
| 34 | +# Check for removed variable symbols |
| 35 | +removed_vars=$(comm -23 $OLD_VARS $NEW_VARS) |
| 36 | +if [ -n "$removed_vars" ]; then |
| 37 | + error_flag=1 |
| 38 | + error_message+="[Removed Variables]\n$removed_vars\n" |
| 39 | +fi |
| 40 | + |
| 41 | +# Check for added variable symbols |
| 42 | +added_vars=$(comm -13 $OLD_VARS $NEW_VARS) |
| 43 | +if [ -n "$added_vars" ]; then |
| 44 | + error_flag=1 |
| 45 | + error_message+="[Added Variables]\n$added_vars\n" |
| 46 | +fi |
| 47 | + |
| 48 | +# Remove temporary files |
| 49 | +rm -f $NEW_FUNCS $OLD_FUNCS $OLD_VARS $NEW_VARS |
| 50 | + |
| 51 | +# Display error messages if any |
| 52 | +if [ "$error_flag" -eq 1 ]; then |
| 53 | + echo -e "$error_message" |
| 54 | + echo "ABI compatibility check failed." |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | + |
| 58 | +echo "ABI compatibility check passed: No variable symbols were removed or added, and no function symbols were removed." |
| 59 | +exit 0 |
0 commit comments