From b6a947ede19da18e2cf8841b1283db350d7e64a6 Mon Sep 17 00:00:00 2001 From: Earnie Boyd Date: Fri, 21 Sep 2012 13:57:45 -0400 Subject: [PATCH] * Makefile.in (ofmt_stub.o): Add stub to libmsvcrt.a through libmsvcr71d.a. (libmoldname*.a): Change the DLLNAME to msvcr*.dll as appropriate. * include/sdkddkver.h (_WARN_DEFAULTS): New macro filter for warning about defaults to enable building binutils. * include/sys/stat.h: Rework structure definitions and declarations to allow building binutils. (_fstat64i32): New inline function. (_stat64i32): Ditto. * include/winsock.h (_WARN_WINSOCK_H): New macro filter for warning about inclusion of winsock.h to allow building binutils. --- ChangeLog | 14 ++++ Makefile.in | 24 +++++-- include/sdkddkver.h | 8 ++- include/sys/stat.h | 199 +++++++++++++++++++++++++++++----------------------- include/winsock.h | 2 +- 5 files changed, 152 insertions(+), 95 deletions(-) diff --git a/ChangeLog b/ChangeLog index 208bc72..1a2baed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2012-09-21 Earnie Boyd + + * Makefile.in (ofmt_stub.o): Add stub to libmsvcrt.a through + libmsvcr71d.a. + (libmoldname*.a): Change the DLLNAME to msvcr*.dll as appropriate. + * include/sdkddkver.h (_WARN_DEFAULTS): New macro filter for warning + about defaults to enable building binutils. + * include/sys/stat.h: Rework structure definitions and declarations to + allow building binutils. + (_fstat64i32): New inline function. + (_stat64i32): Ditto. + * include/winsock.h (_WARN_WINSOCK_H): New macro filter for warning + about inclusion of winsock.h to allow building binutils. + 2012-09-20 Earnie Boyd Redo the filters based on assumptions discussed in mingw-dvlpr list. diff --git a/Makefile.in b/Makefile.in index d32a229..20b232a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -115,8 +115,10 @@ crt0_SOURCES := \ $(SRCDIR)/CRT_fp8.c \ $(SRCDIR)/CRT_fp10.c \ $(SRCDIR)/txtmode.c \ - $(SRCDIR)/binmode.c + $(SRCDIR)/binmode.c \ + $(SRCDIR)/ofmt_stub.s crt0_OBJECTS := $(crt0_SOURCES:.c=.o) $(SRCDIR)/crt2.o $(SRCDIR)/dllcrt2.o +crt0_OBJECTS := $(crt0_OBJECTS:.s=.o) SRCDIR := src/libcrt/crt mingwm10_dll_SOURCES := \ @@ -629,7 +631,6 @@ $(msvcrt_DEF): lib/lib32/msvcrt.def.in -C -E -P -xc-header \ $? > $@ - $(moldname_DEF): lib/lib32/moldname.def.in N=`echo $@ | sed -e 's|\([a-z]*\)\([0-9]*\).*|\1|'`; \ test "$$N" == "msvcr" && N="msvcrt"; \ @@ -667,11 +668,16 @@ $(notdir $(winapi_lib_DIRECTX_LIBRARIES)): $(addprefix lib/lib32/directx/,$(wina $(DLLTOOL) $(DLLTOOL_FLAGS) $(subst lib,,$(@:.a=.dll)) --def $(addprefix $(top_srcdir)/lib/lib32/directx/,$(subst lib,,$(@:.a=.def))) --output-lib $@ $(RANLIB) $@ +libmoldname.a: moldname.def + @echo Making library $@ from $?. + DLLNAME="msvcrt.dll"; \ + $(DLLTOOL) $(DLLTOOL_FLAGS) $${DLLNAME} -U --def $< --output-lib $@ + $(RANLIB) $@ + libmoldname%.a: moldname%.def @echo Making library $@ from $?. - N=`echo $@ | sed -e 's|lib\([a-z]*\)\([0-9]*\).*|\1|'`; \ V=`echo $@ | sed -e 's|lib\([a-z]*\)\([0-9]*\).*|\2|'`; \ - DLLNAME="$${N}$${V}.dll"; \ + DLLNAME="msvcr$${V}.dll"; \ $(DLLTOOL) $(DLLTOOL_FLAGS) $${DLLNAME} -U --def $< --output-lib $@ $(RANLIB) $@ @@ -680,7 +686,15 @@ lib%.a: %.def N=`echo $@ | sed -e 's|lib\([a-z]*\)\([0-9]*\).*|\1|'`; \ V=`echo $@ | sed -e 's|lib\([a-z]*\)\([0-9]*\).*|\2|'`; \ DLLNAME="$${N}$${V}.dll"; \ - $(DLLTOOL) $(DLLTOOL_FLAGS) $${DLLNAME} --def $< --output-lib $@ + $(DLLTOOL) $(DLLTOOL_FLAGS) $${DLLNAME} --def $< --output-lib $@ ; \ + if [[ $${DLLNAME} = msvcrt.dll || \ + $${DLLNAME} = msvcrtd.dll || \ + $${DLLNAME} = msvcr70.dll || \ + $${DLLNAME} = msvcr70d.dll || \ + $${DLLNAME} = msvcr71.dll || \ + $${DLLNAME} = msvcr71d.dll ]]; then \ + $(AR) rc $@ src/libcrt/crt/ofmt_stub.o; \ + fi $(RANLIB) $@ lib%.a: %.o diff --git a/include/sdkddkver.h b/include/sdkddkver.h index a2d8066..8323eeb 100644 --- a/include/sdkddkver.h +++ b/include/sdkddkver.h @@ -146,7 +146,9 @@ # ifdef WINVER # define _WIN32_WINNT WINVER # else -# warning _WIN32_WINNT is defaulting to _WIN32_WINNT_WIN2K +# ifdef _WARN_DEFAULTS +# warning _WIN32_WINNT is defaulting to _WIN32_WINNT_WIN2K +# endif # define _WIN32_WINNT _WIN32_WINNT_WIN2K # endif #endif @@ -156,7 +158,9 @@ #endif #ifndef NTDDI_VERSION -# warning NTDDI_VERSION is defaulting to _WIN32_WINNT version SPK0 +# ifdef _WARN_DEFAULTS +# warning NTDDI_VERSION is defaulting to _WIN32_WINNT version SPK0 +# endif # define NTDDI_VERSION NTDDI_VERSION_FROM_WIN32_WINNT(_WIN32_WINNT) #endif diff --git a/include/sys/stat.h b/include/sys/stat.h index 9bb85aa..75e84d7 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -94,25 +94,25 @@ * invalid, they will cause localtime et. al. to return NULL. And calling * asctime with a NULL pointer causes an Invalid Page Fault. So watch it! */ -struct _stat +struct _stat32 { - _dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */ - _ino_t st_ino; /* Always zero ? */ - _mode_t st_mode; /* See above constants */ - short st_nlink; /* Number of links. */ - short st_uid; /* User: Maybe significant on NT ? */ - short st_gid; /* Group: Ditto */ - _dev_t st_rdev; /* Seems useless (not even filled in) */ - _off_t st_size; /* File size in bytes */ - time_t st_atime; /* Accessed date (always 00:00 hrs local + _dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */ + _ino_t st_ino; /* Always zero ? */ + _mode_t st_mode; /* See above constants */ + short st_nlink; /* Number of links. */ + short st_uid; /* User: Maybe significant on NT ? */ + short st_gid; /* Group: Ditto */ + _dev_t st_rdev; /* Seems useless (not even filled in) */ + _off_t st_size; /* File size in bytes */ + __time32_t st_atime; /* Accessed date (always 00:00 hrs local * on FAT) */ - time_t st_mtime; /* Modified time */ - time_t st_ctime; /* Creation time */ + __time32_t st_mtime; /* Modified time */ + __time32_t st_ctime; /* Creation time */ }; #ifndef _NO_OLDNAMES /* NOTE: Must be the same as _stat above. */ -struct stat +struct xstat { dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */ ino_t st_ino; /* Always zero ? */ @@ -129,6 +129,21 @@ struct stat }; #endif /* _NO_OLDNAMES */ +struct _stat64 { + dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */ + ino_t st_ino; /* Always zero ? */ + mode_t st_mode; /* See above constants */ + short st_nlink; /* Number of links. */ + short st_uid; /* User: Maybe significant on NT ? */ + short st_gid; /* Group: Ditto */ + dev_t st_rdev; /* Seems useless (not even filled in) */ + __int64 st_size; /* File size in bytes */ + __time64_t st_atime; /* Accessed date (always 00:00 hrs local + * on FAT) */ + __time64_t st_mtime; /* Modified time */ + __time64_t st_ctime; /* Creation time */ +}; + struct _stati64 { _dev_t st_dev; _ino_t st_ino; @@ -142,34 +157,6 @@ struct _stati64 { time_t st_mtime; time_t st_ctime; }; -struct __stat64 -{ - _dev_t st_dev; - _ino_t st_ino; - _mode_t st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int64 st_size; - __time64_t st_atime; - __time64_t st_mtime; - __time64_t st_ctime; -}; -struct __stat32 -{ - _dev_t st_dev; - _ino_t st_ino; - _mode_t st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - __int32 st_size; - __time32_t st_atime; - __time32_t st_mtime; - __time32_t st_ctime; -}; struct _stat32i64 { _dev_t st_dev; _ino_t st_ino; @@ -196,6 +183,19 @@ struct _stat64i32 { __time64_t st_mtime; __time64_t st_ctime; }; + +#define __stat64 _stat64 +#ifdef _USE_32BIT_TIME_T +#define _fstat _fstat32 +#define _fstati64 _fstat32i64 +#define _stat _stat32 +#define _stati64 _stat32i64 +#else /* !_USE_32BIT_TIME_T */ +#define _fstat _fstat64i32 +#define _fstati64 _fstat64 +#define _stat _stat64i32 +#define _stati64 _stat64 +#endif /* _USE_32BIT_TIME_T */ #define _STAT_DEFINED #endif /* _STAT_DEFINED */ @@ -203,59 +203,84 @@ struct _stat64i32 { extern "C" { #endif -_CRTIMP int __cdecl __MINGW_NOTHROW _fstat (int, struct _stat*); -_CRTIMP int __cdecl __MINGW_NOTHROW _chmod (const char*, int); -_CRTIMP int __cdecl __MINGW_NOTHROW _stat (const char*, struct _stat*); - -#ifndef _NO_OLDNAMES -/* These functions live in liboldnames.a. */ -_CRTIMP int __cdecl __MINGW_NOTHROW fstat (int, struct stat*); -_CRTIMP int __cdecl __MINGW_NOTHROW chmod (const char*, int); -_CRTIMP int __cdecl __MINGW_NOTHROW stat (const char*, struct stat*); - -#endif /* Not _NO_OLDNAMES */ - -_CRTIMP int __cdecl __MINGW_NOTHROW _fstati64(int, struct _stati64 *); -_CRTIMP int __cdecl __MINGW_NOTHROW _stati64(const char *, struct _stati64 *); -/* These require newer versions of msvcrt.dll (6.10 or higher). */ -_CRTIMP int __cdecl __MINGW_NOTHROW _fstat64 (int, struct __stat64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _stat64 (const char*, struct __stat64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _fstat32 (int, struct __stat32*); -_CRTIMP int __cdecl __MINGW_NOTHROW _stat32 (const char*, struct __stat32*); -_CRTIMP int __cdecl __MINGW_NOTHROW _fstat32i64 (int, struct _stat32i64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _fstat64i32 (int, struct _stat64i32*); -_CRTIMP int __cdecl __MINGW_NOTHROW _stat32i64 (const char*, struct _stat32i64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _stat64i32 (const char*, struct _stat64i32*); -#ifndef _USE_32BIT_TIME_T -_CRTALIAS int __cdecl __MINGW_NOTHROW _fstat (int _v1, struct _stat* _v2) { return(_fstat64i32 (_v1,(struct _stat64i32*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _stat (const char* _v1, struct _stat* _v2) { return(_stat64i32 (_v1,(struct _stat64i32*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _fstati64 (int _v1, struct _stati64* _v2) { return(_fstat64 (_v1,(struct __stat64*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _stati64 (const char* _v1, struct _stati64* _v2) { return(_stat64 (_v1,(struct __stat64*)_v2)); } +_CRTIMP int __cdecl __MINGW_NOTHROW _stat32 (const char*, struct _stat32*); +_CRTIMP int __cdecl __MINGW_NOTHROW _stat64 (const char*, struct _stat64*); +_CRTIMP int __cdecl __MINGW_NOTHROW _stat32i64 (const char*, struct _stat32i64*); +_CRTIMP int __cdecl __MINGW_NOTHROW _stat64i32 (const char*, struct _stat64i32*); +_CRTIMP int __cdecl __MINGW_NOTHROW _fstat32 (int, struct _stat32*); +_CRTIMP int __cdecl __MINGW_NOTHROW _fstat64 (int, struct _stat64*); +_CRTIMP int __cdecl __MINGW_NOTHROW _fstat32i64 (int, struct _stat32i64*); +_CRTIMP int __cdecl __MINGW_NOTHROW _fstat64i32 (int, struct _stat64i32*); +#ifndef __NO_INLINE__ + __CRT_INLINE int __cdecl _fstat64i32(int desc, struct _stat64i32 *_stat) + { + struct _stat64 st; + int ret = _fstat64(desc, &st); + if (ret == -1) { + memset(_stat, 0, sizeof(struct _stat64i32)); + return -1; + } + _stat->st_dev = st.st_dev; + _stat->st_ino = st.st_ino; + _stat->st_mode = st.st_mode; + _stat->st_nlink = st.st_nlink; + _stat->st_uid = st.st_uid; + _stat->st_gid = st.st_gid; + _stat->st_rdev = st.st_rdev; + _stat->st_size = (_off_t) st.st_size; + _stat->st_atime = st.st_atime; + _stat->st_mtime = st.st_mtime; + _stat->st_ctime = st.st_ctime; + return ret; + } + __CRT_INLINE int __cdecl _stat64i32(const char *fname, struct _stat64i32 *_stat) + { + struct _stat64 st; + int ret = _stat64(fname, &st); + if (ret == -1) { + memset(_stat, 0, sizeof(struct _stat64i32)); + return -1; + } + _stat->st_dev = st.st_dev; + _stat->st_ino = st.st_ino; + _stat->st_mode = st.st_mode; + _stat->st_nlink = st.st_nlink; + _stat->st_uid = st.st_uid; + _stat->st_gid = st.st_gid; + _stat->st_rdev = st.st_rdev; + _stat->st_size = (_off_t) st.st_size; + _stat->st_atime = st.st_atime; + _stat->st_mtime = st.st_mtime; + _stat->st_ctime = st.st_ctime; + return ret; + } +#endif +#if !defined(__NO_INLINE__) && !defined(__STRICT_ANSI__) +#ifdef _USE_32BIT_TIME_T +#define stat(a,b) _stat32(a,b) +#define fstat(a,b) _fstat32(a,b) #else - -_CRTALIAS int __cdecl __MINGW_NOTHROW _fstat (int _v1, struct _stat* _v2) { return(_fstat32 (_v1,(struct __stat32*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _stat (const char* _v1, struct _stat* _v2) { return(_stat32 (_v1,(struct __stat32*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _fstati64 (int _v1, struct _stati64* _v2) { return(_fstat32i64 (_v1,(struct _stat32i64*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _stati64 (const char* _v1, struct _stati64* _v2) { return(_stat32i64 (_v1,(struct _stat32i64*)_v2)); } -#endif /* !_USE_32BIT_TIME_T */ - +#define stat(a,b) _stat64i32(a,b) +#define fstat(a,b) _fstat64i32(a,b) +#endif +#define stat _stat +#define fstat _fstat +#endif /* !defined(__NO_INLINE__) && !defined(__STRICT_ANSI__) */ #if !defined ( _WSTAT_DEFINED) /* also declared in wchar.h */ -_CRTIMP int __cdecl __MINGW_NOTHROW _wstat(const wchar_t*, struct _stat*); -_CRTIMP int __cdecl __MINGW_NOTHROW _wstati64 (const wchar_t*, struct _stati64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _wstat64 (const wchar_t*, struct __stat64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _wstat32 (const wchar_t*, struct __stat32*); -_CRTIMP int __cdecl __MINGW_NOTHROW _wstat32i64 (const wchar_t*, struct _stat32i64*); -_CRTIMP int __cdecl __MINGW_NOTHROW _wstat64i32 (const wchar_t*, struct _stat64i32*); +_CRTIMP int __cdecl __MINGW_NOTHROW _wstat32 (const wchar_t*, struct _stat32*); +_CRTIMP int __cdecl __MINGW_NOTHROW _wstat64 (const wchar_t*, struct _stat64*); +_CRTIMP int __cdecl __MINGW_NOTHROW _wstat32i64 (const wchar_t*, struct _stat32i64*); +_CRTIMP int __cdecl __MINGW_NOTHROW _wstat64i32 (const wchar_t*, struct _stat64i32*); -#ifndef _USE_32BIT_TIME_T -_CRTALIAS int __cdecl __MINGW_NOTHROW _wstat (const wchar_t* _v1, struct _stat* _v2) { return(_wstat64i32 (_v1,(struct _stat64i32*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _wstati64 (const wchar_t* _v1, struct _stati64* _v2) { return(_wstat64 (_v1,(struct __stat64*)_v2)); } +#ifdef _USE_32BIT_TIME_T +#define _wstat _wstat32 +#define _wstati64 _wstat32i64 #else -_CRTALIAS int __cdecl __MINGW_NOTHROW _wstat (const wchar_t* _v1, struct _stat* _v2) { return(_wstat32 (_v1,(struct __stat32*)_v2)); } -_CRTALIAS int __cdecl __MINGW_NOTHROW _wstati64 (const wchar_t* _v1, struct _stati64* _v2) { return(_wstat32i64 (_v1,(struct _stat32i64*)_v2)); } +#define _wstat _wstat64i32 +#define _wstati64 _wstat64 #endif /* !_USE_32BIT_TIME_T */ #define _WSTAT_DEFINED diff --git a/include/winsock.h b/include/winsock.h index d717585..8c0504a 100644 --- a/include/winsock.h +++ b/include/winsock.h @@ -26,7 +26,7 @@ #pragma GCC system_header #include <_mingw.h> -#if (_WIN32_WINNT >= _WIN32_WINNT_WIN95) +#if (_WIN32_WINNT >= _WIN32_WINNT_WIN95) && defined(_WARN_WINSOCK_H) #warning WARNING Winsock.h is included instead of winsock2.h. #endif -- 2.11.0