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