History

tccpe.c: never assume static system libtaries

just clear s1->static_link before loading msvcrt etc. Also: - configure: get cc_version/name when making a cross compiler too - configure: fix android triplets - Makefile: remove CONFIG_TCC_CROSS, check TCC_TARGET_xxx instead - libtcc.c: parse some linker option arguments more correctly - tccelf.c: fix a versym problem with clang on android - lib/Makefile, build-tcc.bat: bcheck.c now includes config.h

grischka committed 1 year ago

Commit a5222131 parent 31582878 files · +63 −48Browse files

Unified · Split

8 files
  1. Makefile +3 −2
  2. configure +27 −21
  3. lib/Makefile +2 −2
  4. libtcc.c +17 −18
  5. tccelf.c +11 −3
  6. tccpe.c +1 −0
  7. tests/Makefile +1 −1
  8. win32/build-tcc.bat +1 −1
Makefile+3−2
@@ -169,7 +169,6 @@ DEFINES += $(DEF-$(or $(findstring win,$T),unx)) · 168 unmodified lines
169169
170170 ifneq ($(X),)
171171 $(if $(DEF-$T),,$(error error: unknown target: '$T'))
172−DEF-$T += -DCONFIG_TCC_CROSS
173172 DEF-$(NATIVE_TARGET) =
174173 DEF-$T += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
175174 ifneq ($(CONFIG_WIN32),yes)
@@ -234,7 +233,9 @@ LIBTCC_INC = $(filter %.h %-gen.c %-link.c,$($T_FILES)) · 58 unmodified lines
234233 TCC_FILES = $(X)tcc.o $(LIBTCC_OBJ)
235234 $(X)tccpp.o : $(TCCDEFS_H)
236235 $(X)libtcc.o : DEFINES += -DONE_SOURCE=0
236+$(CROSS_TARGET)-tcc.o : DEFINES += -DONE_SOURCE=0
237237 endif
238+# native tcc always made from tcc.o and libtcc.[so|a]
238239 tcc.o : DEFINES += -DONE_SOURCE=0
239240 DEFINES += -I$(TOP)
240241
@@ -464,7 +465,7 @@ tcov-tes% : tcc_c$(EXESUF) · 223 unmodified lines
464465 tcc_c$(EXESUF): $($T_FILES)
465466 $S$(TCC) tcc.c -o $@ -ftest-coverage $(DEFINES) $(LIBS)
466467 # test the installed tcc instead
467−test-install: tccdefs_.h
468+test-install: $(TCCDEFS_H)
468469 @$(MAKE) -C tests TESTINSTALL=yes #_all
469470
470471 clean:
configure+27−21
@@ -384,12 +384,12 @@ case $targetos in · 383 unmodified lines
384384 confvars_set Android new_dtags rpath=no
385385 test "${cpu}" != "i386" && confvars_set pie
386386 default_conf "static=no"
387− if test "${cpu}" = "arm"; then
388− default triplet "arm-linux-androideabi"
389− cpuver=7
390− else
391− default triplet "${cpu}-linux-android"
392− fi
387+ case "$cpu" in
388+ arm) default triplet "arm-linux-androideabi"; cpuver=7 ;;
389+ arm64) default triplet "aarch64-linux-android" ;;
390+ x86_64) default triplet "x86_64-linux-android" ;;
391+ i386) default triplet "i686-linux-android" ;;
392+ esac
393393 test "${cpu%64}" != "${cpu}" && S="64" || S=""
394394 default tcc_sysincludepaths "{B}/include:{R}/include:{R}/include/${triplet}"
395395 default tcc_libpaths "{B}:{R}/lib:/system/lib${S}"
@@ -438,17 +438,27 @@ if test x"$show_help" = "xyes" ; then · 42 unmodified lines
438438 show_help
439439 fi
440440
441−if test -z "$build_cross"; then
442− CONFTEST=./conftest$EXESUF
443− if ! $cc -o $CONFTEST "$source_path/conftest.c" ; then
441+CONFTEST=./conftest$EXESUF
442+if test -z "$cross_prefix" \
443+ && $cc -o $CONFTEST "$source_path/conftest.c" \
444+ && $CONFTEST 2>/dev/null; then
445+ cc_name="$($CONFTEST compiler)"
446+ gcc_major="$($CONFTEST version)"
447+ gcc_minor="$($CONFTEST minor)"
448+else
449+ if test -z "$build_cross"; then
444450 echo "configure: error: '$cc' failed to compile conftest.c."
445− else
446− cc_name="$($CONFTEST compiler)"
447− gcc_major="$($CONFTEST version)"
448− gcc_minor="$($CONFTEST minor)"
449− bigendian="$($CONFTEST bigendian)"
450− _triplet="$($CONFTEST triplet)"
451451 fi
452+ if test "${cc%tcc*}" != "$cc"; then
453+ cc_name="tcc"
454+ elif test "${cc%clang*}" != "$cc"; then
455+ cc_name="clang"
456+ fi
457+fi
458+
459+if test -z "$build_cross"; then
460+ bigendian="$($CONFTEST bigendian)"
461+ _triplet="$($CONFTEST triplet)"
452462 if test "$mingw32" = "no" ; then
453463 if test -z "$triplet" && test -n "$_triplet"; then
454464 if test -f "/usr/lib/$_triplet/crti.o"; then
@@ -473,11 +483,6 @@ if test -z "$build_cross"; then · 18 unmodified lines
473483 fi
474484 else
475485 # can only make guesses about compiler and target
476− if test "${cc%tcc*}" != "$cc"; then
477− cc_name="tcc"
478− elif test "${cc%clang*}" != "$cc"; then
479− cc_name="clang"
480− fi
481486 case $cpu in
482487 ppc|mips|s390) bigendian=yes;;
483488 esac
@@ -619,7 +624,8 @@ cat >$TMPH <<EOF · 135 unmodified lines
619624 #define GCC_MAJOR $gcc_major
620625 #define GCC_MINOR $gcc_minor
621626
622−#if !CONFIG_TCC_CROSS
627+#if !(TCC_TARGET_I386 || TCC_TARGET_X86_64 || TCC_TARGET_ARM\
628+ || TCC_TARGET_ARM64 || TCC_TARGET_RISCV64 || TCC_TARGET_C67)
623629 EOF
624630
625631 predefs=1
lib/Makefile+2−2
@@ -16,7 +16,7 @@ XCC = $(XTCC) · 15 unmodified lines
1616 XAR = $(XTCC) -ar
1717 XFLAGS-unx = -B$(TOPSRC)
1818 XFLAGS-win = -B$(TOPSRC)/win32 -I$(TOPSRC)/include
19−XFLAGS = $(XFLAGS$(XCFG)) -I$(TOP)
19+XFLAGS = $(XFLAGS$(XCFG))
2020 BFLAGS = -bt
2121
2222 # in order to use gcc, type: make <target>-libtcc1-usegcc=yes
@@ -91,7 +91,7 @@ $(X)%.o : %.S $(TCC) · 68 unmodified lines
9191 $(TOP)/%.o : %.c $(TCC)
9292 $S$(XCC) -c $< -o $@ $(XFLAGS)
9393
94−$(TOP)/bcheck.o : XFLAGS += $(BFLAGS)
94+$(TOP)/bcheck.o : XFLAGS += $(BFLAGS) -I$(TOP)
9595 $(TOP)/bt-exe.o : $(TOP)/tccrun.c
9696
9797 $(X)crt1w.o : crt1.c
libtcc.c+17−18
@@ -1194,11 +1194,9 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) · 1193 unmodified lines
11941194 /* find [cross-]libtcc1.a and tcc helper objects in library path */
11951195 ST_FUNC int tcc_add_support(TCCState *s1, const char *filename)
11961196 {
1197−#if CONFIG_TCC_CROSS
11981197 char buf[100];
11991198 if (CONFIG_TCC_CROSSPREFIX[0])
12001199 filename = strcat(strcpy(buf, CONFIG_TCC_CROSSPREFIX), filename);
1201−#endif
12021200 return tcc_add_dll(s1, filename, AFF_PRINT_ERROR);
12031201 }
12041202
@@ -1234,11 +1232,6 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname) · 29 unmodified lines
12341232 return ret;
12351233 ++pp;
12361234 }
1237−#if CONFIG_TCC_CROSS
1238− /* hack for '<cross>-tcc -nostdlib -ltcc1' to find <cross>-libtcc1.a */
1239− if (0 == strcmp(libraryname, "tcc1"))
1240− return tcc_add_support(s, TCC_LIBTCC1);
1241−#endif
12421235 return tcc_add_dll(s, libraryname, AFF_PRINT_ERROR);
12431236 }
12441237
@@ -1343,6 +1336,12 @@ static int link_option(const char *str, const char *val, const char **ptr) · 98 unmodified lines
13431336 return ret;
13441337 }
13451338
1339+static int link_arg(const char *opt, const char *str)
1340+{
1341+ int l = strlen(opt);
1342+ return 0 == strncmp(opt, str, l) && (str[l] == '\0' || str[l] == ',');
1343+}
1344+
13461345 static const char *skip_linker_arg(const char **str)
13471346 {
13481347 const char *s1 = *str;
@@ -1410,10 +1409,10 @@ static int tcc_set_linker(TCCState *s, const char *option) · 61 unmodified lines
14101409 if (strstart("elf32-", &p)) {
14111410 #endif
14121411 s->output_format = TCC_OUTPUT_FORMAT_ELF;
1413− } else if (!strcmp(p, "binary")) {
1412+ } else if (link_arg("binary", p)) {
14141413 s->output_format = TCC_OUTPUT_FORMAT_BINARY;
14151414 #ifdef TCC_TARGET_COFF
1416− } else if (!strcmp(p, "coff")) {
1415+ } else if (link_arg("coff", p)) {
14171416 s->output_format = TCC_OUTPUT_FORMAT_COFF;
14181417 #endif
14191418 } else
@@ -1446,24 +1445,24 @@ static int tcc_set_linker(TCCState *s, const char *option) · 26 unmodified lines
14461445 s->pe_stack_size = strtoul(p, &end, 10);
14471446 } else if (link_option(option, "subsystem=", &p)) {
14481447 #if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
1449− if (strstart("native", &p)) {
1448+ if (link_arg("native", p)) {
14501449 s->pe_subsystem = 1;
1451− } else if (strstart("console", &p)) {
1450+ } else if (link_arg("console", p)) {
14521451 s->pe_subsystem = 3;
1453− } else if (strstart("gui", &p) || strstart("windows", &p)) {
1452+ } else if (link_arg("gui", p) || link_arg("windows", p)) {
14541453 s->pe_subsystem = 2;
1455− } else if (strstart("posix", &p)) {
1454+ } else if (link_arg("posix", p)) {
14561455 s->pe_subsystem = 7;
1457− } else if (strstart("efiapp", &p)) {
1456+ } else if (link_arg("efiapp", p)) {
14581457 s->pe_subsystem = 10;
1459− } else if (strstart("efiboot", &p)) {
1458+ } else if (link_arg("efiboot", p)) {
14601459 s->pe_subsystem = 11;
1461− } else if (strstart("efiruntime", &p)) {
1460+ } else if (link_arg("efiruntime", p)) {
14621461 s->pe_subsystem = 12;
1463− } else if (strstart("efirom", &p)) {
1462+ } else if (link_arg("efirom", p)) {
14641463 s->pe_subsystem = 13;
14651464 #elif defined(TCC_TARGET_ARM)
1466− if (strstart("wince", &p)) {
1465+ if (link_arg("wince", p)) {
14671466 s->pe_subsystem = 9;
14681467 #endif
14691468 } else
tccelf.c+11−3
@@ -582,17 +582,24 @@ version_add (TCCState *s1) · 581 unmodified lines
582582 for (sym_index = 1; sym_index < end_sym; ++sym_index) {
583583 int dllindex, verndx;
584584 sym = &((ElfW(Sym) *)symtab->data)[sym_index];
585− if (sym->st_shndx != SHN_UNDEF)
586− continue; /* defined symbol doesn't need library version */
587585 name = (char *) symtab->link->data + sym->st_name;
588586 dllindex = find_elf_sym(s1->dynsymtab_section, name);
589587 verndx = (dllindex && dllindex < nb_sym_to_version)
590588 ? sym_to_version[dllindex] : -1;
591− if (verndx >= 0) {
589+ if (verndx >= 0
590+ /* XXX: on android, clang refuses to link with a libtcc.so made by tcc
591+ when defined symbols have a version > 1 or when the version is '0'.
592+ Whereas version '1' for example for 'signal' in an exe defeats
593+ bcheck's signal_redir. */
594+ && (sym->st_shndx == SHN_UNDEF || (s1->output_type & TCC_OUTPUT_EXE))
595+ ) {
592596 if (!sym_versions[verndx].out_index)
593597 sym_versions[verndx].out_index = nb_versions++;
594598 versym[sym_index] = sym_versions[verndx].out_index;
599+ } else {
600+ versym[sym_index] = 1; /* (*global*) */
595601 }
602+ //printf("SYM %d %s\n", versym[sym_index], name);
596603 }
597604 /* generate verneed section, but not when it will be empty. Some
598605 dynamic linkers look at their contents even when DTVERNEEDNUM and
@@ -631,6 +638,7 @@ version_add (TCCState *s1) · 32 unmodified lines
631638 sv->out_index = -2;
632639 vna->vna_name = put_elf_str(verneed_section->link, sv->version);
633640 vna->vna_next = sizeof (*vna);
641+ //printf("LIB %d %s %s\n", vna->vna_other, sv->lib, verneed_section->link->data + vna->vna_name);
634642 n_same_libs++;
635643 }
636644 if (prev >= 0)
tccpe.c+1−0
@@ -1909,6 +1909,7 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe) · 1908 unmodified lines
19091909 const char * const *pp, *p;
19101910 if (TCC_LIBTCC1[0])
19111911 tcc_add_support(s1, TCC_LIBTCC1);
1912+ s1->static_link = 0; /* no static crt for tcc */
19121913 for (pp = libs; 0 != (p = *pp); ++pp) {
19131914 if (*p)
19141915 tcc_add_library(s1, p);
tests/Makefile+1−1
@@ -318,7 +318,7 @@ CROSS-TGTS = \ · 317 unmodified lines
318318
319319 define CROSS-COMPILE
320320 @echo " . $(1)"
321− $(TCC) $(DEF-$1) -DCONFIG_TCC_CROSS -DTCC_CROSS_TEST -run $(TOPSRC)/tcc.c \
321+ $(TCC) $(DEF-$1) -DTCC_CROSS_TEST -run $(TOPSRC)/tcc.c \
322322 -c $(if $(findstring c67,$1),$(filter %/ex3.c,$^),$<) -w $(TCCFLAGS)
323323
324324 endef
win32/build-tcc.bat+1−1
@@ -201,7 +201,7 @@ exit /B %ERRORLEVEL% · 200 unmodified lines
201201 .\tcc -B. -m%1 -c ../lib/alloca-bt.S
202202 .\tcc -B. -m%1 -c ../lib/stdatomic.c
203203 .\tcc -B. -m%1 -ar lib/%2libtcc1.a libtcc1.o crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o alloca.o alloca-bt.o stdatomic.o
204−.\tcc -B. -m%1 -c ../lib/bcheck.c -o lib/%2bcheck.o -bt
204+.\tcc -B. -m%1 -c ../lib/bcheck.c -o lib/%2bcheck.o -bt -I..
205205 .\tcc -B. -m%1 -c ../lib/bt-exe.c -o lib/%2bt-exe.o
206206 .\tcc -B. -m%1 -c ../lib/bt-log.c -o lib/%2bt-log.o
207207 .\tcc -B. -m%1 -c ../lib/bt-dll.c -o lib/%2bt-dll.o

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t