1#!/bin/sh 2 3# program 4# 5# dlopen(): 6# liba.so 7# <- libb.so 8# <- libb_dependency.so 9# libd.so 10# libe.so 11# 12# Expected: Undefined symbol in libe.so resolves to symbol in 13# libb_dependency.so, not to symbol in libd.so. 14 15 16. ./test_setup 17 18 19# create libb_dependency.so 20cat > libb_dependency.c << EOI 21int c() { return 1; } 22EOI 23 24# build 25compile_lib -o libb_dependency.so libb_dependency.c 26 27 28# create libb.so 29cat > libb.c << EOI 30int b() { return 1; } 31EOI 32 33# build 34compile_lib -o libb.so libb.c ./libb_dependency.so 35 36 37# create libd.so 38cat > libd.c << EOI 39int c() { return 2; } 40EOI 41 42# build 43compile_lib -o libd.so libd.c 44 45 46# create liba.so 47cat > liba.c << EOI 48extern int c(); 49int e() { return 0; } 50EOI 51 52# build 53compile_lib -o liba.so liba.c ./libb.so 54 55 56# create libe.so 57cat > libe.c << EOI 58extern int c(); 59int a() { return c(); } 60EOI 61 62# build 63compile_lib -o libe.so libe.c 64 65 66# create program 67cat > program.c << EOI 68#include <dlfcn.h> 69#include <stdio.h> 70#include <stdlib.h> 71int 72main() 73{ 74 void* liba; 75 void* libd; 76 void* libe; 77 int (*a)(); 78 79 liba = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL); 80 if (liba == NULL) { 81 fprintf(stderr, "Error opening liba.so: %s\n", dlerror()); 82 exit(117); 83 } 84 85 libd = dlopen("./libd.so", RTLD_NOW | RTLD_GLOBAL); 86 if (libd == NULL) { 87 fprintf(stderr, "Error opening libd.so: %s\n", dlerror()); 88 exit(117); 89 } 90 91 libe = dlopen("./libe.so", RTLD_NOW | RTLD_GLOBAL); 92 if (libe == NULL) { 93 fprintf(stderr, "Error opening libe.so: %s\n", dlerror()); 94 exit(117); 95 } 96 97 a = (int (*)())dlsym(libe, "a"); 98 if (a == NULL) { 99 fprintf(stderr, "Error getting symbol a: %s\n", dlerror()); 100 exit(116); 101 } 102 103 return a(); 104} 105EOI 106 107# build 108compile_program_dl -o program program.c 109 110# run 111test_run_ok ./program 1 112