mirror of
https://github.com/frida/tinycc
synced 2024-12-24 05:56:49 +03:00
libtcc: support more than one crtprefix
Looks like gcc has that. Oh Deer!
This commit is contained in:
parent
e6f3bf7f08
commit
e844fb11c2
2
configure
vendored
2
configure
vendored
@ -281,7 +281,7 @@ echo " --with-selinux use mmap instead of exec mem"
|
||||
echo " [requires write access to /tmp]"
|
||||
echo " --sysincludepaths=... specify system include paths, colon separated"
|
||||
echo " --libpaths=... specify system library paths, colon separated"
|
||||
echo " --crtprefix=... specify location of crt?.o"
|
||||
echo " --crtprefix=... specify locations of crt?.o, colon separated"
|
||||
echo " --elfinterp=... specify elf interpreter"
|
||||
echo ""
|
||||
#echo "NOTE: The object files are build at the place where configure is launched"
|
||||
|
57
libtcc.c
57
libtcc.c
@ -994,6 +994,8 @@ LIBTCCAPI TCCState *tcc_new(void)
|
||||
#ifndef TCC_TARGET_PE
|
||||
/* default library paths */
|
||||
tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
|
||||
/* paths for crt objects */
|
||||
tcc_split_path(s, (void ***)&s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
|
||||
#endif
|
||||
|
||||
/* no section zero */
|
||||
@ -1059,6 +1061,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
|
||||
|
||||
/* free library paths */
|
||||
dynarray_reset(&s1->library_paths, &s1->nb_library_paths);
|
||||
dynarray_reset(&s1->crt_paths, &s1->nb_crt_paths);
|
||||
|
||||
/* free include paths */
|
||||
dynarray_reset(&s1->cached_includes, &s1->nb_cached_includes);
|
||||
@ -1225,45 +1228,51 @@ LIBTCCAPI int tcc_add_library_path(TCCState *s, const char *pathname)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* find and load a dll. Return non zero if not found */
|
||||
/* XXX: add '-rpath' option support ? */
|
||||
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
|
||||
static int tcc_add_library_internal(TCCState *s, const char *fmt,
|
||||
const char *filename, int flags, char **paths, int nb_paths)
|
||||
{
|
||||
char buf[1024];
|
||||
int i;
|
||||
|
||||
for(i = 0; i < s->nb_library_paths; i++) {
|
||||
snprintf(buf, sizeof(buf), "%s/%s",
|
||||
s->library_paths[i], filename);
|
||||
for(i = 0; i < nb_paths; i++) {
|
||||
snprintf(buf, sizeof(buf), fmt, paths[i], filename);
|
||||
if (tcc_add_file_internal(s, buf, flags) == 0)
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* find and load a dll. Return non zero if not found */
|
||||
/* XXX: add '-rpath' option support ? */
|
||||
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);
|
||||
}
|
||||
|
||||
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
|
||||
{
|
||||
if (-1 == tcc_add_library_internal(s, "%s/%s",
|
||||
filename, 0, s->crt_paths, s->nb_crt_paths))
|
||||
error_noabort("file '%s' not found", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the library name is the same as the argument of the '-l' option */
|
||||
LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
|
||||
{
|
||||
char buf[1024];
|
||||
int i;
|
||||
|
||||
/* first we look for the dynamic library if not static linking */
|
||||
if (!s->static_link) {
|
||||
#ifdef TCC_TARGET_PE
|
||||
if (pe_add_dll(s, libraryname) == 0)
|
||||
return 0;
|
||||
const char *libs[] = { "%s/%s.def", "%s/lib%s.def", "%s/%s.dll", "%s/lib%s.dll", "%s/lib%s.a", NULL };
|
||||
const char **pp = s->static_link ? libs + 4 : libs;
|
||||
#else
|
||||
snprintf(buf, sizeof(buf), "lib%s.so", libraryname);
|
||||
if (tcc_add_dll(s, buf, 0) == 0)
|
||||
return 0;
|
||||
const char *libs[] = { "%s/lib%s.so", "%s/lib%s.a", NULL };
|
||||
const char **pp = s->static_link ? libs + 1 : libs;
|
||||
#endif
|
||||
}
|
||||
/* then we look for the static library */
|
||||
for(i = 0; i < s->nb_library_paths; i++) {
|
||||
snprintf(buf, sizeof(buf), "%s/lib%s.a",
|
||||
s->library_paths[i], libraryname);
|
||||
if (tcc_add_file_internal(s, buf, 0) == 0)
|
||||
while (*pp) {
|
||||
if (0 == tcc_add_library_internal(s, *pp,
|
||||
libraryname, 0, s->library_paths, s->nb_library_paths))
|
||||
return 0;
|
||||
++pp;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -1329,8 +1338,8 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
||||
if ((output_type == TCC_OUTPUT_EXE || output_type == TCC_OUTPUT_DLL) &&
|
||||
!s->nostdlib) {
|
||||
if (output_type != TCC_OUTPUT_DLL)
|
||||
tcc_add_file(s, TCC_CRTO("crt1.o"));
|
||||
tcc_add_file(s, TCC_CRTO("crti.o"));
|
||||
tcc_add_crt(s, "crt1.o");
|
||||
tcc_add_crt(s, "crti.o");
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
|
8
tcc.h
8
tcc.h
@ -144,7 +144,7 @@
|
||||
|
||||
/* path to find crt1.o, crti.o and crtn.o */
|
||||
#ifndef CONFIG_TCC_CRTPREFIX
|
||||
# define CONFIG_TCC_CRTPREFIX "/usr" CONFIG_TCC_LDDIR
|
||||
# define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR
|
||||
#endif
|
||||
|
||||
/* system include paths */
|
||||
@ -190,8 +190,6 @@
|
||||
|
||||
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
|
||||
#define TCC_LIBGCC CONFIG_SYSROOT CONFIG_TCC_LDDIR "/libgcc_s.so.1"
|
||||
/* crt?.o files */
|
||||
#define TCC_CRTO(crto) CONFIG_SYSROOT CONFIG_TCC_CRTPREFIX "/" crto
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
@ -474,6 +472,8 @@ struct TCCState {
|
||||
|
||||
char **library_paths;
|
||||
int nb_library_paths;
|
||||
char **crt_paths;
|
||||
int nb_crt_paths;
|
||||
|
||||
/* array of all loaded dlls (including those referenced by loaded
|
||||
dlls) */
|
||||
@ -1013,6 +1013,7 @@ ST_FUNC void tcc_close(void);
|
||||
|
||||
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
|
||||
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
|
||||
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
|
||||
PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value);
|
||||
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
|
||||
PUB_FUNC void set_num_callers(int n);
|
||||
@ -1300,7 +1301,6 @@ ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
|
||||
/* ------------ tccpe.c -------------- */
|
||||
#ifdef TCC_TARGET_PE
|
||||
ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
|
||||
ST_FUNC int pe_add_dll(struct TCCState *s, const char *libraryname);
|
||||
ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
|
||||
ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const void *value);
|
||||
ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
|
||||
|
2
tccelf.c
2
tccelf.c
@ -1247,7 +1247,7 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
|
||||
#endif
|
||||
/* add crt end if not memory output */
|
||||
if (s1->output_type != TCC_OUTPUT_MEMORY)
|
||||
tcc_add_file(s1, TCC_CRTO("crtn.o"));
|
||||
tcc_add_crt(s1, "crtn.o");
|
||||
}
|
||||
}
|
||||
|
||||
|
15
tccpe.c
15
tccpe.c
@ -1659,21 +1659,6 @@ ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ST_FUNC int pe_add_dll(struct TCCState *s, const char *libname)
|
||||
{
|
||||
static const char *pat[] = {
|
||||
"%s.def", "lib%s.def", "%s.dll", "lib%s.dll", NULL
|
||||
};
|
||||
const char **p = pat;
|
||||
do {
|
||||
char buf[MAX_PATH];
|
||||
snprintf(buf, sizeof(buf), *p, libname);
|
||||
if (tcc_add_dll(s, buf, 0) == 0)
|
||||
return 0;
|
||||
} while (*++p);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
#ifdef TCC_TARGET_X86_64
|
||||
static unsigned pe_add_uwwind_info(TCCState *s1)
|
||||
|
Loading…
Reference in New Issue
Block a user