Uhm, that is not exactly the 5 lines isolated bug test case we'd wish.

Thanks anyway.  Please retry.

FYI, the offending line was tccpe.c:1184

    *(DWORD*)(s->data + rel->r_offset) += addr - pe->imagebase;

and what happens here is that tcc is trying to create code for adding
PTR s->data and long long r_offset which, for 32bit targets, didn't
work well at all.

--- grischka

avih wrote:
When using native tcc (32) to build tcc cross compilers, the resulting tcc 
cross compiler to windows x86_64 crashes when trying to create an executable. 
However, if using gcc (32) to build tcc cross compilers, the resulting tcc 
cross compiler to windows x86_64 seems to work. Compile-only seems to work and 
create identical object files, and libtcc1.a is also identical between the two 
cross compilers.

The long versions and steps to reproduce, from scratch if you need:
Setup msys2, build env and tcc:

1. Download and install msys2 from http://msys2.github.io/ (I got 
msys2-x86_64-20160921.exe) - can be used for native 32 or 64 gcc
2. Possibly follow the instructions to self-update (you may need to kill a 
stray pacman.exe process after closing the terminal)
3. Install required tools: pacman -S --force git make diffutils texinfo 
   * due to bug at the current installer, the first 32 and 64 installs require 
--force: https://github.com/Alexpux/MSYS2-packages/issues/689

4. Close the terminal and open the mingw 32 shell environment: double click 

5. Get tcc: cd /c/ && git clone git://repo.or.cz/tinycc.git

Builds, tests and installs should complete successfully (assuming tcc was 
cloned to /c/tinycc):

6. Build (with gcc i686)/test/install native tcc 32 and cross compilers. Needs 
--cpu since `uname -m` reports x86_64 (on a 64 system):
   cd /c/tinycc && mkdir with-gcc32 && cd with-gcc32 && ../configure --cpu=i386 --enable-cross 
--prefix=$(pwd)/dist && make && make test && make install

7. Build/test/install native tcc 32 and cross compilers again, now using the 
newly built tcc 32 (it's fast! yay!):
   cd /c/tinycc && mkdir with-tcc32 && cd with-tcc32 && ../configure --cpu=i386 --enable-cross 
--prefix=$(pwd)/dist --cc=/c/tinycc/with-gcc32/dist/tcc.exe --ar=/c/tinycc/with-gcc32/dist/tiny_libmaker.exe && make 
&& make test && make install

The bug:

8. Create a test file: cd /c/tinycc && echo "int main(int argc, char **argv) { return 
argc - 1; }" > test.c

9. Build the test file with x86_64-win32-tcc.exe which was built using gcc: 
./with-gcc32/dist/x86_64-win32-tcc.exe test.c
   - The build succeeds and the resulting test.exe is functional, e.g. this 
prints 3: ./test.exe 1 2 3; echo $?

10 Same as above but using x86_64-win32-tcc.exe which was built using tcc: 
./with-tcc32/dist/x86_64-win32-tcc.exe test.c
   - crash/segmentation fault


- Both compilers can run and report expected paths: 
./with-{g|t}cc32/dist/x86_64-win32-tcc.exe -vv
- The lib objects (which were compiled with the respective 
x86_64-win32-tcc.exe) and the resulting libtcc1.a are identical at 
./with-{g|t}cc32/lib/x86_64-win32/ and at ./with-{g|t}cc32/dist/lib/64
- Compile only (-c) of the test file works and creates identical test.o with 
both cross compilers.  - The one with gcc succeeds link: 
`./with-gcc32/dist/x86_64-win32-tcc.exe -o test.exe test.o`
  - The one with tcc crashes: `./with-tcc32/dist/x86_64-win32-tcc.exe -o 
test.exe test.o`

Tinycc-devel mailing list

Reply via email to