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)
This commit is contained in:
xenia 2020-10-16 23:33:50 -04:00
parent a38a6219c2
commit fb05155915
4 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -3,6 +3,25 @@
#include <racket/scheme.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// patchups for musl vs glibc stuff
#include <sys/stat.h>
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;

View File

@ -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)

View File

@ -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