constructor/destructor support

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

constructor/destructor support

tinycc-devel mailing list
I implemented constructors and destructors. This was the one thing I was
missing for my own project.

See the attachment.

Can I push it?

     Herman


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

constructor.patch (10K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

Christian Jullien-3
Thank again for this new tcc contribution which makes sense.

Let me make few remarks:

- First, since it works like gcc extension and because tcc already includes "some' gcc compatibility to ease portability between compilers, I would personally vote to include this patch.
- I've no clear option if we want to support this extension on Windows. To answer this question:
  * what we already doing on Windows with gcc specific extensions?
  * having it, even if not supported by standard vc++, will let to have a single source code that works the same on all tcc supported system
  * gcc on Windows supports all its extensions unless they conflict with vc++ (are there any?)
- Currently, I have the impression that test case is ran also on Windows .. which probably raises an error.

That said, if maintainers agree your patch, I would probably prefer it is supported also on Windows which is more in the spirit of what gcc does on different platforms.

As usual, I'll be very happy to test it on the different platforms I have access to

M2c.

Christian

-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Herman ten Brugge via Tinycc-devel
Sent: Friday, October 25, 2019 22:49
To: Herman ten Brugge via Tinycc-devel
Cc: Herman ten Brugge
Subject: *** SPAM *** [Tinycc-devel] constructor/destructor support

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

See the attachment.

Can I push it?

     Herman



_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

tinycc-devel mailing list
On 2019-10-26 06:08, Christian Jullien wrote:

> Thank again for this new tcc contribution which makes sense.
>
> Let me make few remarks:
>
> - First, since it works like gcc extension and because tcc already includes "some' gcc compatibility to ease portability between compilers, I would personally vote to include this patch.
> - I've no clear option if we want to support this extension on Windows. To answer this question:
>    * what we already doing on Windows with gcc specific extensions?
>    * having it, even if not supported by standard vc++, will let to have a single source code that works the same on all tcc supported system
>    * gcc on Windows supports all its extensions unless they conflict with vc++ (are there any?)
> - Currently, I have the impression that test case is ran also on Windows .. which probably raises an error.
>
> That said, if maintainers agree your patch, I would probably prefer it is supported also on Windows which is more in the spirit of what gcc does on different platforms.
>
> As usual, I'll be very happy to test it on the different platforms I have access to
I will try to implement this on windows. However the first tests show
that this does not work for dll's (or wine/cygwin is broken).
This will take some time. I have other things to do. I will probably
sent the updated patch at the end of november.

     Herman


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

Michael Matz-4
In reply to this post by tinycc-devel mailing list
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
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

Christian Jullien-3
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=[hidden email]] 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
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

tinycc-devel mailing list
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=[hidden email]] 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
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

win_contructor.patch (8K) Download Attachment
e.c (301 bytes) Download Attachment
d.c (372 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

Christian Jullien-3
My voice is not a maintainer one. As it adds something (no chance to break code) and you have test case for it, I vote for a push in mob which is the best way to have more remarks, feedbacks and possible improvements.

On my side, I'll be glad to run QA on machines I have access to.

C.

-----Original Message-----
From: Tinycc-devel [mailto:tinycc-devel-bounces+eligis=[hidden email]] On Behalf Of Herman ten Brugge via Tinycc-devel
Sent: Wednesday, October 30, 2019 07:20
To: [hidden email]
Cc: Herman ten Brugge
Subject: Re: [Tinycc-devel] constructor/destructor support

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=[hidden email]] 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
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>



_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

Michael Matz-4
In reply to this post by tinycc-devel mailing list
Hi,

On Wed, 30 Oct 2019, Herman ten Brugge via Tinycc-devel wrote:

> I had a good night sleep and realized that I could copy the .init/.fini
> arrays relocations to the text section

Why to the text section (and not, say .data, .init_array contains
pointers, not code), and why copying at all?  The link process (i.e.
pe_assign_addresses) merely needs to make sure that .init/.fini becomes
part of the loaded image (which should already be the case without any
changes?), then the start/stop symbols (why aren't you using
add_init_array_defines?) point to the correct areas in that image and
should be accessible just fine from the crt startup code.


Ciao,
Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

grischka
Michael Matz wrote:

> Hi,
>
> On Wed, 30 Oct 2019, Herman ten Brugge via Tinycc-devel wrote:
>
>> I had a good night sleep and realized that I could copy the .init/.fini
>> arrays relocations to the text section
>
> Why to the text section (and not, say .data, .init_array contains
> pointers, not code), and why copying at all?  The link process (i.e.
> pe_assign_addresses) merely needs to make sure that .init/.fini becomes
> part of the loaded image (which should already be the case without any
> changes?), then the start/stop symbols (why aren't you using
> add_init_array_defines?) point to the correct areas in that image and
> should be accessible just fine from the crt startup code.

Hi Herman,

Do you think we could get rid of the tcc_strdup()s and the n^2 strcmp()s
(and some of the static data) that were introduced for sym-versions, at
some point, too?

Anyway best wishes from me, for wholesome nights and dreams ;)

-- grischka

> Ciao,
> Michael.
>
> _______________________________________________
> Tinycc-devel mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel


_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

tinycc-devel mailing list
In reply to this post by Michael Matz-4
Sorry for the delay. I had a long vacation.

Before I went on vacation I read some Microsoft documentation.
This documentation send me in the wrong direction.
So the patch is now much simpler (see attachment).

Regards,

     Herman

On 2019-10-30 15:58, Michael Matz wrote:

> Hi,
>
> On Wed, 30 Oct 2019, Herman ten Brugge via Tinycc-devel wrote:
>
>> I had a good night sleep and realized that I could copy the .init/.fini
>> arrays relocations to the text section
> Why to the text section (and not, say .data, .init_array contains
> pointers, not code), and why copying at all?  The link process (i.e.
> pe_assign_addresses) merely needs to make sure that .init/.fini becomes
> part of the loaded image (which should already be the case without any
> changes?), then the start/stop symbols (why aren't you using
> add_init_array_defines?) point to the correct areas in that image and
> should be accessible just fine from the crt startup code.
>
>
> Ciao,
> Michael.

_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Reply | Threaded
Open this post in threaded view
|

Re: constructor/destructor support

Michael Matz-4
Hi,

On Tue, 26 Nov 2019, Herman ten Brugge wrote:

> Sorry for the delay. I had a long vacation.

Nice!  ;-)

> Before I went on vacation I read some Microsoft documentation.
> This documentation send me in the wrong direction.
> So the patch is now much simpler (see attachment).

I like that, push it :)


Ciao,
Michael.


>
> Regards,
>
>     Herman
>
> On 2019-10-30 15:58, Michael Matz wrote:
> > Hi,
> >
> > On Wed, 30 Oct 2019, Herman ten Brugge via Tinycc-devel wrote:
> >
> >> I had a good night sleep and realized that I could copy the .init/.fini
> >> arrays relocations to the text section
> > Why to the text section (and not, say .data, .init_array contains
> > pointers, not code), and why copying at all?  The link process (i.e.
> > pe_assign_addresses) merely needs to make sure that .init/.fini becomes
> > part of the loaded image (which should already be the case without any
> > changes?), then the start/stop symbols (why aren't you using
> > add_init_array_defines?) point to the correct areas in that image and
> > should be accessible just fine from the crt startup code.
> >
> >
> > Ciao,
> > Michael.
>
>
_______________________________________________
Tinycc-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel