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 20gcc -shared -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 37gcc -shared -o libb.so libb.c -D_GNU_SOURCE ./libd.so $libdl 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 53gcc -shared -o liba.so liba.c -D_GNU_SOURCE ./libb.so $libdl 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 76gcc -o program program.c -D_GNU_SOURCE ./liba.so $libdl \ 77 -Wl,-rpath,.,--export-dynamic 78 79# run 80test_run_ok ./program 15 81 82