Last active
April 14, 2024 04:13
-
-
Save depressed-pho/b6894fdaef94a1b9aa5459b1a2f65590 to your computer and use it in GitHub Desktop.
I thought there was an issue in TLS handling but it doesn't reproduce with this code...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlfcn.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
typedef int (*get_foo_t)(); | |
int main() { | |
void* lib = dlopen("./libtls.so", RTLD_LAZY); | |
if (!lib) { | |
printf("%s", dlerror()); | |
exit(1); | |
} | |
get_foo_t get_foo = dlsym(lib, "get_foo"); | |
if (!get_foo) { | |
printf("%s", dlerror()); | |
exit(1); | |
} | |
printf("foo = %d\n", get_foo()); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: run | |
run: dlopen-tls-test libtls.so | |
./dlopen-tls-test | |
.PHONY: clean | |
clean: | |
rm -f dlopen-tls-test *.so | |
dlopen-tls-test: main.c | |
cc -o $@ main.c | |
libtls.so: tls.c | |
cc -shared -fPIC -o $@ tls.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% make | |
cc -o dlopen-tls-test main.c | |
cc -shared -fPIC -o libtls.so tls.c | |
./dlopen-tls-test | |
foo = -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static __thread int foo = -1; | |
int get_foo() { | |
return foo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment