File indexing completed on 2024-04-21 05:41:33

0001 #!/bin/bash
0002 
0003 input_file=$(readlink -f test_linkage.c)
0004 cd /tmp
0005 
0006 function run {
0007   echo "compiling with $@"
0008   gcc $@ -O0 -g $input_file -o test_linkage || return
0009   readelf -a test_linkage | grep free
0010   ./test_linkage &
0011   p=$!
0012   sleep .1
0013   heaptrack -p $p |& tee test_linkage.log
0014   if ! grep -qP "^\s+allocations:\s+10$" test_linkage.log; then
0015     echo "FAILED: wrong allocation count (compiled with $@)"
0016   fi
0017   if ! grep -qP "^\s+leaked allocations:\s+0$" test_linkage.log; then
0018     echo "FAILED: wrong allocation count (compiled with $@)"
0019   fi
0020   if ! grep -qP "^\s+temporary allocations:\s+10$" test_linkage.log; then
0021     echo "FAILED: wrong temporary allocation count (compiled with $@)"
0022   fi
0023 }
0024 
0025 # set -o xtrace
0026 
0027 for linker in bfd gold; do
0028     run -fuse-ld=$linker
0029     run -fuse-ld=$linker -Wl,-z,now
0030     run -fuse-ld=$linker -DTAKE_ADDR
0031     run -fuse-ld=$linker -DUSE_FREEPTR
0032 done
0033 
0034 rm heaptrack.test_linkage.*.gz test_linkage test_linkage.log