LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25305 - Clang-cl generates a call to an undefined symbol __udivti3
Summary: Clang-cl generates a call to an undefined symbol __udivti3
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: LLVM Codegen (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P normal
Assignee: Adrian McCarthy
URL:
Keywords:
Depends on:
Blocks: 48769
  Show dependency tree
 
Reported: 2015-10-23 18:35 PDT by Mark Harmer
Modified: 2021-09-07 11:40 PDT (History)
12 users (show)

See Also:
Fixed By Commit(s):


Attachments
Build with: clang-cl main.c (158 bytes, text/plain)
2015-10-23 18:35 PDT, Mark Harmer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Harmer 2015-10-23 18:35:09 PDT
Created attachment 15150 [details]
Build with: clang-cl main.c

While attempting to build a (very) old version of libtomcrypt with Clang-cl (64-bit r250698), it appears a call to an undefined function is being generated:

main-ff9827.obj : error LNK2019: unresolved external symbol __udivti3 referenced in function main

I've attached a minimal reproduce case. This appears to be due to the "__attribute__((mode(TI)))" on the typedef.
Comment 1 Anton Korobeynikov 2015-10-23 18:49:31 PDT
mode(TI) is a gcc extension. Therefore you need to link with libgcc / compiler_rt.
Comment 2 Mark Harmer 2015-10-23 19:00:01 PDT
Is this true under Windows as well? The default installation of LLVM (through the installer provided at llvm.org/builds) doesn't seem to supply either libgcc or compiler_rt.

From a user standpoint there doesn't seem to be anything I can link against under Windows to resolve this.
Comment 3 Reid Kleckner 2015-10-23 20:03:12 PDT
Very rarely do you need compiler-rt. I think you can trigger the reference a different way, something like this with -fms-extensions:

__int128 mydiv(__int128 a, __int128 b) {
  return a / b;
}

I bet we still generate the call to compiler-rt.

If the MSVC CRT has a reliably available libcall (going back to VC 6.0 in MSVCRT.dll), then we could call it instead of the libgcc version. If not, I'd recommend building compiler-rt. It isn't normally required.
Comment 4 Stephan Bergmann 2017-11-23 04:01:17 PST
(In reply to Reid Kleckner from comment #3)
> If the MSVC CRT has a reliably available libcall (going back to VC 6.0 in
> MSVCRT.dll), then we could call it instead of the libgcc version. If not,
> I'd recommend building compiler-rt. It isn't normally required.

But even with projects/compiler-rt built (alongside llvm itself and tools/clang), `clang-cl main.c` still cannot resolve __udivti3, and I cannot spot any .lib in the installation tree that would provide it.  (On recent trunk towards LLVM 6.)
Comment 5 Gregory PAKOSZ 2018-03-14 07:31:45 PDT
I'm currently hitting this exact same bug while compiling the a project that makes use of libTomMath v0.41
Comment 6 Gregory PAKOSZ 2018-09-10 04:46:21 PDT
Hello there,

As far as I can tell, running strings on "C:\Program Files\LLVM\lib\clang\6.0.1\lib\windows\clang_rt.builtins-x86_64.lib" seems to indicate udivti3 should be linked in from udivti3.c.obj.

However, running DUMPBIN /SYMBOLS on the said file only lists the udivsi3 function.

What's the proper way to request the 128b variants are linked are not optimized out or compiled out of clang_rt.builtins-x86_64.lib ?

Thank you
Comment 7 Adrian McCarthy 2021-03-04 10:58:42 PST
Per conversation with @rnk, I'll see if the driver can be convinced to include the right compiler-rt files.
Comment 8 Nick Desaulniers 2021-08-30 11:15:55 PDT
This has come up again in https://bugs.llvm.org/show_bug.cgi?id=28629. I think Renato's comment here is highly relevant: https://github.com/ClangBuiltLinux/linux/issues/1438#issuecomment-907689836.
Comment 9 Nick Desaulniers 2021-09-07 11:08:15 PDT
We'll want to do something similar to this list of commits: https://bugs.llvm.org/show_bug.cgi?id=28629#c23.
Comment 10 Craig Topper 2021-09-07 11:40:39 PDT
(In reply to Nick Desaulniers from comment #9)
> We'll want to do something similar to this list of commits:
> https://bugs.llvm.org/show_bug.cgi?id=28629#c23.

Its a quite a bit more complicated than that. We need to generate a inline division implementation, but that requires loops that SelectionDAG can't create. We likely need a pre-SelectionDAG IR pass that expands the unsupported division.