Both functions __iob_func() and __p__iob() returns same constant value - pointer to the first member of _iob[] array. Symbol for _iob[] array is present in every msvcrt DLL library.
Function __p__iob() is provided by every i386 version of msvcrt DLL library since VC20. But it is not available in any non-i386 version. Function __iob_func() is provided by every version of msvcrt DLL library since VC70 for every architecture. __iob_func() is provided also by every X64 and ARM versions of OS system version msvcrt.dll. Note that UCRT does not provide neither __iob_func(), nor __p__iob() function. So for all msvcrt versions before VC70 define __iob_func symbol as an alias to __p__iob symbol. And for versions before VC20 provide custom mingw-w64 implementation of __iob_func() function which returns pointer to the first member of _iob[] array. This change allows to remove #ifdef around _iob declaration in stdio.h and wchar.h header files as now the __iob_func() function is provided by every version of msvcrt import library. --- mingw-w64-crt/Makefile.am | 2 ++ mingw-w64-crt/def-include/crt-aliases.def.in | 4 ++++ mingw-w64-crt/lib-common/msvcrt.def.in | 6 +++++- mingw-w64-crt/lib32/msvcr40d.def.in | 1 + mingw-w64-crt/lib32/msvcrt20.def.in | 1 + mingw-w64-crt/lib32/msvcrt40.def.in | 1 + mingw-w64-crt/lib32/msvcrtd.def.in | 1 + mingw-w64-crt/stdio/iob_func.c | 21 ++++++++++++++++++++ mingw-w64-headers/crt/stdio.h | 11 ---------- mingw-w64-headers/crt/wchar.h | 12 ----------- 10 files changed, 36 insertions(+), 24 deletions(-) create mode 100644 mingw-w64-crt/stdio/iob_func.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 0c702b645e4d..04224389d6a0 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -595,6 +595,7 @@ src_crtdll=\ stdio/_scprintf.c \ stdio/_vscprintf.c \ stdio/atoll.c \ + stdio/iob_func.c \ stdio/mingw_dummy__lock.c \ stdio/mingw_lock.c @@ -619,6 +620,7 @@ src_msvcrt10=\ stdio/_scprintf.c \ stdio/_vscprintf.c \ stdio/atoll.c \ + stdio/iob_func.c \ stdio/mingw_dummy__lock.c \ stdio/mingw_lock.c diff --git a/mingw-w64-crt/def-include/crt-aliases.def.in b/mingw-w64-crt/def-include/crt-aliases.def.in index aca031d4b027..885563da1d26 100644 --- a/mingw-w64-crt/def-include/crt-aliases.def.in +++ b/mingw-w64-crt/def-include/crt-aliases.def.in @@ -252,6 +252,10 @@ strncasecmp == _strnicmp _strcmpi == _stricmp #endif +#ifdef WITH_IOB_FUNC_ALIAS +__iob_func == __p__iob +#endif + #ifdef WITH_ATOLL_ALIAS atoll == _atoi64 #endif diff --git a/mingw-w64-crt/lib-common/msvcrt.def.in b/mingw-w64-crt/lib-common/msvcrt.def.in index 69068ae4bb43..b5e55deda2a3 100644 --- a/mingw-w64-crt/lib-common/msvcrt.def.in +++ b/mingw-w64-crt/lib-common/msvcrt.def.in @@ -1109,7 +1109,7 @@ F_X86_ANY(___unguarded_readlc_active_add_func) __crtCompareStringW __crtGetStringTypeW __crtLCMapStringW -__iob_func +F_NON_I386(__iob_func) ; i386 __iob_func replaced by alias __pctype_func __wcserror _aligned_free @@ -1830,6 +1830,10 @@ F_ARM_ANY(fabsf) ; i386 and x64 fabsf provided by emu #define NO_FIXED_SIZE_64_ALIAS #define NO_TIME_ALIAS #define NO_STRCMPI_ALIAS +#ifdef DEF_I386 +; i386 __iob_func replaced by alias +#define WITH_IOB_FUNC_ALIAS +#endif #define WITH_ATOLL_ALIAS #define WITH_ATOLL_L_ALIAS #define WITH_STRTO64_L_ALIAS diff --git a/mingw-w64-crt/lib32/msvcr40d.def.in b/mingw-w64-crt/lib32/msvcr40d.def.in index a7fd678eabab..10737f0e17be 100644 --- a/mingw-w64-crt/lib32/msvcr40d.def.in +++ b/mingw-w64-crt/lib32/msvcr40d.def.in @@ -1698,4 +1698,5 @@ _dstbias DATA #define PRE_C95_SWPRINTF #define FIXED_SIZE_SYMBOLS #define NO_STRCMPI_ALIAS +#define WITH_IOB_FUNC_ALIAS #include "crt-aliases.def.in" diff --git a/mingw-w64-crt/lib32/msvcrt20.def.in b/mingw-w64-crt/lib32/msvcrt20.def.in index fb193fa6b189..d221b5fdec5e 100644 --- a/mingw-w64-crt/lib32/msvcrt20.def.in +++ b/mingw-w64-crt/lib32/msvcrt20.def.in @@ -1580,4 +1580,5 @@ _safe_fprem1 #define FIXED_SIZE_SYMBOLS #define NO_I64_FIXED_SIZE #define NO_STRCMPI_ALIAS +#define WITH_IOB_FUNC_ALIAS #include "crt-aliases.def.in" diff --git a/mingw-w64-crt/lib32/msvcrt40.def.in b/mingw-w64-crt/lib32/msvcrt40.def.in index fb85a50750d9..645d23934998 100644 --- a/mingw-w64-crt/lib32/msvcrt40.def.in +++ b/mingw-w64-crt/lib32/msvcrt40.def.in @@ -1663,4 +1663,5 @@ _dstbias DATA #define PRE_C95_SWPRINTF #define FIXED_SIZE_SYMBOLS #define NO_STRCMPI_ALIAS +#define WITH_IOB_FUNC_ALIAS #include "crt-aliases.def.in" diff --git a/mingw-w64-crt/lib32/msvcrtd.def.in b/mingw-w64-crt/lib32/msvcrtd.def.in index 56f985bca812..873e6c40e3f0 100644 --- a/mingw-w64-crt/lib32/msvcrtd.def.in +++ b/mingw-w64-crt/lib32/msvcrtd.def.in @@ -858,6 +858,7 @@ _chkesp #define NO_FIXED_SIZE_64_ALIAS #define NO_TIME_ALIAS #define NO_STRCMPI_ALIAS +#define WITH_IOB_FUNC_ALIAS #define WITH_ATOLL_ALIAS #define WITH_ATOLL_L_ALIAS #define WITH_STRTO64_L_ALIAS diff --git a/mingw-w64-crt/stdio/iob_func.c b/mingw-w64-crt/stdio/iob_func.c new file mode 100644 index 000000000000..01e92c63a8f1 --- /dev/null +++ b/mingw-w64-crt/stdio/iob_func.c @@ -0,0 +1,21 @@ +/** + * 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. + */ + +#include <_mingw.h> + +typedef struct FILE FILE; + +extern FILE* __MINGW_IMP_SYMBOL(_iob); + +FILE* __cdecl __iob_func(void); +FILE* __cdecl __iob_func(void) +{ + return __MINGW_IMP_SYMBOL(_iob); +} +FILE* (__cdecl *__MINGW_IMP_SYMBOL(__iob_func))(void) = __iob_func; + +FILE* __attribute__ ((alias ("__iob_func"))) __cdecl __p__iob(void); +extern FILE* (__cdecl * __attribute__ ((alias (__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(__iob_func))))) __MINGW_IMP_SYMBOL(__p__iob))(void); diff --git a/mingw-w64-headers/crt/stdio.h b/mingw-w64-headers/crt/stdio.h index c22122c33bc9..39125a000d1b 100644 --- a/mingw-w64-headers/crt/stdio.h +++ b/mingw-w64-headers/crt/stdio.h @@ -100,20 +100,9 @@ extern "C" { _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index); #ifndef _STDIO_DEFINED -#ifdef _WIN64 _CRTIMP FILE *__cdecl __iob_func(void); -#define _iob __iob_func() -#else -#ifdef _MSVCRT_ -extern FILE _iob[]; /* A pointer to an array of FILE */ -#define __iob_func() (_iob) -#else -extern FILE (* __MINGW_IMP_SYMBOL(_iob))[]; /* A pointer to an array of FILE */ -#define __iob_func() (* __MINGW_IMP_SYMBOL(_iob)) #define _iob __iob_func() #endif -#endif -#endif #ifndef _FPOS_T_DEFINED #define _FPOS_T_DEFINED diff --git a/mingw-w64-headers/crt/wchar.h b/mingw-w64-headers/crt/wchar.h index c3bbbcc2339f..c20f5870a48b 100644 --- a/mingw-w64-headers/crt/wchar.h +++ b/mingw-w64-headers/crt/wchar.h @@ -55,19 +55,7 @@ extern "C" { _CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index); #ifndef _STDIO_DEFINED -#ifdef _WIN64 _CRTIMP FILE *__cdecl __iob_func(void); -#define _iob __iob_func() -#else -#ifdef _MSVCRT_ -extern FILE _iob[]; /* A pointer to an array of FILE */ -#define __iob_func() (_iob) -#else -extern FILE (* __MINGW_IMP_SYMBOL(_iob))[]; /* A pointer to an array of FILE */ -#define __iob_func() (* __MINGW_IMP_SYMBOL(_iob)) -#endif -#endif - #define _iob __iob_func() #endif -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public