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