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