Use CString to concat linker options
As suggested, change type of linker_arg variable to the more appropriate CString type, since linker_arg is about dynamically grown string.
This commit is contained in:
parent
2eee100c37
commit
1c11b857fe
1 changed files with 8 additions and 13 deletions
21
tcc.c
21
tcc.c
|
@ -35,7 +35,7 @@ static int do_bench = 0;
|
||||||
static int gen_deps;
|
static int gen_deps;
|
||||||
static const char *deps_outfile;
|
static const char *deps_outfile;
|
||||||
static const char *m_option;
|
static const char *m_option;
|
||||||
static char *linker_arg;
|
static CString linker_arg;
|
||||||
|
|
||||||
#define TCC_OPTION_HAS_ARG 0x0001
|
#define TCC_OPTION_HAS_ARG 0x0001
|
||||||
#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
|
#define TCC_OPTION_NOSEP 0x0002 /* cannot have space before option and arg */
|
||||||
|
@ -281,11 +281,11 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
||||||
const char *optarg, *p1, *r1;
|
const char *optarg, *p1, *r1;
|
||||||
char *r;
|
char *r;
|
||||||
int was_pthread;
|
int was_pthread;
|
||||||
unsigned long linker_argsize = 0;
|
|
||||||
|
|
||||||
was_pthread = 0; /* is set if commandline contains -pthread key */
|
was_pthread = 0; /* is set if commandline contains -pthread key */
|
||||||
|
|
||||||
optind = 1;
|
optind = 1;
|
||||||
|
cstr_new(&linker_arg);
|
||||||
while (optind < argc) {
|
while (optind < argc) {
|
||||||
|
|
||||||
r = argv[optind++];
|
r = argv[optind++];
|
||||||
|
@ -444,16 +444,11 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
||||||
s->rdynamic = 1;
|
s->rdynamic = 1;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_Wl:
|
case TCC_OPTION_Wl:
|
||||||
if (!linker_arg) {
|
if (!linker_arg.data_allocated)
|
||||||
linker_argsize = strlen(optarg) + 1;
|
cstr_cat(&linker_arg, optarg);
|
||||||
linker_arg = tcc_malloc(linker_argsize);
|
|
||||||
pstrcpy(linker_arg, linker_argsize, optarg);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
linker_argsize += strlen(optarg) + 1;
|
cstr_ccat(&linker_arg, ',');
|
||||||
linker_arg = tcc_realloc(linker_arg, linker_argsize);
|
cstr_cat(&linker_arg, optarg);
|
||||||
pstrcat(linker_arg, linker_argsize, ",");
|
|
||||||
pstrcat(linker_arg, linker_argsize, optarg);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_E:
|
case TCC_OPTION_E:
|
||||||
|
@ -476,7 +471,7 @@ static int parse_args(TCCState *s, int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((r = (char *) tcc_set_linker(s, (char *)linker_arg, TRUE)))
|
if ((r = (char *) tcc_set_linker(s, (char *) linker_arg.data, TRUE)))
|
||||||
tcc_error("unsupported linker option '%s'", r);
|
tcc_error("unsupported linker option '%s'", r);
|
||||||
/* fixme: these options could be different on your platform */
|
/* fixme: these options could be different on your platform */
|
||||||
if (was_pthread && output_type != TCC_OUTPUT_OBJ) {
|
if (was_pthread && output_type != TCC_OUTPUT_OBJ) {
|
||||||
|
@ -610,7 +605,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
tcc_delete(s);
|
tcc_delete(s);
|
||||||
tcc_free(linker_arg);
|
cstr_free(&linker_arg);
|
||||||
tcc_free(outfile);
|
tcc_free(outfile);
|
||||||
|
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
|
|
Loading…
Add table
Reference in a new issue