public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
@ 2021-12-09 18:07 mark at harmstone dot com
  2021-12-09 22:34 ` [Bug target/103635] " redi at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-09 18:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

            Bug ID: 103635
           Summary: size_t and uintptr_t have wrong sizes with
                    x86_64-w64-mingw32-g++ -mabi=sysv
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mark at harmstone dot com
  Target Milestone: ---

When you add the option -mabi=sysv to mingw for amd64, it changes size_t and
uintptr_t from 64 to 32 bits.

Minimal example:

tmp.cpp:
#include <stddef.h>
static_assert(sizeof(size_t) == 8, "!");
static_assert(sizeof(uintptr_t) == 8, "!");

Working:
x86_64-pc-linux-gnu-g++ -mabi=ms -c tmp.cpp
x86_64-pc-linux-gnu-g++ -mabi=sysv -c tmp.cpp
x86_64-pc-cygwin-g++ -mabi=ms -c tmp.cpp
x86_64-pc-cygwin-g++ -mabi=sysv -c tmp.cpp
x86_64-w64-mingw32-g++ -mabi=ms -c tmp.cpp

Not working:
x86_64-w64-mingw32-g++ -mabi=sysv -c tmp.cpp
tmp.cpp:2:30: error: static assertion failed: !
    2 | static_assert(sizeof(size_t) == 8, "!");
      |               ~~~~~~~~~~~~~~~^~~~
tmp.cpp:3:33: error: static assertion failed: !
    3 | static_assert(sizeof(uintptr_t) == 8, "!");
      | 

My hunch is that perhaps GCC is assuming that long is the same size as a
pointer, which it's not on Windows. The SysV specs say that size_t is
equivalent to unsigned long on LP64 (but unsurprisingly doesn't mention the
LLP64 that Windows uses).

The practical problem this causes is that you can't #include <string> on mingw
with -mabi=sysv, as _mm_malloc amongst others uses size_t to do pointer
arithmetic.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
@ 2021-12-09 22:34 ` redi at gcc dot gnu.org
  2021-12-09 23:01 ` mark at harmstone dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-09 22:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Mark Harmstone from comment #0)
> The practical problem this causes is that you can't #include <string> on
> mingw with -mabi=sysv,

I don't think that's going to work anyway, is it?

I would expect that you need to rebuild the whole of libstdc++ to be able to
use a different -mabi switch.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
  2021-12-09 22:34 ` [Bug target/103635] " redi at gcc dot gnu.org
@ 2021-12-09 23:01 ` mark at harmstone dot com
  2021-12-10  0:32 ` redi at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-09 23:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #2 from Mark Harmstone <mark at harmstone dot com> ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to Mark Harmstone from comment #0)
> > The practical problem this causes is that you can't #include <string> on
> > mingw with -mabi=sysv,
> 
> I don't think that's going to work anyway, is it?
> 
> I would expect that you need to rebuild the whole of libstdc++ to be able to
> use a different -mabi switch.

Possibly, possibly not. I think a lot of <string> is templated rather than
precompiled. That wouldn't have been a blocker to what I was working on,
anyway.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
  2021-12-09 22:34 ` [Bug target/103635] " redi at gcc dot gnu.org
  2021-12-09 23:01 ` mark at harmstone dot com
@ 2021-12-10  0:32 ` redi at gcc dot gnu.org
  2021-12-10  0:36 ` mark at harmstone dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-10  0:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There's an explicit instantiation declaration at the end of the header, which
means the entire thing is externally defined in libstdc++.so and the only code
that gets instantiated in your own translation unit is for tiny functions which
are inlined. The rest will refer to the extern template definitions in the
shared library.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (2 preceding siblings ...)
  2021-12-10  0:32 ` redi at gcc dot gnu.org
@ 2021-12-10  0:36 ` mark at harmstone dot com
  2021-12-10  0:46 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-10  0:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #4 from Mark Harmstone <mark at harmstone dot com> ---
Thanks, but I mentioned <string> just to illustrate that this isn't purely a
hypothetical bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (3 preceding siblings ...)
  2021-12-10  0:36 ` mark at harmstone dot com
@ 2021-12-10  0:46 ` pinskia at gcc dot gnu.org
  2021-12-11 14:07 ` mark at harmstone dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-10  0:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2021-12-10

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
My bet it is a bug in the stddef.h header file.
Can you do the following:
x86_64-w64-mingw32-g++ -mabi=sysv -c tmp.cpp -save-temps -g3

and attach the preprocessed source?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (4 preceding siblings ...)
  2021-12-10  0:46 ` pinskia at gcc dot gnu.org
@ 2021-12-11 14:07 ` mark at harmstone dot com
  2021-12-12  3:07 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-11 14:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #6 from Mark Harmstone <mark at harmstone dot com> ---
Created attachment 51973
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51973&action=edit
preprocessed source

Thanks Andrew, attached.

Relevant bits:
typedef unsigned int size_t;
typedef unsigned int uintptr_t;

Both are "unsigned long long" for -mabi=ms.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (5 preceding siblings ...)
  2021-12-11 14:07 ` mark at harmstone dot com
@ 2021-12-12  3:07 ` pinskia at gcc dot gnu.org
  2021-12-12  3:42 ` mark at harmstone dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-12  3:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Mark Harmstone from comment #6)
> Created attachment 51973 [details]
> preprocessed source
> 
> Thanks Andrew, attached.
> 
> Relevant bits:
> typedef unsigned int size_t;
> typedef unsigned int uintptr_t;
> 
> Both are "unsigned long long" for -mabi=ms.

#define __SIZE_TYPE__ long long unsigned int
...

# 29 "/usr/x86_64-w64-mingw32/usr/include/corecrt.h" 3 4
#define _CRTNOALIAS 



#define _CRTRESTRICT 



#define _SIZE_T_DEFINED 
#undef size_t

__extension__ typedef unsigned long long size_t;






#define _SSIZE_T_DEFINED 
#undef ssize_t

__extension__ typedef long long ssize_t;

---- CUT -----
Did you attach the wrong file?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (6 preceding siblings ...)
  2021-12-12  3:07 ` pinskia at gcc dot gnu.org
@ 2021-12-12  3:42 ` mark at harmstone dot com
  2021-12-12  3:45 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-12  3:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #8 from Mark Harmstone <mark at harmstone dot com> ---
Created attachment 51976
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51976&action=edit
preprocessed source

Sorry!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (7 preceding siblings ...)
  2021-12-12  3:42 ` mark at harmstone dot com
@ 2021-12-12  3:45 ` pinskia at gcc dot gnu.org
  2021-12-12 12:26 ` mark at harmstone dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-12  3:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Mark Harmstone from comment #8)
> Created attachment 51976 [details]
> preprocessed source

Can you attach /usr/x86_64-w64-mingw32/usr/include/corecrt.h ?
because I suspect it is bug there:
because GCC still has __SIZE_TYPE__ as unsigned long long:

# 0 "<built-in>"
#define __SIZE_TYPE__ long long unsigned int

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (8 preceding siblings ...)
  2021-12-12  3:45 ` pinskia at gcc dot gnu.org
@ 2021-12-12 12:26 ` mark at harmstone dot com
  2021-12-12 12:36 ` pinskia at gcc dot gnu.org
  2021-12-12 16:35 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: mark at harmstone dot com @ 2021-12-12 12:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #10 from Mark Harmstone <mark at harmstone dot com> ---
Created attachment 51977
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51977&action=edit
corecrt.h

>From the file:

#ifndef _SIZE_T_DEFINED
#define _SIZE_T_DEFINED
#undef size_t
#ifdef _WIN64
__MINGW_EXTENSION typedef unsigned __int64 size_t;
#else
typedef unsigned int size_t;
#endif /* _WIN64 */
#endif /* _SIZE_T_DEFINED */

So the underlying issue is that _WIN64 is not getting set with -mabi=sysv. Is
this a bug with GCC, or in the mingw headers?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (9 preceding siblings ...)
  2021-12-12 12:26 ` mark at harmstone dot com
@ 2021-12-12 12:36 ` pinskia at gcc dot gnu.org
  2021-12-12 16:35 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-12 12:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |UNCONFIRMED
     Ever confirmed|1                           |0
           Keywords|                            |rejects-valid, wrong-code

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Mark Harmstone from comment #10)
> So the underlying issue is that _WIN64 is not getting set with -mabi=sysv.
> Is this a bug with GCC, or in the mingw headers?

The mingw headers assume if _WIN64 is not defined then it is mingw32 ABI.

But GCC has:
      builtin_define ("__MSVCRT__");                            \
      builtin_define ("__MINGW32__");                           \
      builtin_define ("_WIN32");                                \
      builtin_define_std ("WIN32");                             \
      builtin_define_std ("WINNT");                             \
      builtin_define_with_int_value ("_INTEGRAL_MAX_BITS",      \
                                     TYPE_PRECISION (intmax_type_node));\
      if (TARGET_64BIT && ix86_abi == MS_ABI)                   \
        {                                                       \
          builtin_define ("__MINGW64__");                       \
          builtin_define_std ("WIN64");                         \
          builtin_define ("_WIN64");                            \
        }                                                       \


At this point, it is up to the mingw maintainers to figure out if the bug is in
GCC or mingw headers because I have no opinion on this really.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug target/103635] size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv
  2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
                   ` (10 preceding siblings ...)
  2021-12-12 12:36 ` pinskia at gcc dot gnu.org
@ 2021-12-12 16:35 ` redi at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-12 16:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103635

--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Arguably sysv ABI on Windows is a distinct target, and you need to provide your
own libc for it.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-12-12 16:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-09 18:07 [Bug c++/103635] New: size_t and uintptr_t have wrong sizes with x86_64-w64-mingw32-g++ -mabi=sysv mark at harmstone dot com
2021-12-09 22:34 ` [Bug target/103635] " redi at gcc dot gnu.org
2021-12-09 23:01 ` mark at harmstone dot com
2021-12-10  0:32 ` redi at gcc dot gnu.org
2021-12-10  0:36 ` mark at harmstone dot com
2021-12-10  0:46 ` pinskia at gcc dot gnu.org
2021-12-11 14:07 ` mark at harmstone dot com
2021-12-12  3:07 ` pinskia at gcc dot gnu.org
2021-12-12  3:42 ` mark at harmstone dot com
2021-12-12  3:45 ` pinskia at gcc dot gnu.org
2021-12-12 12:26 ` mark at harmstone dot com
2021-12-12 12:36 ` pinskia at gcc dot gnu.org
2021-12-12 16:35 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).