check-abi-compatibility.sh 1.7 KB

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