tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Help with tcc_add_symbol // pe_find_import in 0.9.27


From: Christian Jullien
Subject: Re: [Tinycc-devel] Help with tcc_add_symbol // pe_find_import in 0.9.27
Date: Tue, 21 Jun 2022 15:50:26 +0200

Hello Michael,

 

=> http://download.savannah.gnu.org/releases/tinycc/

 

is really quite old, I doubt you’ll get any help from this list unless you use mob https://repo.or.cz/w/tinycc.git

 

C.

 

 

From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=orange.fr@nongnu.org] On Behalf Of Michael Richter
Sent: Tuesday, June 21, 2022 12:38
To: tinycc-devel@nongnu.org
Subject: [Tinycc-devel] Help with tcc_add_symbol // pe_find_import in 0.9.27

 

Hello,

I'm actually trying to port tcc4tcl from 0.9.26 to 0.9.27. (See https://wiki.tcl-lang.org/page/tcc4tcl)

To integrate tcc into tcl there are some changes to be made, especially to the Read/Seek part of the loading routines etc., add tcl.h/tclint.h

So far, it seems like I got tcc working, except for one missing link. To compile into memory and run the resulting code, wich is why tcc is used in this context, you need to transfer the adress of tclStubsPtr (and tclIntStubsPtr) into the symboltable with tcc_add_symbol. Under 0.9.26 this worked as expected, tcc4tcl added the symbols, the linker resolved them and the resulting code executed and found the tclstubs table. Symbols are added in the form tcc_add_symbol (s,"tclStubsPtr", tclStubsPtr) where &tclStubsptr refers to the adress of the internal pointer from the active Tcl Interpreter. the stubstable is organized as a list of functionpointers, that are called relative to tclStubsPtr (https://wiki.tcl-lang.org/page/Stubs for further info)

 

With 0.9.27 this fails, wether with unkonwn symbol or, if I force tccpe to find the symbol, the adress gets resolved in the wrong way and coredumps.

Intersting enough, if I don't compile into memory but use tcc_output_file and link against tclStubs86.a all works, so it's not a general problem with linking.

Further Info:

- I used the last 0.9.27 stable from Fabrice Bellard http://download.savannah.gnu.org/releases/tinycc/

- I compile and test it under windows (ok, wine to be exact), but use -m32 WIN32 model to build the tcc4tcl.dll

- Tcl version is 8.6.6

 

Dumping the symboltable shows, that tclStubsPtr and tclIntStubsptr are in dynsymtable.

 

pe_find_import refuses to find the symbol, though sym_index >0, because the tested conditions are true.

(...)

       sym_index = find_elf_sym(s1->dynsymtab_section, s);
        if (sym_index
            && ELFW(ST_TYPE)(sym->st_info) == STT_OBJECT // was stt_object
            && 0 == (sym->st_other & ST_PE_IMPORT)
            && 0 == a
            ) err = -1, sym_index = 0;

 

(...)

 

 

If I hack this to return the sym_index, the linker will link and the linked adress "looks" like it did in 0.9.26, but the resulting code coredumps, so something is terribly wrong with this.

 

I can't say, why the symbol gets sorted out. I don't kno, if the coredump comes from a false conversion of the pointer adress or if the generated asm is handling it wrongly. I'm stuck....

 

Is anyone here able to point me in the right direction? Is there a patch im missing?

I can put up the modified code on github as a zip if anyone interested in getting into the details :-)

Is my problem clear enough or is there any helpful information missing?

 

Michael

 

 


reply via email to

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