Skip to content

compile and run test programs in separate steps#10

Closed
calid wants to merge 3 commits intorun4flat:masterfrom
calid:tinycc-run-segfault
Closed

compile and run test programs in separate steps#10
calid wants to merge 3 commits intorun4flat:masterfrom
calid:tinycc-run-segfault

Conversation

@calid
Copy link

@calid calid commented Jan 6, 2016

When both installing from cpan and when running tests out of the github repo proper I am getting segfaults. There seems to be either a race condition or other problem with tcc -run, as it is segfaulting when trying to invoke the program main.

This PR changes the test logic to split test program compilation and execution into two separate steps. This seems to avoid the problem.

My environment:

Fedora 21, x86_64, 12GB RAM
Perl 5.18.4

$ pwd
/home/dylan.cali/git/Alien-TinyCC
$ ulimit -c 99999
$ export CFLAGS=-g3
$ perl Build.PL
...
$ ./Build
...
$ ./Build test
t/10-path-tests.t ...... ok
t/20-tcc-exec.t ........ 1/?
#   Failed test 'tcc compiled the code correctly'
#   at t/20-tcc-exec.t line 32.
#          got: ''
#     expected: 'Good to go'
# tcc printed []
# tcc configuration:
# install: /home/dylan.cali/git/Alien-TinyCC/share/lib/tcc/
# crt:
#   /usr/lib64/
# libraries:
#   /usr/lib64/
#   /usr/lib64
#   /lib64/
#   /lib64
#   /usr/local/lib64/
#   /usr/local/lib64
# include:
#   /usr/local/include/
#   /usr/local/include
#   /usr/include/
#   /usr/include
#   /home/dylan.cali/git/Alien-TinyCC/share/lib/tcc/include
# elfinterp:
#   /lib64/ld-linux-x86-64.so.2
# Looks like you failed 1 test of 1.
t/20-tcc-exec.t ........ Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests
t/30-tcc-test-suite.t .. 1/?
#   Failed test 'tcc test src/tests/tests2/00_assignment.c'
#   at t/30-tcc-test-suite.t line 79.
#          got: ''
#     expected: '42
#64
#12, 34'

#   Failed test 'tcc test src/tests/tests2/01_comment.c'
#   at t/30-tcc-test-suite.t line 79.
#          got: ''
#     expected: 'Hello
# Hello
# Hello
# Hello
# Hello'
...
# many more errors with got: '', expected '<something>'

$ ls
blib        core.18468  core.18480  core.18492  core.18504              lib
_build      core.18469  core.18481  core.18493  core.18505              MANIFEST
Build       core.18470  core.18482  core.18494  core.18506              MYMETA.json
Build.PL    core.18471  core.18483  core.18495  core.18507              MYMETA.yml
Changes     core.18472  core.18484  core.18496  core.18508              README.pod
core.18456  core.18473  core.18485  core.18497  core.18509              share
core.18462  core.18474  core.18486  core.18498  core.18510              src
core.18463  core.18475  core.18487  core.18499  core.18511              t
core.18464  core.18476  core.18488  core.18500  core.18512
core.18465  core.18477  core.18489  core.18501  core.18513
core.18466  core.18478  core.18490  core.18502  git-pre-commit-hook.pl
core.18467  core.18479  core.18491  core.18503  inc

digging into the core files with gdb you can see the explosion is occuring when trying to invoke the program main.

$ gdb ./share/bin/tcc core.18456
(gdb) bt
#0  0x000000000069ea50 in ?? ()
#1  0x0000000000420c21 in tcc_run (s1=0x672010, argc=1, argv=0x7ffc100c9c68) at tccrun.c:123
#2  0x00000000004020e6 in main (argc=3, argv=0x7ffc100c9c58) at tcc.c:332
(gdb) up
123             ret = (*prog_main)(argc, argv)

The ?? () indicates to me the program main is either not found or not available when tcc_run tries to invoke it. I'm not sure of the cause, but doing compilation and execution in separate steps avoids the problem.

avoids potential segfault when using tcc -run directly
@calid
Copy link
Author

calid commented Jan 6, 2016

I forgot to mention, another reason I think it is a race condition is because I can't reproduce the segfault when running tcc -run under gdb directly:

$ ./share/bin/tcc -run src/tests/tests2/00_assignment.c
Segmentation fault
$ gdb --args ./share/bin/tcc -run src/tests/tests2/00_assignment.c
Reading symbols from ./share/bin/tcc...done.
(gdb) r
Starting program: /home/dylan.cali/.cpanm/work/1452086502.26224/Alien-TinyCC-0.06/share/bin/tcc -run src/tests/tests2/00_assignment.c
42
64
12, 34
[Inferior 1 (process 15234) exited normally]
(gdb)

calid added 2 commits January 6, 2016 10:35
otherwise arg 0 won't match, e.g. 'arg 0: ./31_args.c' instead of
'arg 0: 31_args.c'
@calid
Copy link
Author

calid commented Jan 6, 2016

after further thought, this doesn't really solve anything since tcc -run will still fail in other contexts, so this is really just a way to install a broken tcc on my machine.

I need to just figure out why tcc -run is failing on my machine and fix it.

@run4flat
Copy link
Owner

run4flat commented May 5, 2016

@calid,

It turns out that tcc cannot produce Mach-O executables on Mac, so the tests must run with tcc -run, at least on Macs. This means I'll need to figure out whey tcc -run was failing, instead of avoiding it. But it seems you've reached the same conclusion. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants