1#!/bin/sh 2 3# program 4# <- liba.so 5# <- libb.so 6# <- libd.so 7# 8# Expected: dlsym(RTLD_NEXT) finds symbol in order liba.so, libb.so, libd.so 9 10 11. ./test_setup 12 13 14# create libd.so 15cat > libd.c << EOI 16int a() { return 1; } 17EOI 18 19# build 20compile_lib -o libd.so libd.c 21 22 23# create libb.so 24cat > libb.c << EOI 25#define __USE_GNU 26#include <dlfcn.h> 27int 28a() 29{ 30 int (*nextA)(); 31 *(void**)&nextA = dlsym(RTLD_NEXT, "a"); 32 return (nextA != 0 ? nextA() : 0) + 2; 33} 34EOI 35 36# build 37compile_lib_dl -o libb.so libb.c ./libd.so 38 39 40# create liba.so 41cat > liba.c << EOI 42#include <dlfcn.h> 43int 44a() 45{ 46 int (*nextA)(); 47 *(void**)&nextA = dlsym(RTLD_NEXT, "a"); 48 return (nextA != 0 ? nextA() : 0) + 4; 49} 50EOI 51 52# build 53compile_lib_dl -o liba.so liba.c ./libb.so 54 55 56# create program 57cat > program.c << EOI 58 59#include <dlfcn.h> 60int 61a() 62{ 63 int (*nextA)(); 64 *(void**)&nextA = dlsym(RTLD_NEXT, "a"); 65 return (nextA != 0 ? nextA() : 0) + 8; 66} 67 68int 69main() 70{ 71 return a(); 72} 73EOI 74 75# build 76compile_program_dl -o program program.c ./liba.so 77 78# run 79test_run_ok ./program 15 80 81