Skip to content

[clang-cl] Auto link clang_rt library when half-precision floating point types are used #120234

Open
@zufuliu

Description

@zufuliu

Tested LLVM 19.1.5, following code with pragma comment out failed to link. it seems frontend doesn't emit link hint for clang_rt library.

//#pragma comment(lib, "clang_rt.builtins-x86_64.lib")
__bf16 add16(__bf16 x, __bf16 y) {
    return x + y;
}
int main(int argc, char *argv[]) {
    int x = argv[0][0] - '0';
    return (int)add16((__bf16)argc, (__bf16)(x));
}
D:\notepad4>clang-cl /c test.cpp

D:\notepad4>lld-link test.obj
lld-link: error: undefined symbol: __truncsfbf2
>>> referenced by test.obj:(struct __clang::__bf16 __cdecl add16(struct __clang::__bf16, struct __clang::__bf16))
>>> referenced by test.obj:(struct __clang::__bf16 __cdecl add16(struct __clang::__bf16, struct __clang::__bf16))
>>> referenced by test.obj:(struct __clang::__bf16 __cdecl add16(struct __clang::__bf16, struct __clang::__bf16))
>>> referenced 2 more times

D:\notepad4>link test.obj
Microsoft (R) Incremental Linker Version 14.42.34435.0
Copyright (C) Microsoft Corporation.  All rights reserved.

test.obj : error LNK2019: unresolved external symbol __truncsfbf2 referenced in function "struct __clang::__bf16 __cdecl add16(struct __clang::__bf16,struct __clang::__bf16)" (?add16@@YAU__bf16@__clang@@U12@0@Z)
test.exe : fatal error LNK1120: 1 unresolved externals

D:\notepad4>

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-cl`clang-cl` driver. Don't use for other compiler parts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions