On Mon, 14 Jun 2021, Liu Hao wrote:
diff --git a/mingw-w64-headers/crt/_mingw_mac.h
b/mingw-w64-headers/crt/_mingw_mac.h
index ca7c89740..ee44fc30c 100644
--- a/mingw-w64-headers/crt/_mingw_mac.h
+++ b/mingw-w64-headers/crt/_mingw_mac.h
@@ -301,6 +301,8 @@
# define __mingw_attribute_artificial
#endif
+#define __MINGW_SELECTANY __attribute__((__selectany__))
+
FWIW we have __declspec(selectany) in a number of places in our headers
already (which expands to the same), but not in the crt/* headers yet. I
don't mind either this or plain __declspec(selectany).
#if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 && __MINGW_GNUC_PREREQ(4, 1)
# if _FORTIFY_SOURCE > 1
# define __MINGW_FORTIFY_LEVEL 2
diff --git a/mingw-w64-headers/crt/locale.h b/mingw-w64-headers/crt/locale.h
index 6b1893b36..d997200cc 100644
--- a/mingw-w64-headers/crt/locale.h
+++ b/mingw-w64-headers/crt/locale.h
@@ -103,6 +103,12 @@ extern "C" {
_CRTIMP wchar_t *__cdecl _wsetlocale(int _Category,const wchar_t *_Locale);
#endif
+#ifdef __CHAR_UNSIGNED__
+/* Pull in the constructor from 'charmax.c'. */
+extern int mingw_initcharmax;
+__MINGW_SELECTANY int* __mingw_reference_charmax = &mingw_initcharmax;
+#endif
I think I'd rather add two double leading underscores to the
mingw_initcharmax symbol too, if we're going to be referencing it from
public headers.
Other than that, this looks ok to me.
Should the pointer be made const?
FWIW this way of referencing the variable causes one extra base relocation
in executables that include it, as the absolute address needs to be
written in the data/rdata section. The MSVC equivalent uses an inline
function to reference it, which should generate position independent code
- but I'm less sure that we can be sure that such code actually gets
emitted, so this form probably is more robust against compilers optimizing
it out.
// Martin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public