From b6ec05a68906668fc3dc7c318b5889800303657f Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 29 Sep 2024 16:10:48 +0200 Subject: [PATCH] fix: enable _GNU_SOURCE in for linux dyn target now correctly builds a dynamically linked executable depending on local libc. still needs to create a tmpdir for libtcc1.a --- build/linux.mk | 2 +- src/cjit.c | 12 +++++------- src/file.c | 6 +----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/build/linux.mk b/build/linux.mk index 3fb21d5..161908d 100644 --- a/build/linux.mk +++ b/build/linux.mk @@ -1,7 +1,7 @@ include build/init.mk cc := gcc -cflags += -DLIBC_GNU +cflags += -DLIBC_GNU -D_GNU_SOURCE all: deps cjit diff --git a/src/cjit.c b/src/cjit.c index 7a292a8..5c3e41f 100644 --- a/src/cjit.c +++ b/src/cjit.c @@ -199,28 +199,27 @@ int main(int argc, char **argv) { // error handler callback for TCC tcc_set_error_func(TCC, stderr, handle_error); -#if defined(LIBC_MUSL) // initialize the tmpdir for execution tmpdir = mkdtemp(tmptemplate); if(!tmpdir) { _err("Error creating temp dir %s: %s",tmptemplate,strerror(errno)); goto endgame; } - // _err("tempdir: %s",tmpdir); tcc_set_lib_path(TCC,tmpdir); tcc_add_library_path(TCC,tmpdir); - //// TCC DEFAULT PATHS - tcc_add_include_path(TCC,"/usr/include/x86_64-linux-musl"); if(! write_to_file(tmpdir,"libtcc1.a",&libtcc1,libtcc1_len) ) goto endgame; + +#if defined(LIBC_MUSL) + //// TCC DEFAULT PATHS + tcc_add_include_path(TCC,"/usr/include/x86_64-linux-musl"); if(! write_to_file(tmpdir,"libc.so",&musl_libc,musl_libc_len) ) goto endgame; #endif #if defined(LIBC_GNU) - tcc_add_include_path(TCC,"/usr/include/linux"); - tcc_add_include_path(TCC,"/usr/lib/gcc/x86_64-linux-gnu/13/include"); + tcc_add_include_path(TCC,"lib/tinycc/include"); #endif // tcc_add_include_path(TCC,"src"); // devuan if(include_path) { @@ -268,7 +267,6 @@ int main(int argc, char **argv) { // free TCC tcc_delete(TCC); if(tmpdir) { - // _err("remove tmpdir"); rm_recursive(tmpdir); } _err("---\nExecution completed"); diff --git a/src/file.c b/src/file.c index d5b5f2e..1ed8409 100644 --- a/src/file.c +++ b/src/file.c @@ -23,9 +23,7 @@ #include #include -#if defined(LIBC_MUSL) -#include // POSIX -#endif +#include // _GNU_SOURCE extern void _err(const char *fmt, ...); @@ -89,7 +87,6 @@ bool write_to_file(char *path, char *filename, char *buf, unsigned int len) { return true; } -#if defined(LIBC_MUSL) static int rm_ftw(const char *pathname, const struct stat *sbuf, int type, struct FTW *ftwb) { @@ -108,4 +105,3 @@ bool rm_recursive(char *path) { } return true; } -#endif