Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sizeof(wchar_t) == 1 on GCC 6.5.0 #169

Open
deadwood2 opened this issue Nov 12, 2024 · 3 comments
Open

sizeof(wchar_t) == 1 on GCC 6.5.0 #169

deadwood2 opened this issue Nov 12, 2024 · 3 comments
Labels
priority:high type:bug Something isn't working

Comments

@deadwood2
Copy link
Owner

deadwood2 commented Nov 12, 2024

For some reason, sizeof(wchar_t) is 1 on GCC 6.5.0. This is wrong as wchar_t should be 4 bytes long - otherwise it is no different than char. Also builtin define __ WCHAR_TYPE __ gets resolved for some reason to 'char'.

Need to check with GCC 10.5.0. If it was fixed, that it actually breaks binary compatibility with current "wrong" wc#? functions exposed in stdlib.library

@deadwood2 deadwood2 added type:bug Something isn't working priority:high labels Nov 12, 2024
@deadwood2 deadwood2 added this to Core Nov 12, 2024
@deadwood2 deadwood2 changed the title sizeof(wchar_t) == 1 on GCC 6.5.5 sizeof(wchar_t) == 1 on GCC 6.5.0 Nov 12, 2024
@deadwood2
Copy link
Owner Author

Further testing shows that this is consistent between i386 and x86_64 GCC 6.5.0 cross & native as well as x86_64 10.5.0 cross and native:

echo "" | ./x86_64-aros-gcc -E - -dM | grep WCHAR

#define __WCHAR_MAX__ 0x7f
#define __WCHAR_MIN__ (-__WCHAR_MAX__ - 1)
#define __WCHAR_WIDTH__ 8
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __WCHAR_TYPE__ char
#define __SIZEOF_WCHAR_T__ 1

echo "" | ./x86_64-aros-gcc -E - -dM -fshort-wchar | grep WCHAR

Furthermore there is -fshort-wchar option which then changes size to 2 bytes:

#define __WCHAR_MAX__ 0xffff
#define __WCHAR_MIN__ 0
#define __WCHAR_WIDTH__ 16
#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
#define __WCHAR_TYPE__ short unsigned int
#define __SIZEOF_WCHAR_T__ 2

Which in default mode should be downgrading wchar_t from 4 to 2 bytes, but now it's actually upgrading it!

@deadwood2
Copy link
Owner Author

deadwood2 commented Nov 14, 2024

Quote of GCC docs:

"Override the underlying type for wchar_t to be short unsigned int instead of the default for the target. This option is useful for building programs to run under WINE.

Warning: the -fshort-wchar switch causes GCC to generate code that is not binary compatible with code generated without that switch. Use it to conform to a non-default application binary interface."

@deadwood2
Copy link
Owner Author

deadwood2 commented Nov 14, 2024

AROS patch for GCC 6.5.0 explicitly sets wchar as 8 bit char. Looking at history it has been this way since first version (2019)

gcc/config/aros.h

+#undef WCHAR_TYPE
+#define WCHAR_TYPE "char"
+
+#undef WCHAR_TYPE_SIZE
+#define WCHAR_TYPE_SIZE 8

This needs to be changed to either 'int' or 'unsigned int'. Seems like some systems use 'unsigned' and also python 3.x checks whether wchar_t is unsigned to decide if it is "usable"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:high type:bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant