#!/bin/sh
# Bug #1155708: load a shared libLLVM privately (as a Vulkan driver's dependencies are) into a
# process with and without libtorch, call into it, and exit. Core dumps off.
set -e; cd "$(dirname "$0")"; ulimit -c 0
gcc -O1 -o dup-plain dup.c
gcc -O1 -o dup-torch dup.c -Wl,--no-as-needed -ltorch_cpu -lc10 -Wl,--as-needed
for prog in dup-plain dup-torch; do for lib in libLLVM.so.23.1 libLLVM.so.22.1; do
  printf '%s + %s: ' "$prog" "$lib"; ./$prog $lib >/dev/null 2>err.txt && echo "exit 0" || echo "exit $? ($(tail -1 err.txt))"
done; done; rm -f err.txt
