1#!/bin/sh
2
3# program
4#
5# dlopen():
6# liba.so
7# <- libb.so
8#    <- libb_dependency.so
9# <- libd.so
10#
11# Expected: Undefined symbol in liba.so resolves to symbol in
12# libd.so, 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 libd.so
37cat > libd.c << EOI
38int c() { return 2; }
39EOI
40
41# build
42compile_lib -o libd.so libd.c
43
44
45# create liba.so
46cat > liba.c << EOI
47extern int c();
48int a() { return c(); }
49EOI
50
51# build
52compile_lib -o liba.so liba.c ./libb.so ./libd.so
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	int (*a)();
65
66	liba = dlopen("./liba.so", RTLD_NOW | RTLD_GLOBAL);
67	if (liba == NULL) {
68		fprintf(stderr, "Error opening liba.so: %s\n", dlerror());
69		exit(117);
70	}
71
72	a = (int (*)())dlsym(liba, "a");
73	if (a == NULL) {
74		fprintf(stderr, "Error getting symbol a: %s\n", dlerror());
75		exit(116);
76	}
77
78	return a();
79}
80EOI
81
82# build
83compile_program_dl -o program program.c
84
85# run
86test_run_ok ./program 2
87
88