Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
On Sat, 25 Nov 2017, Sven Kretzschmar wrote: Thanks for your WIP stdio_s.h . That helped a lot. I had to add another func (swprintf_s) & I had to comment out 3 of your wip functions, because there is no "__stdio_common_vfscanf_s" internal func in MS ucrtbase. I have attached my modified stdio_s.h & wchar_s.h file if you want to have a look if I did that right. Changes are framed - a bit unorthodox - by /* NEW SK */ ... I'll see later if I get more time to dig into this again... However, I am getting a new error now, when compiling Julia sources with the ucrtbase version of gcc - see below ERROR #4. I think you mentioned somewhere that you excluded "tzset" from the "ucrtbase autoexport" patch, because this led to an "infinite recursion" or similar. But by looking at the below error, it seems that it is still needed to be excluded somehow. Do you have any ideas for an additional/different patch to address this ? (Preferably not requiring to explicitly exclude linkage via -Wl linker flags, as all this is happing somewhere deep inside the big Makefile & CMake build system for Julia ? Yes, it seems I overlooked some other detail relating to the tzset function (not the thing I mentioned earlier) - see the patch I just posted - that should fix this issue. // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
P.S.: There is no "__stdio_common_vfscanf_s" in ucrtbase internals, but there is a "__stdio_common_vfscanf" - wasn't wearing my glasses, sorry ;) But this has nothing to do with the new "tzset" error #4 - Sven -Original Message- From: Sven Kretzschmar [mailto:sven.kretzsch...@gmx.de] Sent: 25 November 2017 16:39 To: mingw-w64-public@lists.sourceforge.net Subject: Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported Hi Martin, Thanks for your WIP stdio_s.h . That helped a lot. I had to add another func (swprintf_s) & I had to comment out 3 of your wip functions, because there is no "__stdio_common_vfscanf_s" internal func in MS ucrtbase. I have attached my modified stdio_s.h & wchar_s.h file if you want to have a look if I did that right. Changes are framed - a bit unorthodox - by /* NEW SK */ ... However, I am getting a new error now, when compiling Julia sources with the ucrtbase version of gcc - see below ERROR #4. I think you mentioned somewhere that you excluded "tzset" from the "ucrtbase autoexport" patch, because this led to an "infinite recursion" or similar. But by looking at the below error, it seems that it is still needed to be excluded somehow. Do you have any ideas for an additional/different patch to address this ? (Preferably not requiring to explicitly exclude linkage via -Wl linker flags, as all this is happing somewhere deep inside the big Makefile & CMake build system for Julia ? Thanks & Cheers - Sven ERROR #4: -- /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrtbase_compat.o): In function `tzset': /home/sven/buildtmp/build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/crt/uc rtbase_compat.c:178: multiple definition of `tzset' /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(dumns02036.o):(.text+0x0): first defined here /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrtbase_compat.o):/home/sven/buildt mp/build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/crt/ucrtbase_compat.c:2 36: multiple definition of `__imp_tzset' /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(dumns02036.o):(.idata$5+0x0): first defined here collect2: error: ld returned 1 exit status -Original Message- From: Martin Storsjö [mailto:mar...@martin.st] Sent: 24 November 2017 13:02 To: mingw-w64-public@lists.sourceforge.net Subject: Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported On Thu, 23 Nov 2017, Sven Kretzschmar wrote: > I will try to add the 2 missing references in the way you hinted at in > your post. FWIW, for the _cprintf one, the conio.h patch that I sent should be a proper fix. The other one requires fixing stdio_s.h, and it's a truly huge number of functions there. I started looking at it, but don't have time to do them all right now. Attached is my work in progress for this header, that should cover at least the function that you mentioned so far. That one isn't sent for review yet as it's quite incomplete. OTOH, perhaps it's better to at least fix up some subsets of it, that happens to be used, instead of aiming for all of them. // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
Hi Martin, Thanks for your WIP stdio_s.h . That helped a lot. I had to add another func (swprintf_s) & I had to comment out 3 of your wip functions, because there is no "__stdio_common_vfscanf_s" internal func in MS ucrtbase. I have attached my modified stdio_s.h & wchar_s.h file if you want to have a look if I did that right. Changes are framed - a bit unorthodox - by /* NEW SK */ ... However, I am getting a new error now, when compiling Julia sources with the ucrtbase version of gcc - see below ERROR #4. I think you mentioned somewhere that you excluded "tzset" from the "ucrtbase autoexport" patch, because this led to an "infinite recursion" or similar. But by looking at the below error, it seems that it is still needed to be excluded somehow. Do you have any ideas for an additional/different patch to address this ? (Preferably not requiring to explicitly exclude linkage via -Wl linker flags, as all this is happing somewhere deep inside the big Makefile & CMake build system for Julia ? Thanks & Cheers - Sven ERROR #4: -- /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrtbase_compat.o): In function `tzset': /home/sven/buildtmp/build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/crt/uc rtbase_compat.c:178: multiple definition of `tzset' /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(dumns02036.o):(.text+0x0): first defined here /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrtbase_compat.o):/home/sven/buildt mp/build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/crt/ucrtbase_compat.c:2 36: multiple definition of `__imp_tzset' /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(dumns02036.o):(.idata$5+0x0): first defined here collect2: error: ld returned 1 exit status -Original Message- From: Martin Storsjö [mailto:mar...@martin.st] Sent: 24 November 2017 13:02 To: mingw-w64-public@lists.sourceforge.net Subject: Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported On Thu, 23 Nov 2017, Sven Kretzschmar wrote: > I will try to add the 2 missing references in the way you hinted at in > your post. FWIW, for the _cprintf one, the conio.h patch that I sent should be a proper fix. The other one requires fixing stdio_s.h, and it's a truly huge number of functions there. I started looking at it, but don't have time to do them all right now. Attached is my work in progress for this header, that should cover at least the function that you mentioned so far. That one isn't sent for review yet as it's quite incomplete. OTOH, perhaps it's better to at least fix up some subsets of it, that happens to be used, instead of aiming for all of them. // Martin /** * This file has no copyright assigned and is placed in the Public Domain. * This file is part of the mingw-w64 runtime package. * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ #ifndef _INC_WCHAR_S #define _INC_WCHAR_S #include #if defined(MINGW_HAS_SECURE_API) #if defined(__LIBMSVCRT__) /* When building mingw-w64, this should be blank. */ #define _SECIMP #else #ifndef _SECIMP #define _SECIMP __declspec(dllimport) #endif /* _SECIMP */ #endif /* defined(_CRTBLD) || defined(__LIBMSVCRT__) */ #ifdef __cplusplus extern "C" { #endif /* NEW SK */ #if __MSVCRT_VERSION__ >= 0x1400 int __cdecl __stdio_common_vswprintf_s(unsigned __int64 Options, wchar_t *Str, size_t Len, const wchar_t *Format, _locale_t _Locale, va_list _ArgList); #endif /* NEW SK */ #ifndef _WIO_S_DEFINED #define _WIO_S_DEFINED _SECIMP errno_t __cdecl _waccess_s (const wchar_t *_Filename,int _AccessMode); _SECIMP errno_t __cdecl _wmktemp_s (wchar_t *_TemplateName,size_t _SizeInWords); #endif #ifndef _WCONIO_S_DEFINED #define _WCONIO_S_DEFINED _SECIMP errno_t __cdecl _cgetws_s (wchar_t *_Buffer,size_t _SizeInWords,size_t *_SizeRead); _SECIMP int __cdecl _cwprintf_s (const wchar_t *_Format,...); _CRTIMP int __cdecl _cwscanf_s(const wchar_t *_Format,...); _CRTIMP int __cdecl _cwscanf_s_l(const wchar_t *_Format,_locale_t _Locale,...); _SECIMP int __cdecl _vcwprintf_s (const wchar_t *_Format,va_list _ArgList); _SECIMP int __cdecl _cwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,...); _SECIMP int __cdecl _vcwprintf_s_l (const wchar_t *_Format,_locale_t _Locale,va_list _ArgList); #endif #ifndef _WSTDIO_S_DEFINED #define _WSTDIO_S_DEFINED _CRTIMP wchar_t *__cdecl _getws_s(wchar_t *_Str,size_t _SizeInWords); int __cdecl fwprintf_s(FILE *_File,const wchar_t *_Format,...); int __cdecl wprintf_s(const wchar_t *_Format,...); int __cdecl vfwprintf_s(FILE *_File,const wchar_t *_Format,va_list _ArgList); int __cdecl
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
On Thu, 23 Nov 2017, Sven Kretzschmar wrote: I will try to add the 2 missing references in the way you hinted at in your post. FWIW, for the _cprintf one, the conio.h patch that I sent should be a proper fix. The other one requires fixing stdio_s.h, and it's a truly huge number of functions there. I started looking at it, but don't have time to do them all right now. Attached is my work in progress for this header, that should cover at least the function that you mentioned so far. That one isn't sent for review yet as it's quite incomplete. OTOH, perhaps it's better to at least fix up some subsets of it, that happens to be used, instead of aiming for all of them. // MartinFrom 53f8cc4ba4ec693fb0324e220b7e4b952635fb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Fri, 24 Nov 2017 13:58:21 +0200 Subject: [PATCH] WIP: Map some functions in stdio_s.h for ucrtbase This is still incomplete. --- mingw-w64-headers/crt/sec_api/stdio_s.h | 202 +++- 1 file changed, 196 insertions(+), 6 deletions(-) diff --git a/mingw-w64-headers/crt/sec_api/stdio_s.h b/mingw-w64-headers/crt/sec_api/stdio_s.h index 092f337..08f519d 100644 --- a/mingw-w64-headers/crt/sec_api/stdio_s.h +++ b/mingw-w64-headers/crt/sec_api/stdio_s.h @@ -26,8 +26,195 @@ extern "C" { #ifndef _STDIO_S_DEFINED #define _STDIO_S_DEFINED _CRTIMP errno_t __cdecl clearerr_s(FILE *_File); - int __cdecl fprintf_s(FILE *_File,const char *_Format,...); + size_t __cdecl fread_s(void *_DstBuf,size_t _DstSize,size_t _ElementSize,size_t _Count,FILE *_File); + +#if __MSVCRT_VERSION__ >= 0x1400 + int __cdecl __stdio_common_vsprintf_s(unsigned __int64 _Options, char *_Str, size_t _Len, const char *_Format, _locale_t _Locale, va_list _ArgList); + int __cdecl __stdio_common_vsnprintf_s(unsigned __int64 _Options, char *_Str, size_t _Len, size_t _MaxCount, const char *_Format, _locale_t _Locale, va_list _ArgList); + int __cdecl __stdio_common_vsprintf_p(unsigned __int64 _Options, char *_Str, size_t _Len, const char *_Format, _locale_t _Locale, va_list _ArgList); + int __cdecl __stdio_common_vfprintf_s(unsigned __int64 _Options, FILE *_File, const char *_Format, _locale_t _Locale, va_list _ArgList); + int __cdecl __stdio_common_vfprintf_p(unsigned __int64 _Options, FILE *_File, const char *_Format, _locale_t _Locale, va_list _ArgList); + + __mingw_ovr int __cdecl fprintf_s(FILE *_File,const char *_Format,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Format); +_Ret = __stdio_common_vfprintf_s(0, _File, _Format, NULL, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + __mingw_ovr int __cdecl _fscanf_s_l(FILE *_File,const char *_Format,_locale_t _Locale,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Locale); +_Ret = __stdio_common_vfscanf_s(0, _File, _Format, _Locale, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + __mingw_ovr int __cdecl printf_s(const char *_Format,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Format); +_Ret = __stdio_common_vfprintf_s(0, stdout, _Format, NULL, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + __mingw_ovr int __cdecl _scanf_l(const char *_Format,_locale_t _Locale,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Locale); +_Ret = __stdio_common_vfscanf(0, stdin, _Format, _Locale, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + __mingw_ovr int __cdecl _scanf_s_l(const char *_Format,_locale_t _Locale,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Locale); +_Ret = __stdio_common_vfscanf_s(0, stdin, _Format, _Locale, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + // TODO: Not mapped for ucrtbase yet + _CRTIMP int __cdecl _snprintf_c(char *_DstBuf,size_t _MaxCount,const char *_Format,...); + _CRTIMP int __cdecl _vsnprintf_c(char *_DstBuf,size_t _MaxCount,const char *_Format,va_list _ArgList); + + __mingw_ovr int __cdecl _fscanf_l(FILE *_File,const char *_Format,_locale_t _Locale,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Locale); +_Ret = __stdio_common_vfscanf(0, _File, _Format, _Locale, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + __mingw_ovr int __cdecl _sscanf_l(const char *_Src,const char *_Format,_locale_t _Locale,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgList, _Locale); +_Ret = __stdio_common_vsscanf(0, _Src, (size_t)-1, _Format, _Locale, _ArgList); +__builtin_va_end(_ArgList); +return _Ret; + } + __mingw_ovr int __cdecl _sscanf_s_l(const char *_Src,const char *_Format,_locale_t _Locale,...) + { +__builtin_va_list _ArgList; +int _Ret; +__builtin_va_start(_ArgLi
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
On Thu, 23 Nov 2017, Sven Kretzschmar wrote: Currently I get a new strange error while compiling the Julia sources with the new toolchain: /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrt_sprintf.o):/home/sven/buildtmp/ build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/stdio/ucrt_sprintf.c:20: multiple definition of `__imp_snprintf' /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrt_snprintf.o):/home/sven/buildtmp /build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/stdio/ucrt_snprintf.c:20: first defined here Is it possible that your last ucrtbase patch contained a typo ? : diff --git a/mingw-w64-crt/stdio/ucrt_sprintf.c b/mingw-w64-crt/stdio/ucrt_sprintf.c index 74d665d..b9029d5 100644 --- a/mingw-w64-crt/stdio/ucrt_sprintf.c +++ b/mingw-w64-crt/stdio/ucrt_sprintf.c @@ -17,3 +17,4 @@ int __cdecl sprintf(char * __restrict__ _Dest,const char * __restrict__ _Format, __builtin_va_end(ap); return ret; } +int __cdecl (*__MINGW_IMP_SYMBOL(snprintf))(char *__restrict__, const <== Typo here ? (snprintf -> sprintf) ? *** +char *__restrict__, ...) = sprintf; Oh, oops - yes, this is a typo. I pushed a fix now. // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
Hi Martin, Thanks a lot for your support in getting ucrtbase to work. I will try to add the 2 missing references in the way you hinted at in your post. Currently I get a new strange error while compiling the Julia sources with the new toolchain: /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrt_sprintf.o):/home/sven/buildtmp/ build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/stdio/ucrt_sprintf.c:20: multiple definition of `__imp_snprintf' /CROSS64/lib/gcc/x86_64-w64-mingw32/6.4.0/../../../../x86_64-w64-mingw32/lib /../lib/libmsvcrt.a(lib64_libucrtbase_a-ucrt_snprintf.o):/home/sven/buildtmp /build/mingw-crt/../../src/mingw-w64/mingw-w64-crt/stdio/ucrt_snprintf.c:20: first defined here Is it possible that your last ucrtbase patch contained a typo ? : diff --git a/mingw-w64-crt/stdio/ucrt_sprintf.c b/mingw-w64-crt/stdio/ucrt_sprintf.c index 74d665d..b9029d5 100644 --- a/mingw-w64-crt/stdio/ucrt_sprintf.c +++ b/mingw-w64-crt/stdio/ucrt_sprintf.c @@ -17,3 +17,4 @@ int __cdecl sprintf(char * __restrict__ _Dest,const char * __restrict__ _Format, __builtin_va_end(ap); return ret; } +int __cdecl (*__MINGW_IMP_SYMBOL(snprintf))(char *__restrict__, const <== Typo here ? (snprintf -> sprintf) ? *** +char *__restrict__, ...) = sprintf; Thanks & Cheers - Sven -Original Message- From: Martin Storsjö [mailto:mar...@martin.st] Sent: 23 November 2017 12:15 To: Kai Tietz via Mingw-w64-public Subject: Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported On Thu, 23 Nov 2017, Martin Storsjö wrote: > On Thu, 23 Nov 2017, Kai Tietz via Mingw-w64-public wrote: > >> Martin, >> >> patch looks ok. Be careful about the static symbol in custom section >> that it is actually present in a finally linked version. Sometimes >> gcc thinks ... that it can optimize away such static symbols. I had >> to introduce for that dummy references to such symbols in the past. >> See crt/* folder for that. > > Yup, in this case I used __attribute__((__used__)) for that. > > // Martin Pushed - with one minor adjustment (we didn't need any __MINGW_IMP_SYMBOL(_tzset), and by adding one it would recurse infinitely). // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
On Thu, 23 Nov 2017, Martin Storsjö wrote: On Thu, 23 Nov 2017, Kai Tietz via Mingw-w64-public wrote: Martin, patch looks ok. Be careful about the static symbol in custom section that it is actually present in a finally linked version. Sometimes gcc thinks ... that it can optimize away such static symbols. I had to introduce for that dummy references to such symbols in the past. See crt/* folder for that. Yup, in this case I used __attribute__((__used__)) for that. // Martin Pushed - with one minor adjustment (we didn't need any __MINGW_IMP_SYMBOL(_tzset), and by adding one it would recurse infinitely). // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
On Thu, 23 Nov 2017, Kai Tietz via Mingw-w64-public wrote: Martin, patch looks ok. Be careful about the static symbol in custom section that it is actually present in a finally linked version. Sometimes gcc thinks ... that it can optimize away such static symbols. I had to introduce for that dummy references to such symbols in the past. See crt/* folder for that. Yup, in this case I used __attribute__((__used__)) for that. // Martin -- Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot ___ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
Re: [Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
Martin, patch looks ok. Be careful about the static symbol in custom section that it is actually present in a finally linked version. Sometimes gcc thinks ... that it can optimize away such static symbols. I had to introduce for that dummy references to such symbols in the past. See crt/* folder for that. Cheers, Kai 2017-11-23 10:43 GMT+01:00 Martin Storsjö : > When linking a DLL without using dllexport attributes or a def > file, all global symbols are exported, unless they are excluded > for one reason or another. GNU ld has got a list of libraries and > object files to exclude, so any symbols from e.g. libmingwex or > libmingw32 or dllcrt2.o won't get exported. > > However, libmsvcrt is missing from that list (and libucrtbase > obviously isn't present either). In LLD, libmsvcrt and libucrtbase > are part of the library exclude list. > > By linking with -Wl,--exclude-libs,libucrtbase.a, one can manually > request to exclude any symbols from this library. > > There are a number of exceptions to the rules for autoexporting > (which aren't clearly documented but can be found in ld/pe-dll.c > in GNU binutils). One that seems to cover the cases that currently > are found in libmsvcrt.a, explaining why such symbols haven't > been exported before, is that a symbol foo won't be exported, if a > corresponding symbol __imp_foo also is defined. > > We can use this to add __imp_ prefixed symbols for symbols that > strictly don't need it (where no calling code currently refers to > it with a dllimport attribute). > > Make the _CRTALLOC pointer static with an attribute indicating that > it is used and should be kept even though unreferenced. > > All in all, this avoids exporting unintentional symbols from DLLs > that link to ucrtbase, even though it might be desireable to > add libmsvcrt and libucrtbase to the built-in exclude list as well. > > Signed-off-by: Martin Storsjö > --- > mingw-w64-crt/crt/ucrtbase_compat.c | 16 +++- > mingw-w64-crt/stdio/ucrt__vsnprintf.c | 1 + > mingw-w64-crt/stdio/ucrt_fprintf.c| 1 + > mingw-w64-crt/stdio/ucrt_printf.c | 1 + > mingw-w64-crt/stdio/ucrt_snprintf.c | 1 + > mingw-w64-crt/stdio/ucrt_sprintf.c| 1 + > mingw-w64-crt/stdio/ucrt_vfprintf.c | 1 + > mingw-w64-crt/stdio/ucrt_vprintf.c| 1 + > mingw-w64-crt/stdio/ucrt_vsnprintf.c | 1 + > mingw-w64-crt/stdio/ucrt_vsprintf.c | 1 + > 10 files changed, 24 insertions(+), 1 deletion(-) > > diff --git a/mingw-w64-crt/crt/ucrtbase_compat.c > b/mingw-w64-crt/crt/ucrtbase_compat.c > index 53e44f6..9d580df 100644 > --- a/mingw-w64-crt/crt/ucrtbase_compat.c > +++ b/mingw-w64-crt/crt/ucrtbase_compat.c > @@ -153,7 +153,7 @@ static void __cdecl init_compat_dtor(void) >atexit(free_locks); > } > > -_CRTALLOC(".CRT$XID") _PVFV mingw_ucrtbase_compat_init = init_compat_dtor; > +static _CRTALLOC(".CRT$XID") __attribute__((__used__)) _PVFV > mingw_ucrtbase_compat_init = init_compat_dtor; > > > // These are required to provide the unrepfixed data symbols "timezone" > @@ -226,6 +226,20 @@ int __cdecl __ms_fwprintf(FILE *file, const wchar_t > *fmt, ...) >va_end(ap); >return ret; > } > + > +// Dummy/unused __imp_ wrappers, to make GNU ld not autoexport these symbols. > +int __cdecl (*__MINGW_IMP_SYMBOL(__getmainargs))(int *, char ***, char ***, > int, _startupinfo *) = __getmainargs; > +int __cdecl (*__MINGW_IMP_SYMBOL(__wgetmainargs))(int *, wchar_t ***, > wchar_t ***, int, _startupinfo *) = __wgetmainargs; > +_onexit_t __cdecl (*__MINGW_IMP_SYMBOL(__dllonexit))(_onexit_t, _PVFV**, > _PVFV**) = __dllonexit; > +void __cdecl (*__MINGW_IMP_SYMBOL(_amsg_exit))(int) = _amsg_exit; > +unsigned int __cdecl (*__MINGW_IMP_SYMBOL(_get_output_format))(void) = > _get_output_format; > +void __cdecl (*__MINGW_IMP_SYMBOL(_tzset))(void) = _tzset; > +void __cdecl (*__MINGW_IMP_SYMBOL(tzset))(void) = tzset; > +void __cdecl (*__MINGW_IMP_SYMBOL(_lock))(int) = _lock; > +void __cdecl (*__MINGW_IMP_SYMBOL(_unlock))(int) = _unlock; > +int __cdecl (*__MINGW_IMP_SYMBOL(fwprintf))(FILE *, const wchar_t *, ...) = > fwprintf; > +int __cdecl (*__MINGW_IMP_SYMBOL(_snwprintf))(wchar_t *restrict, size_t, > const wchar_t *restrict, ...) = _snwprintf; > +int __cdecl (*__MINGW_IMP_SYMBOL(__ms_fwprintf))(FILE *, const wchar_t *, > ...) = __ms_fwprintf; > #ifdef __GNUC__ > #pragma GCC diagnostic pop > #endif > diff --git a/mingw-w64-crt/stdio/ucrt__vsnprintf.c > b/mingw-w64-crt/stdio/ucrt__vsnprintf.c > index 6828007..58f29f1 100644 > --- a/mingw-w64-crt/stdio/ucrt__vsnprintf.c > +++ b/mingw-w64-crt/stdio/ucrt__vsnprintf.c > @@ -12,3 +12,4 @@ int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t > _Count,const char * __re > { >return > __stdio_common_vsprintf(UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, > _Dest, _Count, _Format, NULL, _Args); > } > +int __cdecl (*__MINGW_IMP_SYMBOL(_vsnprintf))(char *__restrict__, size_t, > const char *__restrict__, va_list) = _vsnprintf; > diff --git a/mi
[Mingw-w64-public] [PATCH] ucrtbase: Make sure that compat symbols aren't autoexported
When linking a DLL without using dllexport attributes or a def file, all global symbols are exported, unless they are excluded for one reason or another. GNU ld has got a list of libraries and object files to exclude, so any symbols from e.g. libmingwex or libmingw32 or dllcrt2.o won't get exported. However, libmsvcrt is missing from that list (and libucrtbase obviously isn't present either). In LLD, libmsvcrt and libucrtbase are part of the library exclude list. By linking with -Wl,--exclude-libs,libucrtbase.a, one can manually request to exclude any symbols from this library. There are a number of exceptions to the rules for autoexporting (which aren't clearly documented but can be found in ld/pe-dll.c in GNU binutils). One that seems to cover the cases that currently are found in libmsvcrt.a, explaining why such symbols haven't been exported before, is that a symbol foo won't be exported, if a corresponding symbol __imp_foo also is defined. We can use this to add __imp_ prefixed symbols for symbols that strictly don't need it (where no calling code currently refers to it with a dllimport attribute). Make the _CRTALLOC pointer static with an attribute indicating that it is used and should be kept even though unreferenced. All in all, this avoids exporting unintentional symbols from DLLs that link to ucrtbase, even though it might be desireable to add libmsvcrt and libucrtbase to the built-in exclude list as well. Signed-off-by: Martin Storsjö --- mingw-w64-crt/crt/ucrtbase_compat.c | 16 +++- mingw-w64-crt/stdio/ucrt__vsnprintf.c | 1 + mingw-w64-crt/stdio/ucrt_fprintf.c| 1 + mingw-w64-crt/stdio/ucrt_printf.c | 1 + mingw-w64-crt/stdio/ucrt_snprintf.c | 1 + mingw-w64-crt/stdio/ucrt_sprintf.c| 1 + mingw-w64-crt/stdio/ucrt_vfprintf.c | 1 + mingw-w64-crt/stdio/ucrt_vprintf.c| 1 + mingw-w64-crt/stdio/ucrt_vsnprintf.c | 1 + mingw-w64-crt/stdio/ucrt_vsprintf.c | 1 + 10 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mingw-w64-crt/crt/ucrtbase_compat.c b/mingw-w64-crt/crt/ucrtbase_compat.c index 53e44f6..9d580df 100644 --- a/mingw-w64-crt/crt/ucrtbase_compat.c +++ b/mingw-w64-crt/crt/ucrtbase_compat.c @@ -153,7 +153,7 @@ static void __cdecl init_compat_dtor(void) atexit(free_locks); } -_CRTALLOC(".CRT$XID") _PVFV mingw_ucrtbase_compat_init = init_compat_dtor; +static _CRTALLOC(".CRT$XID") __attribute__((__used__)) _PVFV mingw_ucrtbase_compat_init = init_compat_dtor; // These are required to provide the unrepfixed data symbols "timezone" @@ -226,6 +226,20 @@ int __cdecl __ms_fwprintf(FILE *file, const wchar_t *fmt, ...) va_end(ap); return ret; } + +// Dummy/unused __imp_ wrappers, to make GNU ld not autoexport these symbols. +int __cdecl (*__MINGW_IMP_SYMBOL(__getmainargs))(int *, char ***, char ***, int, _startupinfo *) = __getmainargs; +int __cdecl (*__MINGW_IMP_SYMBOL(__wgetmainargs))(int *, wchar_t ***, wchar_t ***, int, _startupinfo *) = __wgetmainargs; +_onexit_t __cdecl (*__MINGW_IMP_SYMBOL(__dllonexit))(_onexit_t, _PVFV**, _PVFV**) = __dllonexit; +void __cdecl (*__MINGW_IMP_SYMBOL(_amsg_exit))(int) = _amsg_exit; +unsigned int __cdecl (*__MINGW_IMP_SYMBOL(_get_output_format))(void) = _get_output_format; +void __cdecl (*__MINGW_IMP_SYMBOL(_tzset))(void) = _tzset; +void __cdecl (*__MINGW_IMP_SYMBOL(tzset))(void) = tzset; +void __cdecl (*__MINGW_IMP_SYMBOL(_lock))(int) = _lock; +void __cdecl (*__MINGW_IMP_SYMBOL(_unlock))(int) = _unlock; +int __cdecl (*__MINGW_IMP_SYMBOL(fwprintf))(FILE *, const wchar_t *, ...) = fwprintf; +int __cdecl (*__MINGW_IMP_SYMBOL(_snwprintf))(wchar_t *restrict, size_t, const wchar_t *restrict, ...) = _snwprintf; +int __cdecl (*__MINGW_IMP_SYMBOL(__ms_fwprintf))(FILE *, const wchar_t *, ...) = __ms_fwprintf; #ifdef __GNUC__ #pragma GCC diagnostic pop #endif diff --git a/mingw-w64-crt/stdio/ucrt__vsnprintf.c b/mingw-w64-crt/stdio/ucrt__vsnprintf.c index 6828007..58f29f1 100644 --- a/mingw-w64-crt/stdio/ucrt__vsnprintf.c +++ b/mingw-w64-crt/stdio/ucrt__vsnprintf.c @@ -12,3 +12,4 @@ int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const char * __re { return __stdio_common_vsprintf(UCRTBASE_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION, _Dest, _Count, _Format, NULL, _Args); } +int __cdecl (*__MINGW_IMP_SYMBOL(_vsnprintf))(char *__restrict__, size_t, const char *__restrict__, va_list) = _vsnprintf; diff --git a/mingw-w64-crt/stdio/ucrt_fprintf.c b/mingw-w64-crt/stdio/ucrt_fprintf.c index 021a12a..f61e002 100644 --- a/mingw-w64-crt/stdio/ucrt_fprintf.c +++ b/mingw-w64-crt/stdio/ucrt_fprintf.c @@ -17,3 +17,4 @@ int __cdecl fprintf(FILE * __restrict__ _File,const char * __restrict__ _Format, __builtin_va_end(ap); return ret; } +int __cdecl (*__MINGW_IMP_SYMBOL(fprintf))(FILE *__restrict__, const char *__restrict__, ...) = fprintf; diff --git a/mingw-w64-crt/stdio/ucrt_printf.c b/mingw-w64-crt/stdio/ucrt_printf.c index d4a6e82..3cbacd7 100644 --- a/mingw-w64-