tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] constructor/destructor support


From: Herman ten Brugge
Subject: Re: [Tinycc-devel] constructor/destructor support
Date: Wed, 30 Oct 2019 07:19:54 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1

I created the windows constructor patch. See attached patch.

I had a good night sleep and realized that I could copy the .init/.fini arrays + relocations to the text section and then modify the win32/lib code to call these functions. I implemented this and it works (even for dll's). So testcase 108 now runs fine on windows.

The testcode for dll's is also attached (d.c and e.c).
To compile this do:
tcc.exe -g -shared -o libe.dll e.c
tcc.exe -g -o d.exe d.c -L. -le

Running d.exe should result in:
constructor1
constructor
main
destructor
destructor1

The mingw compiler now also works. The problem was that you at least have to call 1 functions in the dll.
So compiling with:
x86_64-w64-mingw32-gcc -fPIC -shared -o libe.dll e.c
x86_64-w64-mingw32-gcc d.c -o d -L. -le

Running d.exe has the same result as above.

    Herman


On 2019-10-29 06:51, Christian Jullien wrote:
Replying to my own question, on Windows gcc does support ctor/dtor so, IHMO, 
tcc should do the same.

Taking Herman's 108_constructor.c gcc 9.1 Mingw64 gives:

C:>gcc foo.c -o foo.exe

C:>file foo.exe
foo.exe: PE32+ executable (console) x86-64, for MS Windows

C:>foo
constructor
main
destructor



-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=address@hidden] On 
Behalf Of Michael Matz
Sent: Monday, October 28, 2019 10:40
To: Herman ten Brugge via Tinycc-devel
Cc: Herman ten Brugge
Subject: Re: [Tinycc-devel] constructor/destructor support

Hello,

On Fri, 25 Oct 2019, Herman ten Brugge via Tinycc-devel wrote:

I implemented constructors and destructors. This was the one thing I was
missing for my own project.

See the attachment.

Can I push it?
Could you please refactor some things?  In particular the duplicate code
of add_init_array and add_fini_array: instead add just one function
(add_sec_array?) that takes the name of the section.  Also if you test
the section size for being != 0 before creating the dynamic tags
(DT_INIT* and friends) it might be that you can avoid having to add the
'create' argument to find_section; it would be nice to not have to have
it.

Otherwise, looks good.  Thanks for the work.  (And yeah, bonus points for
Windows and -run support :) ).


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Attachment: win_contructor.patch
Description: Text Data

Attachment: e.c
Description: Text Data

Attachment: d.c
Description: Text Data


reply via email to

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