summaryrefslogtreecommitdiff
path: root/tls_test.c
blob: 22dd131b7ec9998feb7eceacf3db88e505b1dec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
 * Trivial __thread variable test.
 *
 * Gareth Hughes <gareth@nvidia.com>
 */

#include <signal.h>
#include <dlfcn.h>
#include <unistd.h>
#include <stdlib.h>

void seghandle(int bar);

int main(int argc, char *argv[])
{
    void *handle;
    int (*func)(void);
    
    signal(SIGSEGV, seghandle); 
    
    if (argc != 2) {
        exit(1);
    }
    
    handle = dlopen(argv[1], RTLD_NOW);
    if (!handle) {
        exit(1);
    }

    func = dlsym(handle, "getTLSVar");
    if (!func) {
        exit(1);
    }

    func();

    if (dlclose(handle) != 0) {
        exit(1);
    }
    
    return 0;
}

void seghandle(int bar)
{
    exit(1);
}