|
| 1 | +#!/bin/bash |
| 2 | +# Check for unversioned symbols in libraries |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +# Function to check if a library has versioned symbols |
| 7 | +has_versioned_symbols() { |
| 8 | + local lib=$1 |
| 9 | + # Check if the library has version definitions |
| 10 | + if readelf -V "$lib" 2>/dev/null | grep -q "Version definition section"; then |
| 11 | + return 0 |
| 12 | + else |
| 13 | + return 1 |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +# Function to get unversioned symbols from a library |
| 18 | +get_unversioned_symbols() { |
| 19 | + local lib=$1 |
| 20 | + objdump -T "$lib" | \ |
| 21 | + grep -F .text | \ |
| 22 | + awk '{if($6=="Base") {print $7;}}' | \ |
| 23 | + c++filt | \ |
| 24 | + awk '/[() ]/ {print " \"" $0 "\";";} |
| 25 | + !/[() ]/ {print " " $0 ";";}' | \ |
| 26 | + sort |
| 27 | +} |
| 28 | + |
| 29 | +# Libraries to check |
| 30 | +LIBRARIES=( |
| 31 | + "lib/.libs/libaudit.so" |
| 32 | + "auparse/.libs/libauparse.so" |
| 33 | + "auplugin/.libs/libauplugin.so" |
| 34 | +) |
| 35 | + |
| 36 | +echo "Checking for versioned symbols in built libraries..." |
| 37 | + |
| 38 | +# Track if any library uses versioned symbols |
| 39 | +has_versioned=0 |
| 40 | +# Track if we found any unversioned symbols |
| 41 | +found_unversioned=0 |
| 42 | + |
| 43 | +for lib in "${LIBRARIES[@]}"; do |
| 44 | + if [ ! -f "$lib" ]; then |
| 45 | + echo "Warning: Library $lib not found, skipping..." |
| 46 | + continue |
| 47 | + fi |
| 48 | + |
| 49 | + if has_versioned_symbols "$lib"; then |
| 50 | + echo "- Library $lib has versioned symbols" |
| 51 | + has_versioned=1 |
| 52 | + |
| 53 | + # Check for unversioned symbols |
| 54 | + unversioned=$(get_unversioned_symbols "$lib") |
| 55 | + if [ -n "$unversioned" ]; then |
| 56 | + echo "ERROR: Found unversioned symbols in $lib:" |
| 57 | + echo "$unversioned" |
| 58 | + found_unversioned=1 |
| 59 | + else |
| 60 | + echo " No unversioned symbols found" |
| 61 | + fi |
| 62 | + else |
| 63 | + echo "- Library $lib does not have versioned symbols (version script not applied)" |
| 64 | + fi |
| 65 | + echo |
| 66 | +done |
| 67 | + |
| 68 | +if [ $has_versioned -eq 0 ]; then |
| 69 | + echo "No libraries with versioned symbols were found." |
| 70 | + echo "This is expected if the linker does not support version scripts." |
| 71 | + exit 0 |
| 72 | +fi |
| 73 | + |
| 74 | +if [ $found_unversioned -eq 1 ]; then |
| 75 | + echo "FAIL: Unversioned symbols were found in libraries with version scripts!" |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +echo "SUCCESS: All libraries with versioned symbols have all symbols properly versioned." |
| 80 | +exit 0 |
0 commit comments