Re: [Tinycc-devel] Building a single cross-compiler: please test new configure
Using Michael's patch on Gentoo64: austin@aw25 ~/src/tinycc $ ./configure --targetcpu=i386 make Binary directory /usr/local/bin TinyCC directory/usr/local/lib/tcc Library directory /usr/local/lib Include directory /usr/local/include Manual directory/usr/local/share/man Info directory /usr/local/share/info Doc directory /usr/local/share/doc/tcc Target root prefix Source path /home/austin/src/tinycc C compiler gcc Build CPUx86_64 Target CPU i386 Target OSLinux Big Endian no gprof enabledno cross compilers yes use libgcc no Creating config.mak and config.h gcc -o i386-linux-gnu-tcc tcc.c -DONE_SOURCE -DTCC_TARGET_I386 -DCONFIG_TCCDIR=\/usr/local/lib/tcc/i386\ -I. -Wall -g -O2 -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -lm -ldl ln -sf i386-linux-gnu-tcc i386-tcc ar rcs libtcc.a make -C lib cross TARGET=i386 PROG_CROSS=i386-linux-gnu-tcc make[1]: Entering directory '/home/austin/src/tinycc/lib' mkdir -p i386 ../i386-linux-gnu-tcc -B.. -c libtcc1.c -o i386/libtcc1.o -I.. -Wall -g -O2 -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -fPIC -DTCC_TARGET_I386 ../i386-linux-gnu-tcc -B.. -c alloca86.S -o i386/alloca86.o -I.. -Wall -g -O2 -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -fPIC -DTCC_TARGET_I386 ../i386-linux-gnu-tcc -B.. -c alloca86-bt.S -o i386/alloca86-bt.o -I.. -Wall -g -O2 -fno-strict-aliasing -Wno-pointer-sign -Wno-sign-compare -Wno-unused-result -fPIC -DTCC_TARGET_I386 ar rcs i386/libtcc1.a i386/libtcc1.o i386/alloca86.o i386/alloca86-bt.o make[1]: Leaving directory '/home/austin/src/tinycc/lib' ./texi2pod.pl tcc-doc.texi tcc.pod pod2man --section=1 --center=Tiny C Compiler --release=`cat ./VERSION` tcc.pod tcc.1 makeinfo --no-split --html --number-sections -o tcc-doc.html tcc-doc.texi makeinfo tcc-doc.texi it builds fine, but make test fails: austin@aw25 ~/src/tinycc $ make test make -C tests test 'PROGS_CROSS=i386-linux-gnu-tcc' make[1]: Entering directory '/home/austin/src/tinycc/tests' hello-exe ../tcc -B.. -I.. -I.. -I../include ../examples/ex1.c -o hello || (../tcc -vv; exit 1) ./hello /bin/sh: ../tcc: No such file or directory /bin/sh: ../tcc: No such file or directory Makefile:76: recipe for target 'hello-exe' failed make[1]: *** [hello-exe] Error 1 make[1]: Leaving directory '/home/austin/src/tinycc/tests' Makefile:350: recipe for target 'test' failed make: *** [test] Error 2 not terribly surprising, but let's try symlinking to see if anything works: austin@aw25 ~/src/tinycc $ ln -s i386-linux-gnu-tcc tcc austin@aw25 ~/src/tinycc $ make test make -C tests test 'PROGS_CROSS=i386-linux-gnu-tcc' make[1]: Entering directory '/home/austin/src/tinycc/tests' hello-exe ../tcc -B.. -I.. -I.. -I../include ../examples/ex1.c -o hello || (../tcc -vv; exit 1) ./hello /usr/lib/crt1.o: error: invalid object file tcc: error: file 'crt1.o' not found /usr/lib/crti.o: error: invalid object file tcc: error: file 'crti.o' not found /lib64/libc.so.6: error: bad architecture /usr/lib/libc.so:3: error: unrecognized file type /usr/lib/libc.a: error: invalid object file tcc: error: file '../libtcc1.a' not found /usr/lib/crtn.o: error: invalid object file tcc: error: file 'crtn.o' not found tcc: error: undefined symbol 'printf' tcc version 0.9.26 (i386 Linux) install: /usr/local/lib/tcc/i386/ crt: /usr/lib libraries: /usr/lib /lib /usr/local/lib include: /usr/local/include /usr/include /usr/local/lib/tcc/i386/include elfinterp: /lib/ld-linux.so.2 Makefile:76: recipe for target 'hello-exe' failed make[1]: *** [hello-exe] Error 1 make[1]: Leaving directory '/home/austin/src/tinycc/tests' Makefile:350: recipe for target 'test' failed make: *** [test] Error 2 and indeed, trying to do anything with the compiler fails: austin@aw25 ~ $ cat foo.c #include stdio.h int main(void) { return 0; } austin@aw25 ~ $ gcc -o a foo.c ; ./a ; echo $? 0 austin@aw25 ~ $ clang -o a foo.c ; ./a ; echo $? 0 austin@aw25 ~ $ ~/src/tinycc/i386-tcc -o a foo.c ; ./a ; echo $? /usr/lib/crt1.o: error: invalid object file tcc: error: file 'crt1.o' not found /usr/lib/crti.o: error: invalid object file tcc: error: file 'crti.o' not found In file included from foo.c:1: /usr/include/stdio.h:33: error: include file 'stddef.h' not found 0 32-bit libs are in /lib32 /usr/lib32 On Thu, Apr 10, 2014 at 9:01 AM, Michael Matz matz@frakked.de wrote: Hello Thomas, On Wed, 9 Apr 2014, Thomas Preud'homme wrote: I have a patch to build a single cross-compiler by using --targetcpu but given the potential of breakage of the build script I prefer to post it here for now and ask you to try building tcc with it, either natively or all the cross compilers to see if anything break. You can also try building a single compiler to see if it works for you or take a look at the patch. Any feedback welcome.
Re: [Tinycc-devel] Building a single cross-compiler: please test new configure
Hello Thomas, On Wed, 9 Apr 2014, Thomas Preud'homme wrote: I have a patch to build a single cross-compiler by using --targetcpu but given the potential of breakage of the build script I prefer to post it here for now and ask you to try building tcc with it, either natively or all the cross compilers to see if anything break. You can also try building a single compiler to see if it works for you or take a look at the patch. Any feedback welcome. No cake yet, there are multiple problems. Some of them are fixed by the attached second version of that patch (which applies on top of current mob). The changes are: * inconsistent use of X64, x86_64 and x86-64. This now matters because sometimes directory names implies make targets and variables now. I've settled on x86_64, because from that we can infer also C macros * configure would unconditionally put #define TCC_TARGET_$ARCH in config.h. When building cross compilers that would define the native arch and the cross arch for the same executable. So go back to adding the right define in the Makefile * The correct spelling of the make function is 'filter-out' (not with underscore) * libtcc1.c needs access to size_t also for cross environment (no idea why it would be there before the patch), so include stddef.h With that patch the following works on an x86_64 host: % ./configure make make test and % linux32 ./configure CC=gcc -m32 \ sed -i -e 's/lib64/lib/' config.mak \ linux32 make CFLAGS=-g CC=gcc -m32 \ linux32 make CFLAGS=-g CC=gcc -m32 -k test I.e. the two native compilers for such host. Some host compilers compile as well: % ./configure --targetcpu=i386 make The resulting i386-tcc cannot build binaries (with ./i386-tcc -B./ because libtcc1.a isn't found (seems it's not searched in ./lib/i386). This works before the patch. Similar this other cross compiler: % linux32 ./configure CC=gcc -m32 --targetcpu=x86_64 make Produces a 32bit x86_64-tcc executable (correct), which can't link executables, because it searches in /usr/lib for crt[1in].o and doesn't find libgcc1.a Also: % ./configure --enable-cross make ... make -C lib cross TARGET=i386-win32 PROG_CROSS= make[1]: Entering directory `/matz/git/tinycc/lib' ../ -B../win32 -I../include -c libtcc1.c -o i386-win32/libtcc1.o -I.. -g -DTCC_TARGET_I386 -DTCC_TARGET_PE make[1]: execvp: ../: Permission denied make[1]: *** [i386-win32/libtcc1.o] Error 127 make[1]: Leaving directory `/matz/git/tinycc/lib' make: *** [lib/i386-win32/libtcc1.a] Error 2 This points to a general problem in how the Makefile infers some names for the compiler to build the target lib. You have: lib/%/libtcc1.a : FORCE $(filter $*%,$(PROGS_CROSS)) $(MAKE) -C lib cross TARGET=$* PROG_CROSS=$(filter $*%,$(PROGS_CROSS)) The '%' is i386, i386-win32, x86_64-win32, x86_64 and arm. But in $(PROGS_CROSS) there is only i386-w64-mingw32-tcc which doesn't match i386-win32. With arm it's even worse, because there we have four cross compilers in PROGS_CROSS, that all match arm%. So, that needs some more work still. I've attached the patch I have up to now (need to leave now). The result of interdiff of both patches (yours vs. mine) is below to easier see what exactly I've changed relative to yours. Thanks for starting to clean up the cross stuff. Ciao, Michael. - diff -u b/Makefile b/Makefile --- b/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP NATIVE_DEFINES += $(NATIVE_DEFINES_yes) +NATIVE_DEFINES += -DTCC_TARGET_$(ARCH) ifeq ($(TOP),.) @@ -74,7 +75,7 @@ WIN32_CROSS = i386-w64-mingw32-tcc$(EXESUF) WIN64_CROSS = x86_64-w64-mingw32-tcc$(EXESUF) WINCE_CROSS = arm-wince-mingw32ce-tcc$(EXESUF) -X64_CROSS = x86_64-linux-gnu-tcc$(EXESUF) +X86_64_CROSS = x86_64-linux-gnu-tcc$(EXESUF) ARM_FPA_CROSS = arm-linux-fpa-tcc$(EXESUF) ARM_FPA_LD_CROSS = arm-linux-fpa-ld-tcc$(EXESUF) ARM_VFP_CROSS = arm-linux-gnu-tcc$(EXESUF) @@ -88,7 +89,7 @@ $(WIN32_CROSS)_LINK = i386-win32-tcc$(EXESUF) $(WIN64_CROSS)_LINK = x86_64-win32-tcc$(EXESUF) $(WINCE_CROSS)_LINK = arm-win32-tcc$(EXESUF) -$(X64_CROSS)_LINK = x86_64-tcc$(EXESUF) +$(X86_64_CROSS)_LINK = x86_64-tcc$(EXESUF) $(ARM_FPA_CROSS)_LINK = arm-fpa-tcc$(EXESUF) $(ARM_FPA_LD_CROSS)_LINK = arm-fpa-ld-tcc$(EXESUF) $(ARM_VFP_CROSS)_LINK = arm-vfp-tcc$(EXESUF) @@ -107,7 +108,7 @@ I386_LIBTCC1_CROSS=lib/i386/libtcc1.a WIN32_LIBTCC1_CROSS=lib/i386-win32/libtcc1.a WIN64_LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a -X86_64_LIBTCC1_CROSS=lib/x86-64/libtcc1.a +X86_64_LIBTCC1_CROSS=lib/x86_64/libtcc1.a ARM_LIBTCC1_CROSS=lib/arm/libtcc1.a ifdef CONFIG_WIN64 @@ -116,7 +117,7 @@ ARCH=WIN32 endif -TARGET_ALL=WIN32 WIN64 I386 X64 ARM C67 +TARGET_ALL=WIN32 WIN64 I386 X86_64 ARM C67 ifdef TARGET_ARCH NATIVE_FILES= PROGS_CROSS=$($(TARGET_ARCH)_CROSS) @@ -125,8 +126,8 @@ else
[Tinycc-devel] Building a single cross-compiler: please test new configure
I have a patch to build a single cross-compiler by using --targetcpu but given the potential of breakage of the build script I prefer to post it here for now and ask you to try building tcc with it, either natively or all the cross compilers to see if anything break. You can also try building a single compiler to see if it works for you or take a look at the patch. Any feedback welcome. Best regards, Thomasdiff --git a/Makefile b/Makefile index 4f18567..82971e5 100644 --- a/Makefile +++ b/Makefile @@ -61,12 +61,8 @@ LIBTCC=libtcc.a LINK_LIBTCC= endif -CONFIG_$(ARCH) = yes -NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 -NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64 NATIVE_DEFINES_$(CONFIG_WIN32) += -DTCC_TARGET_PE NATIVE_DEFINES_$(CONFIG_uClibc) += -DTCC_UCLIBC -NATIVE_DEFINES_$(CONFIG_arm) += -DTCC_TARGET_ARM NATIVE_DEFINES_$(CONFIG_arm_eabihf) += -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT NATIVE_DEFINES_$(CONFIG_arm_eabi) += -DTCC_ARM_EABI NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP @@ -74,7 +70,6 @@ NATIVE_DEFINES += $(NATIVE_DEFINES_yes) ifeq ($(TOP),.) -PROGS=tcc$(EXESUF) I386_CROSS = i386-linux-gnu-tcc$(EXESUF) WIN32_CROSS = i386-w64-mingw32-tcc$(EXESUF) WIN64_CROSS = x86_64-w64-mingw32-tcc$(EXESUF) @@ -109,33 +104,30 @@ X86_64_FILES = $(CORE_FILES) x86_64-gen.c i386-asm.c x86_64-asm.h ARM_FILES = $(CORE_FILES) arm-gen.c C67_FILES = $(CORE_FILES) c67-gen.c tcccoff.c +I386_LIBTCC1_CROSS=lib/i386/libtcc1.a +WIN32_LIBTCC1_CROSS=lib/i386-win32/libtcc1.a +WIN64_LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a +X86_64_LIBTCC1_CROSS=lib/x86-64/libtcc1.a +ARM_LIBTCC1_CROSS=lib/arm/libtcc1.a + ifdef CONFIG_WIN64 -PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF) -NATIVE_FILES=$(WIN64_FILES) -PROGS_CROSS=$(WIN32_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS) -LIBTCC1_CROSS=lib/i386-win32/libtcc1.a -LIBTCC1=libtcc1.a +ARCH=WIN64 else ifdef CONFIG_WIN32 -PROGS+=tiny_impdef$(EXESUF) tiny_libmaker$(EXESUF) -NATIVE_FILES=$(WIN32_FILES) -PROGS_CROSS=$(WIN64_CROSS) $(I386_CROSS) $(X64_CROSS) $(ARM_CROSS) $(C67_CROSS) -LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a -LIBTCC1=libtcc1.a -else ifeq ($(ARCH),i386) -NATIVE_FILES=$(I386_FILES) -PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS) -LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a -LIBTCC1=libtcc1.a -else ifeq ($(ARCH),x86-64) -NATIVE_FILES=$(X86_64_FILES) -PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS) -LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a -LIBTCC1=libtcc1.a -else ifeq ($(ARCH),arm) -NATIVE_FILES=$(ARM_FILES) -PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(C67_CROSS) +ARCH=WIN32 +endif + +TARGET_ALL=WIN32 WIN64 I386 X64 ARM C67 +ifdef TARGET_ARCH +NATIVE_FILES= +PROGS_CROSS=$($(TARGET_ARCH)_CROSS) +LIBTCC1_CROSS=$($(TARGET_ARCH)_LIBTCC1_CROSS) +LIBTCC1= +else +PROGS=tcc$(EXESUF) +NATIVE_FILES=$($(ARCH)_FILES) +PROGS_CROSS=$(foreach CROSS_ARCH,$(filter_out $(ARCH),$(TARGET_ALL)),$($(CROSS_ARCH)_CROSS)) +LIBTCC1_CROSS=$(foreach CROSS_ARCH,$(filter_out $(ARCH),$(TARGET_ALL)),$($(CROSS_ARCH)_LIBTCC1_CROSS)) LIBTCC1=libtcc1.a -LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a lib/i386/libtcc1.a endif PROGS_CROSS_LINK=$(foreach PROG_CROSS,$(PROGS_CROSS),$($(PROG_CROSS)_LINK)) @@ -168,7 +160,8 @@ tcc_p$(EXESUF): $(NATIVE_FILES) $(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \ -DCONFIG_TCCDIR=\$(tccdir)/i386\ -$(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64 +$(X64_CROSS): DEFINES = -DTCC_TARGET_X86_64 \ +-DCONFIG_TCCDIR=\$(tccdir)/x86-64\ $(WIN32_CROSS): DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \ -DCONFIG_TCCDIR=\$(tccdir)/win32\ \ -DCONFIG_TCC_LIBPATHS=\{B}/lib/32;{B}/lib\ @@ -176,6 +169,8 @@ $(WIN64_CROSS): DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \ -DCONFIG_TCCDIR=\$(tccdir)/win32\ \ -DCONFIG_TCC_LIBPATHS=\{B}/lib/64;{B}/lib\ $(WINCE_CROSS): DEFINES = -DTCC_TARGET_PE +$(ARM_CROSS): DEFINES = -DTCC_TARGET_ARM \ +-DCONFIG_TCCDIR=\$(tccdir)/arm\ $(C67_CROSS): DEFINES = -DTCC_TARGET_C67 $(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM $(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12 @@ -227,8 +222,8 @@ tiny_libmaker$(EXESUF): win32/tools/tiny_libmaker.c # TinyCC runtime libraries libtcc1.a : FORCE $(MAKE) -C lib native -lib/%/libtcc1.a : FORCE $(PROGS_CROSS) - $(MAKE) -C lib cross TARGET=$* +lib/%/libtcc1.a : FORCE $(filter $*%,$(PROGS_CROSS)) + $(MAKE) -C lib cross TARGET=$* PROG_CROSS=$(filter $*%,$(PROGS_CROSS)) FORCE: @@ -273,18 +268,24 @@ endif mkdir -p $(docdir) -$(INSTALL) -m644 tcc-doc.html $(docdir) ifdef CONFIG_CROSS + for libpath in $(LIBTCC1_CROSS) ; do \ + libdir=$${libpath%/libtcc1.a} ; \ + $(INSTALL) -m644 $$libdir $(tccdir) ; \ + cp -r $(tccdir)/include $(tccdir)/$${libdir#lib/} ; \ + done +ifneq (,$(findstring $(WIN32_LIBTCC1_CROSS),$(LIBTCC1_CROSS))) mkdir -p