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