Re: [Tinycc-devel] Building a single cross-compiler: please test new configure

2014-04-11 Thread Austin English
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

2014-04-10 Thread Michael Matz
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