tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Hello and a few questions about using libtcc


From: Joshua Scholar
Subject: [Tinycc-devel] Hello and a few questions about using libtcc
Date: Sun, 20 Dec 2020 06:02:38 -0800

Hi. I just joined this list.  

It feels a bit rude just barging in with questions here I go.

I would like to use libtcc to implement a jit so I have a few questions.
First a couple questions about the library's API, and then a couple on the generated code.

On the api:
1) If I've generated some code into a memory buffer and I've retrieved an entry point with tcc_get_symbol, is it safe to call tcc_delete_state before I call the entry point?  Looking at the source code, it looks like tcc_delete_state deletes some things that you don't need at run-time.

2) If you use TCC_RELOCATE_AUTO, does tcc ever delete that memory for you?  Does  tcc_delete_state delete the generated code?  I do realize that if I supply a buffer myself, I have to make it executable myself, but then I can also know that I can delete it.

3) Does the tcc compiler allocate space for a stack?  Or is it that when you call into code it generated, it uses your current stack? Or is there a difference between tcc_run and just calling a function you got back from tcc_get_symbol, where tcc_run allocates its own stack? 

3 a) I noticed that there's a bounds checking version of alloca, but I couldn't understand it.  Does this imply an answer to my previous question, that TCC DOES allocate its own stack? Generally operating systems expand user stacks as needed, up to a point, so bounds checking a stack doesn't make a lot of sense.

4) Is it possible to reuse a TCCState? What would it do?  Would it trash the code already generated?  Would it remember symbols from previous compiles?

5) Is the compiler thread safe?  While it would be surprising, I might as well ask if you can compile multiple sources at once.

Now questions about generated code.  The jit I'm hoping to make is for a language that's embarrassingly parallel, so I need to know how the generated code works with threads and stacks and contexts.

1) The simplest thing, what's the calling convention of generated functions?  On 64 bit windows?  On 64 bit Linux? 

2)  Is the TCC runtime multithread safe?
a) And what are the details?  Can I run generated code in multiple threads at once?  Does it use locks for anything?
Is it at least as thread safe as C usually is, ie, you can do anything that doesn't involve a shared buffer like an implicit error string. Would it be fine as long as I put a critical section around some non-thread safe part?

3) Does the run time library use thread local storage?  

4) If I did something weird like have a call out from generated code to my code, and my code returned on the same stack but in the context of a different thread than it entered from, would that break anything?

5) Some systems are broken by fibers, ie, if I switched between generated code, each using a different stack, but in the same thread, would that break anything?

6) Are there any pointers on how to use the built in assembler?

Thanks,

Joshua Scholar

reply via email to

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