-
-
Save auzhva/6e3660c2433f7ead765d4d09e645013b to your computer and use it in GitHub Desktop.
This file contains 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> | |
int main(const int argc, const char **argv) { | |
void *h = dlopen(argv[1], RTLD_LAZY); | |
if (NULL == h) { | |
printf("error = %s\n", dlerror()); | |
return 1; | |
} | |
printf("dlopen is ok\n"); | |
dlclose(h); | |
} |
This file contains 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 <pthread.h> | |
// cgo def | |
extern int get_version(); | |
char get(int idx) { | |
// C-side __thread var | |
static __thread char buffer[10*1024*1024]; | |
// Call to go | |
get_version(); | |
// meaningless, just a sample | |
return buffer[idx]; | |
} |
This file contains 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
package main | |
import "C" | |
//export get_version | |
func get_version() C.int { | |
return 2 | |
} | |
func main() { | |
} |
This file contains 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
default: run | |
.PHONY: app | |
app: | |
gcc app.c -o app -ldl | |
# This passes as both libGoShared.so and libClibShared.so are dynamic | |
# So only libGoShared has DF_STATIC_TLS flag and it's only 16 bytes | |
shared: app | |
go build -ldflags="-s -w" -o libGoShared.so -buildmode=c-shared ./lib.go | |
gcc -shared -lpthread -fPIC lib.c -o libClibShared.so -lGoShared -L. | |
LD_LIBRARY_PATH=. ./app ./libClibShared.so | |
# This fails as libClibStatic.so contains both C and Go pars | |
# and inherits DF_STATIC_TLS flag from go and fails on loading | |
static: app | |
go build -ldflags="-s -w" -o libGoStatic.a -buildmode=c-archive ./lib.go | |
gcc -shared -lpthread -fPIC lib.c -o libClibStatic.so -lGoStatic -L. | |
LD_LIBRARY_PATH=. ./app ./libClibStatic.so | |
clean: | |
rm -f *.so | |
rm -f *.a | |
rm -f app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment