1#!/bin/sh 2 3# program 4# 5# dlopen(): 6# liba.so 7# <- libb.so 8# <- libb_dependency.so 9# 10# Expected: Undefined symbol in liba.so resolves to symbol in 11# libb_dependency.so. 12 13 14. test_setup 15 16 17# create libb_dependency.so 18cat > libb_dependency.c << EOI 19int c() { return 1; } 20EOI 21 22# build 23gcc -shared -o libb_dependency.so libb_dependency.c 24 25 26# create libb.so 27cat > libb.c << EOI 28int b() { return 1; } 29EOI 30 31# build 32gcc -shared -o libb.so libb.c ./libb_dependency.so 33 34 35# create liba.so 36cat > liba.c << EOI 37extern int c(); 38int a() { return c(); } 39EOI 40 41# build 42gcc -shared -o liba.so liba.c ./libb.so 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 int (*a)(); 55 56 liba = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL); 57 if (liba == NULL) { 58 fprintf(stderr, "Error opening liba.so: %s\n", dlerror()); 59 exit(117); 60 } 61 62 a = (int (*)())dlsym(liba, "a"); 63 if (a == NULL) { 64 fprintf(stderr, "Error getting symbol a: %s\n", dlerror()); 65 exit(116); 66 } 67 68 return a(); 69} 70EOI 71 72# build 73gcc -o program program.c $libdl -Wl,-rpath,.,--export-dynamic 74 75# run 76test_run_ok ./program 1 77 78