Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang-cl generates a call to an undefined symbol __udivti3 #25679

Open
llvmbot opened this issue Oct 24, 2015 · 17 comments
Open

Clang-cl generates a call to an undefined symbol __udivti3 #25679

llvmbot opened this issue Oct 24, 2015 · 17 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang:codegen

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 24, 2015

Bugzilla Link 25305
Version trunk
OS Windows NT
Blocks #48113
Attachments Build with: clang-cl main.c
Reporter LLVM Bugzilla Contributor
CC @amccarth-google,@asl,@compnerd,@topperc,@RKSimon,@nickdesaulniers,@rengolin,@rnk,@stbergmann,@yurybura

Extended Description

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.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 24, 2015

assigned to @amccarth-google

@asl
Copy link
Collaborator

asl commented Oct 24, 2015

mode(TI) is a gcc extension. Therefore you need to link with libgcc / compiler_rt.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Oct 24, 2015

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.

@rnk
Copy link
Collaborator

rnk commented Oct 24, 2015

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.

@stbergmann
Copy link
Collaborator

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.)

@llvmbot
Copy link
Collaborator Author

llvmbot commented Mar 14, 2018

I'm currently hitting this exact same bug while compiling the a project that makes use of libTomMath v0.41

@llvmbot
Copy link
Collaborator Author

llvmbot commented Sep 10, 2018

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

@amccarth-google
Copy link
Collaborator

Per conversation with @​rnk, I'll see if the driver can be convinced to include the right compiler-rt files.

@nickdesaulniers
Copy link
Member

This has come up again in llvm/llvm-bugzilla-archive#28629 . I think Renato's comment here is highly relevant: ClangBuiltLinux/linux#1438 (comment).

@nickdesaulniers
Copy link
Member

We'll want to do something similar to this list of commits: llvm/llvm-bugzilla-archive#28629 #c23.

@topperc
Copy link
Collaborator

topperc commented Sep 7, 2021

We'll want to do something similar to this list of commits:
llvm/llvm-bugzilla-archive#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.

@GabrielRavier
Copy link
Contributor

mentioned in issue #48113

@h-vetinari
Copy link
Contributor

Looking at the status of this, I think it's worth noting that the last update was actually in #26142 (Should clang-cl require compiler-rt?), where @rnk said:

This continues to come up, and I think we want the answer to be yes, we just need to make it happen.

Let's say this is a Duplicate of #25679.

Any update on this effort? I'm hitting this issue while trying to build flang on windows.

@rnk
Copy link
Collaborator

rnk commented May 18, 2023

Specifically, I think we ought to implement this by emitting /defaultlib:clang_rt.builtins.${arch}.lib directives in the object file, so that we auto-link compiler-rt transparently. Bonus points if we only emit the directive when we need these runtime functions.

Separately, folks have been talking about teaching lld-link to find clang runtime libraries by searching relative to argv[0]. That would make this more seamless.

@zmodem
Copy link
Collaborator

zmodem commented May 19, 2023

Separately, folks have been talking about teaching lld-link to find clang runtime libraries by searching relative to argv[0]. That would make this more seamless.

+@tru for that.

It would be amazing to finally get this fixed.

@tru
Copy link
Collaborator

tru commented May 19, 2023

Yes - I have started working on this! Stay tuned.

@h-vetinari
Copy link
Contributor

Yes - I have started working on this! Stay tuned.

Hey @tru, just a gentle question about the status of this. I'm hitting some likely related issues about the different runtime-libraries when test-driving flang on windows.

qtprojectorg pushed a commit to qt/qtbase that referenced this issue Jun 20, 2024
Fixes build with clang-cl on Windows.

This is a workaround for
llvm/llvm-project#25679

Change-Id: I6dc8b045376101d8b8cc26fe5db3e7bf87a6a8f4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:codegen
Projects
None yet
Development

No branches or pull requests