Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-09-28 Thread David Grayson
Microsoft just published an article about this kind of thing: https://blogs.msdn.microsoft.com/oldnewthing/20170927-00/?p=97095 It seems that casting pointers to uintptr_t before comparing them would probably be safe. --David Grayson On Sat, Aug 5, 2017 at 12:44 PM, David Grayson wrote: > What

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-23 Thread David Grayson
Martell: OK, I looked at that link briefly. I think I understand what you're worried about here: the markers that we have at the beginning and end of our constructor/destructor sections might be removed by the linker of clang or GCC if it is determined that no code is actually referencing those va

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-23 Thread Martell Malone
Hey David, I came across this today which might be of interest to our discussion, while it is not related directly to the problem you mentioned it is similar. https://reviews.llvm.org/D37059 I will follow up with a patch for binutils to add __CTOR_END__ and __DTOR_END__ but it is interesting to no

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-22 Thread Martin Storsjö
On Tue, 22 Aug 2017, Martell Malone wrote: pushed to master. Fantastic, thanks! // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-22 Thread Martell Malone
pushed to master. Thanks Martin. On Fri, Aug 18, 2017 at 9:01 PM, Martin Storsjö wrote: > On Fri, 18 Aug 2017, Martell Malone wrote: > > Can I land this in master? >> > > Ok with me at least. Since it's all within clang ifdefs, it shouldn't hurt > for any others than us who run this > still-(bu

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martin Storsjö
On Fri, 18 Aug 2017, Martell Malone wrote: Can I land this in master? Ok with me at least. Since it's all within clang ifdefs, it shouldn't hurt for any others than us who run this still-(but-hopefully-not-for-long)-experimental setup. // Martin ---

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
Can I land this in master? Best, Martell On Fri, Aug 18, 2017 at 8:53 PM, Martell Malone wrote: > I'm not so sure; a normal C struct or array would never have a global >> symbol defined in the middle or at the end, so a smart compiler might >> some day assume that if you take a symbol and decre

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
> > I'm not so sure; a normal C struct or array would never have a global > symbol defined in the middle or at the end, so a smart compiler might > some day assume that if you take a symbol and decrement it, it's an > invalid pointer. I don't really want to argue much more than that, > and I don't

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martin Storsjö
On Fri, 18 Aug 2017, Martell Malone wrote: Attached updated patch. I was itching to invert the .ctors markers so that I could do while (*p) instead of while (*p != (func_ptr) -1) but that would create another binutils breakage so I left it. Let me know how you all want to proceed :) Looks gr

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
Attached updated patch. I was itching to invert the .ctors markers so that I could do while (*p) instead of while (*p != (func_ptr) -1) but that would create another binutils breakage so I left it. Let me know how you all want to proceed :) On Fri, Aug 18, 2017 at 8:39 PM, David Grayson wrote:

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread David Grayson
On Fri, Aug 18, 2017 at 12:26 PM, Martin Storsjö wrote: > Yup, that resolves the concern. > > As long as you just use one or the other of *_LIST__ or *_END__ in each > function and use the sentinel values instead of comparing the pointers, it > should be fine. Otherwise the compiler is free to reg

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martin Storsjö
On Fri, 18 Aug 2017, Martell Malone wrote: LGTM, although it might be good to adjust it in the way David suggested (avoiding the direct comparisons with *_END__, which is technically undefined behaviour, and just checking the sentinel element value instead). I have seen __CTOR_END__ used and

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
> > LGTM, although it might be good to adjust it in the way David suggested > (avoiding the direct comparisons with *_END__, which is technically > undefined behaviour, and just checking the sentinel element value instead). I have seen __CTOR_END__ used and counted backwards by many crt startups.

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martin Storsjö
On Fri, 18 Aug 2017, Martell Malone wrote: Marin, please review :) commit 726ed8e9b9eea9a2c62c46108da9e014b85dca45 Author: Martell Malone Date: Fri Aug 18 19:59:20 2017 +0100 crt: Handle .ctors and .dtors within mingw-w64 When building with clang we currently assume you will be li

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread David Grayson
Thanks for the explanation of the binutils bug, Martell. Also, your latest patch has bad newlines inserted by GMail again. It might actually be better to use GMail's HTML mode, or just use an attachment with a .txt extension (not .patch). --David On Fri, Aug 18, 2017 at 12:05 PM, Martell Malone

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
I typed too fast *martin :) On Fri, Aug 18, 2017 at 8:04 PM, Martell Malone wrote: > Marin, please review :) > > commit 726ed8e9b9eea9a2c62c46108da9e014b85dca45 > Author: Martell Malone > Date: Fri Aug 18 19:59:20 2017 +0100 > > crt: Handle .ctors and .dtors within mingw-w64 > > When b

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
Marin, please review :) commit 726ed8e9b9eea9a2c62c46108da9e014b85dca45 Author: Martell Malone Date: Fri Aug 18 19:59:20 2017 +0100 crt: Handle .ctors and .dtors within mingw-w64 When building with clang we currently assume you will be linking with llvm's lld or a bleeding edge bi

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
In that case I will be back with a patch shortly for you to review. It might look ugly because of a large __clang__ ifdef block but should work. On Fri, Aug 18, 2017 at 7:50 PM, Martin Storsjö wrote: > On Fri, 18 Aug 2017, Martell Malone wrote: > > David, I also want to remove KEEP (*(.ctors));

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martin Storsjö
On Fri, 18 Aug 2017, Martell Malone wrote: David, I also want to remove KEEP (*(.ctors)); which seems to cause a bug when linking in conjunction with KEEP (*(SORT_BY_NAME(.ctors.*))) and our new mingw-w64 markers. I have details in this email on binutils ml. https://sourceware.org/ml/binutils/20

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
David, Sorry the previous email was to the thread, this link is to the exact email where I detail the problem. https://sourceware.org/ml/binutils/2017-08/msg00123.html On Fri, Aug 18, 2017 at 7:46 PM, Martell Malone wrote: > David, I also want to remove KEEP (*(.ctors)); which seems to cause a b

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
David, I also want to remove KEEP (*(.ctors)); which seems to cause a bug when linking in conjunction with KEEP (*(SORT_BY_NAME(.ctors.*))) and our new mingw-w64 markers. I have details in this email on binutils ml. https://sourceware.org/ml/binutils/2017-08/msg00078.html I have to create a minifie

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martin Storsjö
On Fri, 18 Aug 2017, Martell Malone wrote: suddenly requiring the absolutely latest binutils, right? Correct we will need the next binutils release as a min version. I don't think we need a condition we should just specify a new min binutils version for mingw-w64 to require. jon_y said this t

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread David Grayson
Martell, what was wrong with the sorting in the old binutils? It seems like the only thing you're doing is changing "SORT" to "SORT_BY_NAME" but I couldn't easily tell if that will make a difference. --David On Fri, Aug 18, 2017 at 11:11 AM, Martell Malone wrote: >> >> suddenly requiring the a

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-18 Thread Martell Malone
> > suddenly requiring the absolutely latest binutils, right? Correct we will need the next binutils release as a min version. I don't think we need a condition we should just specify a new min binutils version for mingw-w64 to require. jon_y said this to me in the past, I think we should wait un

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-17 Thread Martin Storsjö
On Mon, 14 Aug 2017, Martell Malone wrote: Can you briefly summarize what change this does and why it's necessary, since the plain mingw patch as such seems to work already both with binutils ld and with lld? Is it in order to guarantee that the symbols in the mingw patch are sorted correctly s

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-14 Thread Martell Malone
> > Can you briefly summarize what change this does and why it's necessary, > since the plain mingw patch as such seems to work already both with > binutils ld and with lld? Is it in order to guarantee that the symbols in > the mingw patch are sorted correctly so that we can be sure that the > mark

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-14 Thread Martin Storsjö
On Mon, 14 Aug 2017, Martell Malone wrote: Hey Martin, I had a discussion with Nick and CC'd kai on getting the binutils patch in tree a week ago. https://sourceware.org/ml/binutils/2017-08/msg00123.html It seems to be moving along. Oh, I see - ok. Can you briefly summarize what change this

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-14 Thread Martell Malone
Hey Martin, I had a discussion with Nick and CC'd kai on getting the binutils patch in tree a week ago. https://sourceware.org/ml/binutils/2017-08/msg00123.html It seems to be moving along. Best, Martell On Mon, Aug 14, 2017 at 8:49 AM, Martin Storsjö wrote: > On Sat, 5 Aug 2017, David Grays

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-14 Thread Martin Storsjö
On Sat, 5 Aug 2017, David Grayson wrote: Oops, here is the patch. On Sat, Aug 5, 2017 at 10:14 AM, David Grayson wrote: I think Martell's last patch would have worked but it's not as safe as I would like it to be. I think the constructor and destructor lists should not be defined in gccmain.

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-06 Thread David Grayson
I thought my last email explained it pretty well. The optimizer can do any kind of transformation it wants on the code as long as it doesn't change the behavior of well-defined programs. You seem to be stuck on the "__used__" attribute but that's not relevant to my argument. --David On Sun, Aug

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-06 Thread Martell Malone
> > What I meant is that if GCC's optimizer ever figures out that we are > comparing pointers that came from two different memory objects, it > would know we are doing undefined behavior and would have a license to > do whatever it wants, including removing that code. The way the loop > is written

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-05 Thread David Grayson
What I meant is that if GCC's optimizer ever figures out that we are comparing pointers that came from two different memory objects, it would know we are doing undefined behavior and would have a license to do whatever it wants, including removing that code. The way the loop is written right now i

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-05 Thread Martell Malone
> > I think Martell's last patch would have worked but it's not as safe as > I would like it to be. I think the constructor and destructor lists should not be defined in gccmain.c where they are used, because then > the compiler optimizer might start to get smart and stop optimizing > things in a

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-05 Thread David Grayson
Oops, here is the patch. On Sat, Aug 5, 2017 at 10:14 AM, David Grayson wrote: > I think Martell's last patch would have worked but it's not as safe as > I would like it to be. I think the constructor and destructor lists > should not be defined in gccmain.c where they are used, because then > t

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-05 Thread David Grayson
I think Martell's last patch would have worked but it's not as safe as I would like it to be. I think the constructor and destructor lists should not be defined in gccmain.c where they are used, because then the compiler optimizer might start to get smart and stop optimizing things in a bad way.

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-05 Thread Martell Malone
Hey David, > Your binutils patch did not apply cleanly to binutils-2.27 but I got > it to work. It looks pretty dangerous to me because you removed the > lines for keeping the .dtors, .dtor, .ctors, and .ctor sections. And > you're using .ctors and .dtors in your other patch, and other code > m

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread David Grayson
With your latest two patches, the toolchain compiles but I get an error when building a shared library: /nix/store/k481dhv5hivggnjyb9rs95fz1k6ylhjz-mingw-w64-2017-08-03-i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-gccmain.o): In function `_do_global_dtors': /tmp/nix-build-mingw-w64-

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread David Grayson
Oh, I mean that I got the patch to apply, but I don't know if it really *works*; the toolchain is still building at this time. --David On Fri, Aug 4, 2017 at 6:11 PM, David Grayson wrote: > Your binutils patch did not apply cleanly to binutils-2.27 but I got > it to work. It looks pretty danger

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread David Grayson
Your binutils patch did not apply cleanly to binutils-2.27 but I got it to work. It looks pretty dangerous to me because you removed the lines for keeping the .dtors, .dtor, .ctors, and .ctor sections. And you're using .ctors and .dtors in your other patch, and other code might use them too I sup

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread Martell Malone
Hey David, This could be caused by gcc including it's own crtbegin.o and crtend.o I managed to install a toolchain with brew and I swapped out gcc's and mingw-w64's crtbegin and crtend. Everything seems to work here as intended. Attached is an updated patch that avoids crtbegin and crtend that sho

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread David Grayson
Martell: My setup ( https://github.com/DavidEGrayson/nixcrpkgs ) makes it quite easy to try random patches and make sure that GCC can still be bootstrapped and that I can build non-trivial applications. I tried your patch (after fixing the linebreaks added by GMail) but unfortunately it doesn't w

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread Martell Malone
Okay lets just solve this. I believe the following should work for both clang and gcc I added a test case at the bottom also. diff --git a/mingw-w64-crt/crt/crtbegin.c b/mingw-w64-crt/crt/crtbegin.c index 39c0d856..1672f7b9 100644 --- a/mingw-w64-crt/crt/crtbegin.c +++ b/mingw-w64-crt/crt/crtbegin

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread Martin Storsjö
On Fri, 4 Aug 2017, Ruben Van Boxem wrote: Op 3 aug. 2017 9:26 p.m. schreef "Martell Malone" : I for one would like to be able to use one crt with both Clang and GCC. No use in duplicating 99% of the code for that one little bit of startup code that needs to be different. Perhaps ldd or Clang n

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread David Grayson
Hello. Bellow my signature is a copy of the explanation I sent to the list about why ca451a7 should be reverted. The issue is that different objects are adding constructor pointers to a special section for it, and the CRT need to reliably find the beginning of that section. The CRT uses special

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread Martin Storsjö
On Thu, 3 Aug 2017, Martell Malone wrote: Hey Martin, Glad to see you following up on my various LLVM adventures :) From what I remember the initialization is done in mingw-w64/crt/gccmain.c. I believe it may be possible to add this code and not make is clang specific. Before the iteration lo

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-04 Thread Ruben Van Boxem
Op 3 aug. 2017 9:26 p.m. schreef "Martell Malone" : Hey Martin, Glad to see you following up on my various LLVM adventures :) From what I remember the initialization is done in mingw-w64/crt/gccmain.c. I believe it may be possible to add this code and not make is clang specific. Before the iter

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-03 Thread Martell Malone
Hey Martin, Glad to see you following up on my various LLVM adventures :) From what I remember the initialization is done in mingw-w64/crt/gccmain.c. I believe it may be possible to add this code and not make is clang specific. Before the iteration loop check in __do_global_ctors and __do_global

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2017-08-02 Thread Martin Storsjö
Hi Martell, André and Kai, On Sun, 28 Aug 2016, André Hentschel wrote: Am 09.08.2016 um 11:16 schrieb Kai Tietz: Hallo Martell, patch is ok. Wouldn't it be better to have those symbols in linker scrpt instead? That is actually the way used in ld for it. Thanlks, Kai 2016-08-06 5:14 GMT+02

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2016-08-28 Thread André Hentschel
Am 09.08.2016 um 11:16 schrieb Kai Tietz: > Hallo Martell, > > patch is ok. Wouldn't it be better to have those symbols in linker > scrpt instead? That is actually the way used in ld for it. > > Thanlks, > Kai > > 2016-08-06 5:14 GMT+02:00 Martell Malone : >> This patch should be the last piec

Re: [Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2016-08-09 Thread Kai Tietz
Hallo Martell, patch is ok. Wouldn't it be better to have those symbols in linker scrpt instead? That is actually the way used in ld for it. Thanlks, Kai 2016-08-06 5:14 GMT+02:00 Martell Malone : > This patch should be the last piece of the puzzle. > Now c++ works, it relied heavily on ctors

[Mingw-w64-public] [PATCH] Handle __CTOR_LIST__ for clang

2016-08-05 Thread Martell Malone
This patch should be the last piece of the puzzle. Now c++ works, it relied heavily on ctors which was broken with clang and lld. please review From 077f2318a219db191588d0ab00df58bb694c2931 Mon Sep 17 00:00:00 2001 From: Martell Malone Date: Fri, 5 Aug 2016 20:09:41 -0700 Subject: [PATCH] Handle