Bug 244169 - [clang] __builtin_mul_overflow() with 64-bit values requires __muloti4 which is missing on 32-bit architectures
Summary: [clang] __builtin_mul_overflow() with 64-bit values requires __muloti4 which ...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-16 16:53 UTC by Jan Beich
Modified: 2023-01-27 20:07 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2020-02-16 16:53:28 UTC
$ cc a.c
/tmp/a-667572.o: In function `main':
a.c:(.text+0x50): undefined reference to `__muloti4'
cc: error: linker command failed with exit code 1 (use -v to see invocation)

$ cat a.c
#include <stdint.h>

int main(void)
{
	uint64_t i;
	__builtin_mul_overflow(1, 10, &i);
	return 0;
}
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2020-05-23 11:06:46 UTC
We do compile contrib/llvm-project/compiler-rt/lib/builtins/muloti4.c as part of libcompiler_rt, but the file starts with:

#include "int_lib.h"

#ifdef CRT_HAS_128BIT

// Returns: a * b

// Effects: sets *overflow to 1  if a * b overflows

COMPILER_RT_ABI ti_int __muloti4(ti_int a, ti_int b, int *overflow) {

Obviously, CRT_HAS_128BIT is false on 32-bit platforms; it is defined in int_lib.h as:

#if defined(__LP64__) || defined(__wasm__) || defined(__mips64) ||             \
    defined(__riscv) || defined(_WIN64)
#define CRT_HAS_128BIT
#endif

So I'm not really sure what we can do about this...
Comment 2 Carlo Arenas 2023-01-27 19:20:17 UTC
FWIW, this at least does not affect 32-bit ARM:

FreeBSD generic 14.0-CURRENT FreeBSD 14.0-CURRENT #0 main-n259626-b1ef176eb528: Fri Dec  9 10:56:44 UTC 2022     root@releng1.nyi.freebsd.org:/usr/obj/usr/src/arm.armv7/sys/GENERIC arm
Comment 3 Carlo Arenas 2023-01-27 19:47:29 UTC
it also doesn't replicate in FreeBSD 12.4 amd64 (using -m32 with the system cc), so maybe should be closed?
Comment 4 Carlo Arenas 2023-01-27 20:07:56 UTC
maybe related and therefore solved by:

https://bugs.llvm.org//show_bug.cgi?id=28629