aboutsummaryrefslogtreecommitdiff
path: root/libtcc.c
diff options
context:
space:
mode:
authorDetlef Riekenberg <tcc.dev@web.de>2010-04-05 21:21:58 +0200
committerDetlef Riekenberg <tcc.dev@web.de>2010-04-05 21:21:58 +0200
commit78e83d8761afb792f1a848ade7e1f97a21283a5e (patch)
tree63623a064ce2c3d142de39fec205695e933088a6 /libtcc.c
parenta135dd50c65f35fac6528cafd34ade1ec30abc0f (diff)
downloadtinycc-78e83d8761afb792f1a848ade7e1f97a21283a5e.tar.gz
tinycc-78e83d8761afb792f1a848ade7e1f97a21283a5e.tar.bz2
libtcc: Allow multiple options for -Wl separated with ','
I moved the code to libtcc to prepare for a later tiny_ld -- By by ... Detlef
Diffstat (limited to 'libtcc.c')
-rw-r--r--libtcc.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/libtcc.c b/libtcc.c
index 396ba77..32f2f81 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1394,6 +1394,117 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value)
flag_name, value);
}
+
+static int strstart(const char *str, const char *val, const char **ptr)
+{
+ const char *p, *q;
+ p = str;
+ q = val;
+ while (*q != '\0') {
+ if (*p != *q)
+ return 0;
+ p++;
+ q++;
+ }
+ if (ptr)
+ *ptr = p;
+ return 1;
+}
+
+/* set linker options */
+PUB_FUNC const char * tcc_set_linker(TCCState *s, const char *option, int multi)
+{
+ const char *p = option;
+ char *end = NULL;
+
+ while (option && *option) {
+
+ if (strstart(option, "-Bsymbolic", &p)) {
+ s->symbolic = TRUE;
+#ifdef TCC_TARGET_PE
+ } else if (strstart(option, "--file-alignment,", &p)) {
+ s->pe_file_align = strtoul(p, &end, 16);
+#endif
+ } else if (strstart(option, "--image-base,", &p)) {
+ s->text_addr = strtoul(p, &end, 16);
+ s->has_text_addr = 1;
+
+ } else if (strstart(option, "--oformat,", &p)) {
+#if defined(TCC_TARGET_PE)
+ if (strstart(p, "pe-", NULL)) {
+#else
+#if defined(TCC_TARGET_X86_64)
+ if (strstart(p, "elf64-", NULL)) {
+#else
+ if (strstart(p, "elf32-", NULL)) {
+#endif
+#endif
+ s->output_format = TCC_OUTPUT_FORMAT_ELF;
+ } else if (!strcmp(p, "binary")) {
+ s->output_format = TCC_OUTPUT_FORMAT_BINARY;
+ } else
+#ifdef TCC_TARGET_COFF
+ if (!strcmp(p, "coff")) {
+ s->output_format = TCC_OUTPUT_FORMAT_COFF;
+ } else
+#endif
+ {
+ return p;
+ }
+
+ } else if (strstart(option, "-rpath=", &p)) {
+ s->rpath = p;
+ } else if (strstart(option, "--section-alignment,", &p)) {
+ s->section_align = strtoul(p, &end, 16);
+#ifdef TCC_TARGET_PE
+ } else if (strstart(option, "--subsystem,", &p)) {
+#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
+ if (!strcmp(p, "native")) {
+ s->pe_subsystem = 1;
+ } else if (!strcmp(p, "console")) {
+ s->pe_subsystem = 3;
+ } else if (!strcmp(p, "gui")) {
+ s->pe_subsystem = 2;
+ } else if (!strcmp(p, "posix")) {
+ s->pe_subsystem = 7;
+ } else if (!strcmp(p, "efiapp")) {
+ s->pe_subsystem = 10;
+ } else if (!strcmp(p, "efiboot")) {
+ s->pe_subsystem = 11;
+ } else if (!strcmp(p, "efiruntime")) {
+ s->pe_subsystem = 12;
+ } else if (!strcmp(p, "efirom")) {
+ s->pe_subsystem = 13;
+#elif defined(TCC_TARGET_ARM)
+ if (!strcmp(p, "wince")) {
+ s->pe_subsystem = 9;
+#endif
+ } else {
+ return p;
+ }
+#endif
+
+ } else if (strstart(option, "-Ttext,", &p)) {
+ s->text_addr = strtoul(p, &end, 16);
+ s->has_text_addr = 1;
+
+ } else {
+ return option;
+ }
+
+ if (multi) {
+ if (end) {
+ option = end;
+ } else {
+ option = strchr(p, ',');
+ if (option) option++;
+ }
+ } else
+ option = NULL;
+ }
+ return NULL;
+}
+
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
{
double tt;