From fb051559155d2df30c82bb7cc9429b8e2bc86506 Mon Sep 17 00:00:00 2001 From: haskal Date: Fri, 16 Oct 2020 23:33:50 -0400 Subject: [PATCH] committing ELF crimes (part 1) make a dynamic binary that works under both glibc and musl (given you invoke ld.so directly and create a fake musl libc pointing to glibc) --- Makefile | 3 ++- main_bc.c | 19 +++++++++++++++++++ run.rkt | 8 ++++++++ scripts/setup.sh | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 422c0b4..6a96ff0 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,8 @@ clean-in-container: # main build stuff $(APP_NAME): main_bc.c app.o - $(CC) -o $@ -pipe -O3 -DAPP_NAME='"$(APP_NAME)"' -static $^ -lracket3m -lrktio -lucontext -lffi + # $(CC) -o $@ -pipe -O3 -DAPP_NAME='"$(APP_NAME)"' -static $^ -lracket3m -lrktio -lucontext -lffi + $(CC) -o $@ -pipe -O3 -DAPP_NAME='"$(APP_NAME)"' $^ /usr/lib/libracket3m.a /usr/lib/librktio.a /usr/lib/libffi.a /lib/libucontext.a # this is faster than --c-mods by a lot # it's less portable but like, we're containerized already so it'll work diff --git a/main_bc.c b/main_bc.c index 5207566..b2a3db5 100644 --- a/main_bc.c +++ b/main_bc.c @@ -3,6 +3,25 @@ #include #include #include +#include + +// patchups for musl vs glibc stuff +#include +int stat(const char *restrict path, struct stat *restrict buf) { + return __xstat(1, path, buf); +} +int fstat(int fildes, struct stat *buf) { + return __fxstat(1, fildes, buf); +} +int lstat(const char *restrict path, struct stat *restrict buf) { + return __lxstat(1, path, buf); +} + +extern void* __dso_handle; + +int atexit(void (*function)(void)) { + return __cxa_atexit(function, NULL, __dso_handle); +} extern const char _binary_app_zo_start; extern const char _binary_app_zo_end; diff --git a/run.rkt b/run.rkt index 30f1382..fa1c014 100644 --- a/run.rkt +++ b/run.rkt @@ -17,3 +17,11 @@ (displayln "back") ; (error "meow meow") + +(module gui-test racket/gui + (provide run-test) + (define (run-test) + (message-box "hello" "hello world"))) + +(require (submod "." gui-test)) +(run-test) diff --git a/scripts/setup.sh b/scripts/setup.sh index fa1444a..05625dd 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -13,3 +13,4 @@ rm -Rf src/foreign/libffi make -j $(nproc) CPUS=$(nproc) make install raco pkg install --deps search-auto cext-lib +raco pkg install --deps search-auto gui-lib