GNU LD provides __ImageBase symbol since 2.19. This is standard windows
symbol and should be used instead of custom gnu _image_base__ symbol.
Detect non-existence of __ImageBase symbol at ./configure time and for
compatibility with older GNU LD versions, define __ImageBase symbol as
alias to _image_base__ symbol.
This allows to remove all #ifdef hacks for older GNU LD versions as with
this change __ImageBase works correctly with all GNU LD versions.
---
mingw-w64-crt/Makefile.am | 4 ++++
mingw-w64-crt/configure.ac | 6 ++++++
mingw-w64-crt/crt/__imagebase.c | 18 ++++++++++++++++++
mingw-w64-crt/crt/crtexe.c | 5 -----
mingw-w64-crt/crt/crtexewin.c | 3 ---
mingw-w64-crt/crt/pesect.c | 9 ---------
mingw-w64-crt/crt/pseudo-reloc.c | 6 +-----
mingw-w64-crt/libsrc/dloadhelper.c | 1 -
mingw-w64-crt/misc/delayimp.c | 1 -
9 files changed, 29 insertions(+), 24 deletions(-)
create mode 100644 mingw-w64-crt/crt/__imagebase.c
diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 2056b344dd3e..28d74c66a581 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -129,6 +129,10 @@ src_libmingw32=include/oscalls.h include/internal.h
include/sect_attribs.h \
crt/tlsthrd.c crt/tlsmthread.c crt/tlsmcrt.c \
crt/cxa_atexit.c crt/cxa_thread_atexit.c crt/tls_atexit.c
+if !LD_PROVIDES_IMAGEBASE
+src_libmingw32+=crt/__imagebase.c
+endif
+
src_libscrnsave=libsrc/scrnsave.c
src_libscrnsavw=libsrc/scrnsave.c
src_libstrmiids=libsrc/strmiids.c
diff --git a/mingw-w64-crt/configure.ac b/mingw-w64-crt/configure.ac
index 5c68ff967ba7..a6d120857e1e 100644
--- a/mingw-w64-crt/configure.ac
+++ b/mingw-w64-crt/configure.ac
@@ -368,6 +368,12 @@ AC_MSG_RESULT([$enable_tests_unicode])
#AC_FUNC_VPRINTF
#AC_CHECK_FUNCS([alarm atexit btowc fesetround floor ftruncate gettimeofday
isascii localeconv mbrlen memmove memset pow rint setlocale sqrt strcasecmp
strchr strncasecmp strtoull strtoumax])
+# Check for __ImageBase linker symbol.
+AC_MSG_CHECKING([whether the linker provides __ImageBase symbol])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[extern unsigned char __ImageBase[];]],
[[return __ImageBase[0];]])], [ld_provides_imagebase=yes],
[ld_provides_imagebase=no])
+AC_MSG_RESULT([$ld_provides_imagebase])
+AM_CONDITIONAL([LD_PROVIDES_IMAGEBASE],[test $ld_provides_imagebase = yes])
+
AC_CHECK_HEADER([_mingw_mac.h], [], [AC_MSG_ERROR([Please check if the
mingw-w64 header set and the build/host option are set properly.])])
#Warnings and errors, default level is 3
diff --git a/mingw-w64-crt/crt/__imagebase.c b/mingw-w64-crt/crt/__imagebase.c
new file mode 100644
index 000000000000..95715f953a61
--- /dev/null
+++ b/mingw-w64-crt/crt/__imagebase.c
@@ -0,0 +1,18 @@
+/**
+ * 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_mac.h>
+
+/* This file defines __ImageBase symbol for backward compatibility with older
+ * linker versions which do not provide this symbol. It is used only when
linker
+ * does not provide this symbol (detected by ./configure). __ImageBase symbol
is
+ * defined as alias to _image_base__ symbol which is provided by older linker
+ * versions. Note that gcc does not allow declaring global variable as alias to
+ * external symbol, so do it via inline assembly which allows it. */
+#define ASM_SYM(sym) __MINGW64_STRINGIFY(__MINGW_USYMBOL(sym))
+asm (
+".globl\t" ASM_SYM(__ImageBase) "\n\t"
+".set\t" ASM_SYM(__ImageBase) "," ASM_SYM(_image_base__)
+);
diff --git a/mingw-w64-crt/crt/crtexe.c b/mingw-w64-crt/crt/crtexe.c
index 99e310017eec..1656b0ee0006 100644
--- a/mingw-w64-crt/crt/crtexe.c
+++ b/mingw-w64-crt/crt/crtexe.c
@@ -35,11 +35,6 @@ extern char *** __MINGW_IMP_SYMBOL(__initenv);
#define __initenv (* __MINGW_IMP_SYMBOL(__initenv))
#endif
-/* Hack, for bug in ld. Will be removed soon. */
-#if defined(__GNUC__)
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-/* This symbol is defined by ld. */
extern IMAGE_DOS_HEADER __ImageBase;
extern void _fpreset (void);
diff --git a/mingw-w64-crt/crt/crtexewin.c b/mingw-w64-crt/crt/crtexewin.c
index 33ac1979e331..26179fa905bb 100644
--- a/mingw-w64-crt/crt/crtexewin.c
+++ b/mingw-w64-crt/crt/crtexewin.c
@@ -14,9 +14,6 @@
#define SPACECHAR _T(' ')
#define DQUOTECHAR _T('\"')
-#if defined(__GNUC__)
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
extern IMAGE_DOS_HEADER __ImageBase;
int _tmain (int, _TCHAR **, _TCHAR **);
diff --git a/mingw-w64-crt/crt/pesect.c b/mingw-w64-crt/crt/pesect.c
index 28c34f8caddb..b7f0b181097e 100644
--- a/mingw-w64-crt/crt/pesect.c
+++ b/mingw-w64-crt/crt/pesect.c
@@ -7,16 +7,7 @@
#include <windows.h>
#include <string.h>
-#if defined (_WIN64) && defined (__ia64__)
-#error FIXME: Unsupported __ImageBase implementation.
-#else
-#ifdef __GNUC__
-/* Hack, for bug in ld. Will be removed soon. */
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
-#endif
-/* This symbol is defined by the linker. */
extern IMAGE_DOS_HEADER __ImageBase;
-#endif
WINBOOL _ValidateImageBase (PBYTE);
diff --git a/mingw-w64-crt/crt/pseudo-reloc.c b/mingw-w64-crt/crt/pseudo-reloc.c
index d4589ca66350..5a64e0d37b18 100644
--- a/mingw-w64-crt/crt/pseudo-reloc.c
+++ b/mingw-w64-crt/crt/pseudo-reloc.c
@@ -48,7 +48,7 @@
extern char __RUNTIME_PSEUDO_RELOC_LIST__;
extern char __RUNTIME_PSEUDO_RELOC_LIST_END__;
-extern IMAGE_DOS_HEADER __MINGW_LSYMBOL(_image_base__);
+extern IMAGE_DOS_HEADER __ImageBase;
void _pei386_runtime_relocator (void);
@@ -499,11 +499,7 @@ _pei386_runtime_relocator (void)
do_pseudo_reloc (&__RUNTIME_PSEUDO_RELOC_LIST__,
&__RUNTIME_PSEUDO_RELOC_LIST_END__,
-#ifdef __GNUC__
- &__MINGW_LSYMBOL(_image_base__)
-#else
&__ImageBase
-#endif
);
#ifdef __MINGW64_VERSION_MAJOR
restore_modified_sections ();
diff --git a/mingw-w64-crt/libsrc/dloadhelper.c
b/mingw-w64-crt/libsrc/dloadhelper.c
index ce3a57914b92..85c1a1130157 100644
--- a/mingw-w64-crt/libsrc/dloadhelper.c
+++ b/mingw-w64-crt/libsrc/dloadhelper.c
@@ -15,7 +15,6 @@
*/
typedef DWORD NTSTATUS;
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
extern IMAGE_DOS_HEADER __ImageBase;
/* this typedef is missing from the Windows SDK header, but is present in
diff --git a/mingw-w64-crt/misc/delayimp.c b/mingw-w64-crt/misc/delayimp.c
index 26afde8079ae..ca4b51ad161d 100644
--- a/mingw-w64-crt/misc/delayimp.c
+++ b/mingw-w64-crt/misc/delayimp.c
@@ -47,7 +47,6 @@ static unsigned IndexFromPImgThunkData(PCImgThunkData
pitdCur,PCImgThunkData pit
return (unsigned) (pitdCur - pitdBase);
}
-#define __ImageBase __MINGW_LSYMBOL(_image_base__)
extern IMAGE_DOS_HEADER __ImageBase;
#define PtrFromRVA(RVA) (((PBYTE)&__ImageBase) + (RVA))
--
2.20.1
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public