-
-
Save dagood/05200cc37be277448928e1d920b445d5 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
FROM buildpack-deps:bullseye-scm | |
RUN apt update \ | |
&& apt install -y --no-install-recommends \ | |
g++ \ | |
gcc \ | |
libc6-dev \ | |
make \ | |
wget \ | |
&& ldd --version | |
RUN v=1.18; \ | |
t=go$v.linux-amd64.tar.gz; \ | |
wget -q https://go.dev/dl/$t -O $t \ | |
&& tar -xf $t | |
ADD foo.c . | |
RUN gcc -fPIC -c foo.c \ | |
&& gcc -shared -o foo.so -pthread foo.o | |
ADD . . | |
RUN go/bin/go run . | |
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
FROM buildpack-deps:bullseye-scm | |
RUN apt update \ | |
&& apt install -y --no-install-recommends \ | |
g++ \ | |
gcc \ | |
libc6-dev \ | |
make \ | |
wget \ | |
&& ldd --version | |
RUN v=1.17.8; \ | |
t=go$v.linux-amd64.tar.gz; \ | |
wget -q https://go.dev/dl/$t -O $t \ | |
&& tar -xf $t | |
ADD foo.c . | |
RUN gcc -fPIC -c foo.c \ | |
&& gcc -shared -o foo.so -pthread foo.o | |
ADD . . | |
RUN go/bin/go run . | |
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
FROM fedora:35 | |
RUN dnf install -y \ | |
g++ \ | |
gcc \ | |
glibc-static \ | |
make \ | |
wget \ | |
&& ldd --version | |
RUN v=1.18; \ | |
t=go$v.linux-amd64.tar.gz; \ | |
wget -q https://go.dev/dl/$t -O $t \ | |
&& tar -xf $t | |
ADD foo.c . | |
RUN gcc -fPIC -c foo.c \ | |
&& gcc -shared -o foo.so -pthread foo.o | |
ADD . . | |
RUN go/bin/go run . |
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
FROM buildpack-deps:bullseye-scm | |
RUN apt update \ | |
&& apt install -y --no-install-recommends \ | |
g++ \ | |
gcc \ | |
libc6-dev \ | |
make \ | |
wget \ | |
&& ldd --version | |
RUN v=1.18; \ | |
t=go$v.linux-amd64.tar.gz; \ | |
wget -q https://go.dev/dl/$t -O $t \ | |
&& tar -xf $t | |
ADD foo.c . | |
RUN gcc -fPIC -c -pthread foo.c \ | |
&& gcc -shared -o foo.so -pthread foo.o | |
ADD . . | |
RUN go/bin/go run . | |
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> | |
#include <stdlib.h> | |
pthread_mutex_t *lock_new(void) | |
{ | |
pthread_mutex_t *lock = malloc(sizeof(pthread_mutex_t)); | |
pthread_mutex_lock(lock); | |
return lock; | |
} |
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
module example | |
go 1.18 |
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 | |
/* | |
#include <dlfcn.h> | |
#include <unistd.h> | |
#cgo LDFLAGS: -ldl -static | |
*/ | |
import "C" | |
import "fmt" | |
func main() { | |
fmt.Println("Step 1") | |
if C.dlopen(C.CString("./foo.so"), C.RTLD_NOW) == nil { | |
panic("library not found") | |
} | |
fmt.Println("Step 2") | |
C.setgid(0) | |
fmt.Println("Step 3") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment