From: Peter Damianov <[email protected]>

Since commit 4b5196714 ("crt: Define FE_DFL_ENV next to _fpreset"),
fesetenv.o in libmingwex.a refers to __mingw_fe_dfl_env, which on x86 is
defined next to _fpreset in CRT_fp10.o.  CRT_fp10.o was in libmingw32.a,
which GCC passes before libmingwex.a.

An EXE always pulls in CRT_fp10.o through the _fpreset call in crtexe.c,
but a DLL does not.  When fesetenv.o is first pulled in by a library
that comes after the last libmingw32.a on the command line, such as
libpthread.a (pthread_create calls fesetenv), linking the DLL with GNU
ld fails:

  undefined reference to `__mingw_fe_dfl_env'

Build CRT_fp10.c into libmingwex.a, next to fesetenv.c.  GNU ld rescans
an archive until no more members are pulled in, so CRT_fp10.o is now
found whenever fesetenv.o needs it.  CRT_fp4.o and CRT_fp8.o, when linked
explicitly, still take precedence, as they come before the libraries.

LLD resolves archive members regardless of their order on the command
line, so the testcases, which CI runs with LLD, cannot catch this.

Reported-by: Evgeny Karpov <[email protected]>
Signed-off-by: Peter Damianov <[email protected]>
---
Evgeny, thanks for the report.  I reproduced it with GNU ld by linking a
DLL that calls pthread_create; with this patch it links again.  If what
you were linking is something else, let me know and I'll check that too.

 mingw-w64-crt/Makefile.am | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index f7ddef7ff..082f13da1 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -1649,11 +1649,11 @@ lib32_libgmon_a_CPPFLAGS=$(CPPFLAGS32) $(sysincludes)
 
 lib32_LIBRARIES += lib32/libmingw32.a
 lib32_libmingw32_a_CPPFLAGS=$(CPPFLAGS32) -D_SYSCRT=1 $(extra_include)
-lib32_libmingw32_a_SOURCES = $(src_libmingw32) crt/CRT_fp10.c
+lib32_libmingw32_a_SOURCES = $(src_libmingw32)
 
 lib32_LIBRARIES += lib32/libmingwex.a
 lib32_libmingwex_a_CPPFLAGS=$(CPPFLAGS32) $(extra_include)
-lib32_libmingwex_a_SOURCES = $(src_libmingwex) $(src_libmingwex32) 
$(src_dfp_math)
+lib32_libmingwex_a_SOURCES = $(src_libmingwex) $(src_libmingwex32) 
$(src_dfp_math) crt/CRT_fp10.c
 
 lib32_LIBRARIES += lib32/libmoldname.a
 lib32_libmoldname_a_CPPFLAGS=$(CPPFLAGS32) $(extra_include)
@@ -2069,11 +2069,11 @@ lib64_libgmon_a_CPPFLAGS=$(CPPFLAGS64) $(sysincludes)
 
 lib64_LIBRARIES += lib64/libmingw32.a
 lib64_libmingw32_a_CPPFLAGS=$(CPPFLAGS64) -D_SYSCRT=1 $(extra_include)
-lib64_libmingw32_a_SOURCES = $(src_libmingw32) crt/CRT_fp10.c
+lib64_libmingw32_a_SOURCES = $(src_libmingw32)
 
 lib64_LIBRARIES += lib64/libmingwex.a
 lib64_libmingwex_a_CPPFLAGS=$(CPPFLAGS64) $(extra_include)
-lib64_libmingwex_a_SOURCES = $(src_libmingwex) $(src_libmingwex64) 
$(src_dfp_math)
+lib64_libmingwex_a_SOURCES = $(src_libmingwex) $(src_libmingwex64) 
$(src_dfp_math) crt/CRT_fp10.c
 
 lib64_LIBRARIES += lib64/libmoldname.a
 lib64_libmoldname_a_CPPFLAGS=$(CPPFLAGS64) $(extra_include)
-- 
2.54.0.windows.1



_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to