On 2017/5/3 15:35, Christer Solskogen wrote:
I'm having a hard time (cross) compiling winpthreads (from 5.x branch)
with gcc 7.1.
(... abridgement ...)
src/.libs/libwinpthread_la-clock.o:clock.c:(.text+0x270): undefined
reference to `__divmoddi4'
Here is the 'real' fix for it. Please review.

(I really hate this C-ish code but this way it looks like how `__udivdi3` was implemented.)

--
Best regards,
LH_Mouse




From 04f0579cb7e2f294e1e3ad2be18b8d059546208f Mon Sep 17 00:00:00 2001
From: Liu Hao <[email protected]>
Date: Wed, 3 May 2017 15:52:32 +0800
Subject: [PATCH] winpthreads/src/dll_math.c: Implement `__divmoddi4()' for GCC
 7.

GCC targeting i686 _may_ generate an external call to the function in
question when divding a 64-bit (DIMode) integer with another one.
Since we are linking against a fake libgcc, this function is not available.

Signed-off-by: Liu Hao <[email protected]>
---
.../winpthreads/src/libgcc/dll_math.c | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c b/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c
index e09b481b..aeec0680 100644
--- a/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c
+++ b/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c
@@ -120,6 +120,7 @@ u_quad_t __qdivrem(u_quad_t u, u_quad_t v, u_quad_t *rem);
 u_quad_t       __udivdi3(u_quad_t a, u_quad_t b);
 u_quad_t       __umoddi3(u_quad_t a, u_quad_t b);
 int            __ucmpdi2(u_quad_t a, u_quad_t b);
+quad_t __divmoddi4(quad_t a, quad_t b, quad_t *rem);

 #endif /* !_LIBKERN_QUAD_H_ */

@@ -546,6 +547,32 @@ __umoddi3(a, b)
        (void)__qdivrem(a, b, &r);
        return (r);
 }
+
+/*
+ * Divide two signed quads.
+ * This function is new in GCC 7.
+ */
+quad_t
+__divmoddi4(a, b, rem)
+       quad_t a, b, *rem;
+{
+       u_quad_t ua, ub, uq, ur;
+       int negq, negr;
+
+       if (a < 0)
+               ua = -(u_quad_t)a, negq = 1, negr = 1;
+       else
+               ua = a, negq = 0, negr = 0;
+       if (b < 0)
+               ub = -(u_quad_t)b, negq ^= 1;
+       else
+               ub = b;
+       uq = __qdivrem(ua, ub, &ur);
+       if (rem)
+               *rem = (negr ? -ur : ur);
+       return (negq ? -uq : uq);
+}
+
 #else
 static int __attribute__((unused)) dummy;
 #endif /*deined (_X86_) && !defined (__x86_64__)*/
--
2.12.1

From 04f0579cb7e2f294e1e3ad2be18b8d059546208f Mon Sep 17 00:00:00 2001
From: Liu Hao <[email protected]>
Date: Wed, 3 May 2017 15:52:32 +0800
Subject: [PATCH] winpthreads/src/dll_math.c: Implement `__divmoddi4()' for GCC
 7.

GCC targeting i686 _may_ generate an external call to the function in
question when divding a 64-bit (DIMode) integer with another one.
Since we are linking against a fake libgcc, this function is not available.

Signed-off-by: Liu Hao <[email protected]>
---
 .../winpthreads/src/libgcc/dll_math.c              | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c 
b/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c
index e09b481b..aeec0680 100644
--- a/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c
+++ b/mingw-w64-libraries/winpthreads/src/libgcc/dll_math.c
@@ -120,6 +120,7 @@ u_quad_t    __qdivrem(u_quad_t u, u_quad_t v, u_quad_t 
*rem);
 u_quad_t       __udivdi3(u_quad_t a, u_quad_t b);
 u_quad_t       __umoddi3(u_quad_t a, u_quad_t b);
 int            __ucmpdi2(u_quad_t a, u_quad_t b);
+quad_t __divmoddi4(quad_t a, quad_t b, quad_t *rem);
 
 #endif /* !_LIBKERN_QUAD_H_ */
 
@@ -546,6 +547,32 @@ __umoddi3(a, b)
        (void)__qdivrem(a, b, &r);
        return (r);
 }
+
+/*
+ * Divide two signed quads.
+ * This function is new in GCC 7.
+ */
+quad_t
+__divmoddi4(a, b, rem)
+       quad_t a, b, *rem;
+{
+       u_quad_t ua, ub, uq, ur;
+       int negq, negr;
+
+       if (a < 0)
+               ua = -(u_quad_t)a, negq = 1, negr = 1;
+       else
+               ua = a, negq = 0, negr = 0;
+       if (b < 0)
+               ub = -(u_quad_t)b, negq ^= 1;
+       else
+               ub = b;
+       uq = __qdivrem(ua, ub, &ur);
+       if (rem)
+               *rem = (negr ? -ur : ur);
+       return (negq ? -uq : uq);
+}
+
 #else
 static int __attribute__((unused)) dummy;
 #endif /*deined (_X86_) && !defined (__x86_64__)*/
-- 
2.12.1

------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to