Skip to content

Commit

Permalink
Check for undefined symbols lanterndata#145
Browse files Browse the repository at this point in the history
  • Loading branch information
var77 committed Sep 18, 2023
1 parent 075b84e commit 3428072
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 deletions.
3 changes: 3 additions & 0 deletions ci/scripts/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ function build_and_install() {
# Run cmake
cmake $flags ..
make install

# Check for undefined symbols
/tmp/lantern/check_symbols.sh ./lantern.so
}

function package_if_necessary() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/check_symbols.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SCRIPT=$(realpath "$0")
THIS_DIR=$(dirname "$SCRIPT")

# get all the symbols our shared library assumes are externally provided
MAYBE_EXTERN=$(nm -u $1 | awk '{print $2}' | sed -e 's/@/@@/')
MAYBE_EXTERN=$(nm -u $1 | awk '{print $2}' | sed -e 's/@/@@/' | sed -n -e 's/@@.*$//p')

# get all the symbols that are externally provided
EXTERN_PROVIDED=$($THIS_DIR/extern_defined.sh)
Expand Down
46 changes: 17 additions & 29 deletions scripts/extern_defined.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,22 @@ IFS=$'\n\t'
# hardcoding their paths
# 3. use platorm specific equivalent of nm, ldd, awk

##
# defined in the postgres binary
nm -D /usr/lib/postgresql/14/bin/postgres | grep " T " | awk '{print $3}'
PG_BIN=$(pg_config --bindir)/postgres

nm -D $PG_BIN | grep " T " | awk '{print $3}'
# global bss symbol in postgres
nm -D /usr/lib/postgresql/14/bin/postgres | grep " B " | awk '{print $3}'
nm -D $PG_BIN | grep " B " | awk '{print $3}'
# postgres weak symbols
nm -D /usr/lib/postgresql/14/bin/postgres | grep " w " | awk '{print $2}'

nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep " T "| awk '{print $3}'
nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep " i "| awk '{print $3}' # for memmove et al
nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep " W "| awk '{print $3}' # for munmap, fread et al

# cpp symbols
nm -D /lib/x86_64-linux-gnu/libstdc++.so.6 | grep " T "| awk '{print $3}' | sed -n -e 's/@@.*$//p'

# for _ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate et all, pulled through usearch
# todo: make sure this is not an indication of an issue
# m " V " - the symbol is a weak object
nm -D /lib/x86_64-linux-gnu/libstdc++.so.6 | grep " V "| awk '{print $3}' | sed -n -e 's/@@.*$//p'
# m " W " - the symbol is a weak symbol that has not been specifically tagged as weak object symbol
nm -D /lib/x86_64-linux-gnu/libstdc++.so.6 | grep " W "| awk '{print $3}' | sed -n -e 's/@@.*$//p'

# for Unwind_Resome
# has @@GCC_3.0 and our version has @GCC_3.0
# but the undefined symbols in our lib are modified with s/@/@@/
nm -D /lib/x86_64-linux-gnu/libgcc_s.so.1 | grep ' T ' | awk '{print $3}'

# add all libm symbols
nm -D /lib/x86_64-linux-gnu/libm.so.6 | grep -v " U " | awk '{print $3}' | sed -n -e 's/@@.*$//p'


nm -D $PG_BIN | grep " w " | awk '{print $2}'

# Get a list of shared library dependencies using ldd
dependencies=$(ldd "$PG_BIN" | awk '{print $3}' | grep -v "not a dynamic executable")

# Loop through the dependencies and extract symbols
for dependency in $dependencies; do
nm -D "$dependency" | awk '/ U / {print $3}' | sed -n -e 's/@@.*$//p'
nm -D "$dependency" | awk '/ i / {print $3}' | sed -n -e 's/@@.*$//p'
nm -D "$dependency" | awk '/ T / {print $3}' | sed -n -e 's/@@.*$//p'
nm -D "$dependency" | awk '/ V / {print $3}' | sed -n -e 's/@@.*$//p'
nm -D "$dependency" | awk '/ W / {print $3}' | sed -n -e 's/@@.*$//p'
done

0 comments on commit 3428072

Please sign in to comment.