Skip to content

Commit

Permalink
fix: enable _GNU_SOURCE in for linux dyn target
Browse files Browse the repository at this point in the history
now correctly builds a dynamically linked executable depending on
local libc. still needs to create a tmpdir for libtcc1.a
  • Loading branch information
jaromil committed Sep 29, 2024
1 parent 95edf24 commit b6ec05a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build/linux.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
include build/init.mk

cc := gcc
cflags += -DLIBC_GNU
cflags += -DLIBC_GNU -D_GNU_SOURCE

all: deps cjit

Expand Down
12 changes: 5 additions & 7 deletions src/cjit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
6 changes: 1 addition & 5 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include <string.h>
#include <errno.h>

#if defined(LIBC_MUSL)
#include <ftw.h> // POSIX
#endif
#include <ftw.h> // _GNU_SOURCE

extern void _err(const char *fmt, ...);

Expand Down Expand Up @@ -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) {
Expand All @@ -108,4 +105,3 @@ bool rm_recursive(char *path) {
}
return true;
}
#endif

0 comments on commit b6ec05a

Please sign in to comment.