[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] libtcc (dll) doesn't work for memory output...

From: grischka
Subject: Re: [Tinycc-devel] libtcc (dll) doesn't work for memory output...
Date: Tue, 10 Sep 2013 16:07:29 +0200
User-agent: Thunderbird (Windows/20090812)

Gabriel Corneanu wrote:

I am using libtcc to generate some dynamic code; simple example:

int foo(int n1, int n2){ return n1+n2; }

It used to work using tcc_set_options(FState, "-nostdlib"), tcc_compile_string, tcc_get_symbol("foo") then call it...

The current state doesn't work anymore like before...

1. "nostdlib" is not properly used somewhere in pe_output_file / pe_add_runtime; it always searches for some startup code (start_symbol). the error is 'tcc: error: _runmain not defined', and then it calls tcc_error as explained at #2 (exit!) 2. some compile errors (see #1) reach "tcc_error" where error_set_jmp_enabled is 0, therefore terminating my program!

I modified pe_output_file by using
if(!s1->nostdlib) pe_add_runtime(s1, &pe);
This seems to work for me, but I'm not sure if it's the best solution.
E.g if I still need the stdlib for "printf", I get back to the same problem

3. Why do I NEED a startup code for memory output? I extract my symbols and call the functions directly.
The workaround is to have dummy "runmain", and "main" ...

Yes, there is the problem because for TCC_OUTPUT_MEMORY the
pe_add_runtime() function is supposed to serve two different
cases, that is
1) "tcc -run" or tcc_run() (which is expected to define main)
2) usage of libtcc with custom function as in libtcc_test.
Unfortunately pe_add_runtime() cannot know whether 1) or 2) is

Anyway, it should now work again as it did before:

There are probably still some odd cases, for example you cannot
use -nostdlib and still link the startup code from libtcc1, as
    tcc foo.c -nostdlib -ltcc1

--- grischka


reply via email to

[Prev in Thread] Current Thread [Next in Thread]