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