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