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# libd.so, not to symbol in libb_dependency.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 48int e() { return 0; } 49EOI 50 51# build 52compile_lib -o liba.so liba.c ./libb.so ./libd.so 53 54 55# create libe.so 56cat > libe.c << EOI 57extern int c(); 58int a() { return c(); } 59EOI 60 61# build 62compile_lib -o libe.so libe.c 63 64 65# create program 66cat > program.c << EOI 67#include <dlfcn.h> 68#include <stdio.h> 69#include <stdlib.h> 70int 71main() 72{ 73 void* liba; 74 void* libe; 75 int (*a)(); 76 77 liba = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL); 78 if (liba == NULL) { 79 fprintf(stderr, "Error opening liba.so: %s\n", dlerror()); 80 exit(117); 81 } 82 83 libe = dlopen("./libe.so", RTLD_NOW | RTLD_GLOBAL); 84 if (libe == NULL) { 85 fprintf(stderr, "Error opening libe.so: %s\n", dlerror()); 86 exit(117); 87 } 88 89 a = (int (*)())dlsym(libe, "a"); 90 if (a == NULL) { 91 fprintf(stderr, "Error getting symbol a: %s\n", dlerror()); 92 exit(116); 93 } 94 95 return a(); 96} 97EOI 98 99# build 100compile_program_dl -o program program.c 101 102# run 103test_run_ok ./program 2 104 105