Skip to content

Commit e460f7d

Browse files
author
grischka
committed
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(-)
1 parent d653cf0 commit e460f7d

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ DEFINES += $(DEF-$(or $(findstring win,$T),unx))
172172

173173
ifneq ($(X),)
174174
ifeq ($(CONFIG_WIN32),yes)
175-
DEF-win += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
176-
DEF-unx += -DTCC_LIBTCC1="\"lib/$(X)libtcc1.a\""
175+
DEF-win += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
176+
DEF-unx += -DCONFIG_TCC_CROSSPREFIX="\"lib/$X\""
177177
else
178-
DEF-all += -DTCC_LIBTCC1="\"$(X)libtcc1.a\""
178+
DEF-all += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
179179
DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
180180
endif
181181
endif

libtcc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,14 +1167,24 @@ static int tcc_add_library_internal(TCCState *s, const char *fmt,
11671167
return -1;
11681168
}
11691169

1170-
#ifndef TCC_TARGET_MACHO
11711170
/* find and load a dll. Return non zero if not found */
11721171
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
11731172
{
11741173
return tcc_add_library_internal(s, "%s/%s", filename, flags,
11751174
s->library_paths, s->nb_library_paths);
11761175
}
1176+
1177+
/* find [cross-]libtcc1.a and tcc helper objects in library path */
1178+
ST_FUNC void tcc_add_support(TCCState *s1, const char *filename)
1179+
{
1180+
#ifdef CONFIG_TCC_CROSSPREFIX
1181+
char buf[100];
1182+
snprintf(buf, sizeof buf, "%s%s", CONFIG_TCC_CROSSPREFIX, filename);
1183+
filename = buf;
11771184
#endif
1185+
if (tcc_add_dll(s1, filename, 0) < 0)
1186+
tcc_error_noabort("%s not found", filename);
1187+
}
11781188

11791189
#if !defined TCC_TARGET_PE && !defined TCC_TARGET_MACHO
11801190
ST_FUNC int tcc_add_crt(TCCState *s1, const char *filename)

tcc.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ extern long double strtold (const char *__nptr, char **__endptr);
203203
# endif
204204
#endif
205205

206-
#if !defined TCC_IS_NATIVE \
207-
|| (defined CONFIG_TCC_BACKTRACE && CONFIG_TCC_BACKTRACE==0)
206+
#if defined CONFIG_TCC_BACKTRACE && CONFIG_TCC_BACKTRACE==0
208207
# undef CONFIG_TCC_BACKTRACE
209208
#else
210209
# define CONFIG_TCC_BACKTRACE 1 /* enable builtin stack backtraces */
@@ -285,7 +284,8 @@ extern long double strtold (const char *__nptr, char **__endptr);
285284
# define CONFIG_TCC_LIBPATHS "{B}/lib"
286285
# else
287286
# define CONFIG_TCC_LIBPATHS \
288-
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
287+
"{B}" \
288+
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
289289
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
290290
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
291291
# endif
@@ -1264,9 +1264,8 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
12641264
#ifndef ELF_OBJ_ONLY
12651265
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
12661266
#endif
1267-
#ifndef TCC_TARGET_MACHO
12681267
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1269-
#endif
1268+
ST_FUNC void tcc_add_support(TCCState *s1, const char *filename);
12701269
#ifdef CONFIG_TCC_BCHECK
12711270
ST_FUNC void tcc_add_bcheck(TCCState *s1);
12721271
#endif

tccelf.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,15 +1299,6 @@ static void add_init_array_defines(TCCState *s1, const char *section_name)
12991299
set_global_sym(s1, buf, s, end_offset);
13001300
}
13011301

1302-
#ifndef TCC_TARGET_PE
1303-
static void tcc_add_support(TCCState *s1, const char *filename)
1304-
{
1305-
char buf[1024];
1306-
snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename);
1307-
tcc_add_file(s1, buf);
1308-
}
1309-
#endif
1310-
13111302
ST_FUNC void add_array (TCCState *s1, const char *sec, int c)
13121303
{
13131304
Section *s;

tccpe.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,12 +1858,6 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack)
18581858
#define PE_STDSYM(n,s) "_" n s
18591859
#endif
18601860

1861-
static void tcc_add_support(TCCState *s1, const char *filename)
1862-
{
1863-
if (tcc_add_dll(s1, filename, 0) < 0)
1864-
tcc_error_noabort("%s not found", filename);
1865-
}
1866-
18671861
static void pe_add_runtime(TCCState *s1, struct pe_info *pe)
18681862
{
18691863
const char *start_symbol;

0 commit comments

Comments
 (0)