libtcc: Detect (but ignore) -init and -fini for -Wl

--
By by ... Detlef
master
Detlef Riekenberg 2010-04-05 22:56:33 +02:00
parent 87574de8ed
commit 34dabe496f
4 changed files with 26 additions and 13 deletions

View File

@ -1395,7 +1395,7 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value)
} }
static int strstart(const char *str, const char *val, const char **ptr) static int strstart(const char *str, const char *val, char **ptr)
{ {
const char *p, *q; const char *p, *q;
p = str; p = str;
@ -1407,27 +1407,36 @@ static int strstart(const char *str, const char *val, const char **ptr)
q++; q++;
} }
if (ptr) if (ptr)
*ptr = p; *ptr = (char *) p;
return 1; return 1;
} }
/* set linker options */ /* set linker options */
PUB_FUNC const char * tcc_set_linker(TCCState *s, const char *option, int multi) PUB_FUNC const char * tcc_set_linker(TCCState *s, char *option, int multi)
{ {
const char *p = option; char *p = option;
char *end = NULL; char *end;
while (option && *option) { while (option && *option) {
end = NULL;
if (strstart(option, "-Bsymbolic", &p)) { if (strstart(option, "-Bsymbolic", &p)) {
s->symbolic = TRUE; s->symbolic = TRUE;
#ifdef TCC_TARGET_PE #ifdef TCC_TARGET_PE
} else if (strstart(option, "--file-alignment,", &p)) { } else if (strstart(option, "--file-alignment,", &p)) {
s->pe_file_align = strtoul(p, &end, 16); s->pe_file_align = strtoul(p, &end, 16);
#endif #endif
} else if (strstart(option, "-fini,", &p)) {
s->fini_symbol = p;
if (s->warn_unsupported)
warning("ignoring -fini %s", p);
} else if (strstart(option, "--image-base,", &p)) { } else if (strstart(option, "--image-base,", &p)) {
s->text_addr = strtoul(p, &end, 16); s->text_addr = strtoul(p, &end, 16);
s->has_text_addr = 1; s->has_text_addr = 1;
} else if (strstart(option, "-init,", &p)) {
s->init_symbol = p;
if (s->warn_unsupported)
warning("ignoring -init %s", p);
} else if (strstart(option, "--oformat,", &p)) { } else if (strstart(option, "--oformat,", &p)) {
#if defined(TCC_TARGET_PE) #if defined(TCC_TARGET_PE)
@ -1496,11 +1505,11 @@ PUB_FUNC const char * tcc_set_linker(TCCState *s, const char *option, int multi)
} }
if (multi) { if (multi) {
if (end) { option = NULL;
option = end; p = strchr( (end) ? end : p, ',');
} else { if (p) {
option = strchr(p, ','); *p = 0; /* terminate last option */
if (option) option++; option = ++p;
} }
} else } else
option = NULL; option = NULL;

View File

@ -32,7 +32,7 @@ LIBTCCAPI void tcc_set_error_func(TCCState *s, void *error_opaque,
LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value); LIBTCCAPI int tcc_set_warning(TCCState *s, const char *warning_name, int value);
/* set linker option */ /* set linker option */
LIBTCCAPI const char * tcc_set_linker(TCCState *s, const char *option, int multi); LIBTCCAPI const char * tcc_set_linker(TCCState *s, char *option, int multi);
/*****************************/ /*****************************/
/* preprocessor */ /* preprocessor */

2
tcc.c
View File

@ -367,7 +367,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
break; break;
case TCC_OPTION_Wl: case TCC_OPTION_Wl:
{ {
if ((r = (char *)tcc_set_linker(s, optarg, TRUE))) if ((r = (char *) tcc_set_linker(s, (char *)optarg, TRUE)))
error("unsupported linker option '%s'", r); error("unsupported linker option '%s'", r);
} }
break; break;

4
tcc.h
View File

@ -462,6 +462,10 @@ struct TCCState {
/* address of text section */ /* address of text section */
unsigned long text_addr; unsigned long text_addr;
int has_text_addr; int has_text_addr;
/* symbols to call at load-time / unload-time */
const char *init_symbol;
const char *fini_symbol;
/* output format, see TCC_OUTPUT_FORMAT_xxx */ /* output format, see TCC_OUTPUT_FORMAT_xxx */
int output_format; int output_format;