git: 21c171475da0 - stable/12 - Add clzdi2 to libsa on mips and powerpc, when built with gcc

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Wed, 22 Dec 2021 10:06:39 UTC
The branch stable/12 has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=21c171475da0cc930a3bf802e2acb48ba1fb2c71

commit 21c171475da0cc930a3bf802e2acb48ba1fb2c71
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-12-13 15:52:55 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-22 10:01:31 +0000

    Add clzdi2 to libsa on mips and powerpc, when built with gcc
    
    Otherwise, several programs that link to libsa will fail with:
    
    /usr/obj/usr/src/powerpc.powerpc/stand/libsa/libsa.a(umoddi3.o): In function `__umodXi3':
    /usr/src/contrib/llvm-project/compiler-rt/lib/builtins//int_div_impl.inc:48: undefined reference to `__clzdi2'
    /usr/src/contrib/llvm-project/compiler-rt/lib/builtins//int_div_impl.inc:48: undefined reference to `__clzdi2'
    /usr/obj/usr/src/powerpc.powerpc/stand/libsa/libsa.a(udivdi3.o): In function `__udivXi3':
    /usr/src/contrib/llvm-project/compiler-rt/lib/builtins//int_div_impl.inc:19: undefined reference to `__clzdi2'
    /usr/src/contrib/llvm-project/compiler-rt/lib/builtins//int_div_impl.inc:19: undefined reference to `__clzdi2'
    
    This is because base gcc 4.2 fails to inline the __builtin_clzll() calls
    in int_div_impl.inc.
---
 stand/libsa/Makefile | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/stand/libsa/Makefile b/stand/libsa/Makefile
index e70a5ffb7a82..04d93525c6ad 100644
--- a/stand/libsa/Makefile
+++ b/stand/libsa/Makefile
@@ -66,6 +66,11 @@ SRCS+=	aeabi_memcmp.S aeabi_memcpy.S aeabi_memmove.S aeabi_memset.S
 .PATH: ${SRCTOP}/contrib/llvm-project/compiler-rt/lib/builtins/
 # __clzsi2 and ctzsi2 for various builtin functions
 SRCS+=	clzsi2.c ctzsi2.c
+.if ${COMPILER_TYPE} == "gcc" && \
+    (${MACHINE_CPUARCH} == "mips" || ${MACHINE_CPUARCH} == "powerpc")
+# prevent "undefined reference to `__clzdi2'" in umoddi3.o and udivdi3.o
+SRCS+=	clzdi2.c
+.endif
 # Divide and modulus functions called by the compiler
 SRCS+=	divmoddi4.c  divmodsi4.c  divdi3.c  divsi3.c  moddi3.c  modsi3.c
 SRCS+=	udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c