From e460f7dbb2165112bc618816ec15be312b257de2 Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 23 Jul 2022 17:19:56 +0200 Subject: [PATCH] tccelf: load libtcc1.a from library path ... rather than from tccdir. Also allows to load cross versions of bcheck.o etc. (if we would build them which we currently don't). 18 insertions(+), 24 deletions(-) --- Makefile | 6 +++--- libtcc.c | 12 +++++++++++- tcc.h | 9 ++++----- tccelf.c | 9 --------- tccpe.c | 6 ------ 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 211fb492..16065df5 100644 --- a/Makefile +++ b/Makefile @@ -172,10 +172,10 @@ DEFINES += $(DEF-$(or $(findstring win,$T),unx)) ifneq ($(X),) ifeq ($(CONFIG_WIN32),yes) -DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\"" -DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\"" +DEF-win += -DCONFIG_TCC_CROSSPREFIX="\"$X\"" +DEF-unx += -DCONFIG_TCC_CROSSPREFIX="\"lib/$X\"" else -DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\"" +DEF-all += -DCONFIG_TCC_CROSSPREFIX="\"$X\"" DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" endif endif diff --git a/libtcc.c b/libtcc.c index f446cdf8..ca575586 100644 --- a/libtcc.c +++ b/libtcc.c @@ -1167,14 +1167,24 @@ static int tcc_add_library_internal(TCCState *s, const char *fmt, return -1; } -#ifndef TCC_TARGET_MACHO /* find and load a dll. Return non zero if not found */ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) { return tcc_add_library_internal(s, "%s/%s", filename, flags, s->library_paths, s->nb_library_paths); } + +/* find [cross-]libtcc1.a and tcc helper objects in library path */ +ST_FUNC void tcc_add_support(TCCState *s1, const char *filename) +{ +#ifdef CONFIG_TCC_CROSSPREFIX + char buf[100]; + snprintf(buf, sizeof buf, "%s%s", CONFIG_TCC_CROSSPREFIX, filename); + filename = buf; #endif + if (tcc_add_dll(s1, filename, 0) < 0) + tcc_error_noabort("%s not found", filename); +} #if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename) diff --git a/tcc.h b/tcc.h index 911a32d8..40eb1f03 100644 --- a/tcc.h +++ b/tcc.h @@ -203,8 +203,7 @@ extern long double strtold (const char *__nptr, char **__endptr); # endif #endif -#if !defined TCC_IS_NATIVE \ - || (defined CONFIG_TCC_BACKTRACE && CONFIG_TCC_BACKTRACE==0) +#if defined CONFIG_TCC_BACKTRACE && CONFIG_TCC_BACKTRACE==0 # undef CONFIG_TCC_BACKTRACE #else # define CONFIG_TCC_BACKTRACE 1 /* enable builtin stack backtraces */ @@ -285,7 +284,8 @@ extern long double strtold (const char *__nptr, char **__endptr); # define CONFIG_TCC_LIBPATHS "{B}/lib" # else # define CONFIG_TCC_LIBPATHS \ - ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ + "{B}" \ + ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR) # endif @@ -1264,9 +1264,8 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) #ifndef ELF_OBJ_ONLY ST_FUNC int tcc_add_crt(TCCState *s, const char *filename); #endif -#ifndef TCC_TARGET_MACHO ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags); -#endif +ST_FUNC void tcc_add_support(TCCState *s1, const char *filename); #ifdef CONFIG_TCC_BCHECK ST_FUNC void tcc_add_bcheck(TCCState *s1); #endif diff --git a/tccelf.c b/tccelf.c index 37f943f2..4530b1b7 100644 --- a/tccelf.c +++ b/tccelf.c @@ -1299,15 +1299,6 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) set_global_sym(s1, buf, s, end_offset); } -#ifndef TCC_TARGET_PE -static void tcc_add_support(TCCState *s1, const char *filename) -{ - char buf[1024]; - snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename); - tcc_add_file(s1, buf); -} -#endif - ST_FUNC void add_array (TCCState *s1, const char *sec, int c) { Section *s; diff --git a/tccpe.c b/tccpe.c index f70c8b99..66773312 100644 --- a/tccpe.c +++ b/tccpe.c @@ -1858,12 +1858,6 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack) #define PE_STDSYM(n,s) "_" n s #endif -static void tcc_add_support(TCCState *s1, const char *filename) -{ - if (tcc_add_dll(s1, filename, 0) < 0) - tcc_error_noabort("%s not found", filename); -} - static void pe_add_runtime(TCCState *s1, struct pe_info *pe) { const char *start_symbol;