Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

[UBSan/Win] Linker fails on code that uses int64_t multiplication in 32 bit build #35697

Open Quuxplusone opened 6 years ago

Quuxplusone commented 6 years ago
Bugzilla Link PR36724
Status NEW
Importance P normal
Reported by Markus Maier (markus.maier.sw@gmail.com)
Reported on 2018-03-14 06:27:59 -0700
Last modified on 2018-06-12 11:26:12 -0700
Version 6.0
Hardware PC Windows NT
CC llvm-bugs@lists.llvm.org, rnk@google.com, vitalybuka@google.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
* MSVC2015 32 Bit
* LLVM/Clang 6.0.0 with official installer, bin folder added to PATH
* Host OS: Windows 10 1703 x64

The following code fails to link with clang-cl when building with -
fsanitize=undefined:
______________________________________________
// file main.cpp
#include <iostream>
#include <cstdint>
using namespace std;

int main()
{
    int64_t test = 1;
    test *= 1000;
    cout << "1 * 1000 = " << test << endl;
    return 0;
}
______________________________________________

When changing int64_t to uint64_t, the code builds and runs as expected.

My build commands with "VS2015 x86 Native tools command prompt" including
output:

c:\build>clang-cl -fsanitize=undefined -v main.cpp
clang version 6.0.0 (tags/RELEASE_600/final)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files (x86)\LLVM\bin
 "C:\\Program Files (x86)\\LLVM\\bin\\clang-cl.exe" -cc1 -triple i686-pc-windows-msvc19.0.24215 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fms-volatile -fdiagnostics-format msvc -dwarf-column-info -debugger-tuning=gdb -v -resource-dir "C:\\Program Files (x86)\\LLVM\\lib\\clang\\6.0.0" -internal-isystem "C:\\Program Files (x86)\\LLVM\\lib\\clang\\6.0.0\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\INCLUDE" -internal-isystem "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\ATLMFC\\INCLUDE" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\10\\include\\10.0.10240.0\\ucrt" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.6.1\\include\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\8.1\\include\\\\shared" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\8.1\\include\\\\um" -internal-isystem "C:\\Program Files (x86)\\Windows Kits\\8.1\\include\\\\winrt" -fdeprecated-macro -fdebug-compilation-dir "c:\\build" -ferror-limit 19 -fmessage-length 120 "--dependent-lib=C:\\Program Files (x86)\\LLVM\\lib\\clang\\6.0.0\\lib\\windows\\clang_rt.ubsan_standalone-i386.lib" "--dependent-lib=C:\\Program Files (x86)\\LLVM\\lib\\clang\\6.0.0\\lib\\windows\\clang_rt.ubsan_standalone_cxx-i386.lib" -fsanitize=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,float-divide-by-zero,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound -fsanitize-recover=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,float-divide-by-zero,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,vla-bound -fno-use-cxa-atexit -fms-extensions -fms-compatibility -fms-compatibility-version=19.0.24215 -std=c++14 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\m2_maier\\AppData\\Local\\Temp\\main-366977.obj" -x c++ main.cpp
clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target i686-pc-windows-
msvc
#include "..." search starts here:
#include <...> search starts here:
 C:\Program Files (x86)\LLVM\lib\clang\6.0.0\include
 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE
 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE
 C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt
 C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um
 C:\Program Files (x86)\Windows Kits\8.1\include\\shared
 C:\Program Files (x86)\Windows Kits\8.1\include\\um
 C:\Program Files (x86)\Windows Kits\8.1\include\\winrt
End of search list.
 "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\link.exe" -out:main.exe -nologo "C:\\Users\\markus\\AppData\\Local\\Temp\\main-366977.obj"
   Creating library main.lib and object main.exp
main-366977.obj : error LNK2019: unresolved external symbol ___mulodi4
referenced in function _main
main.exe : fatal error LNK1120: 1 unresolved externals
clang-cl.exe: error: linker command failed with exit code 1120 (use -v to see
invocation)

c:\build>
Quuxplusone commented 6 years ago

Any ideas?

Quuxplusone commented 6 years ago

Clang should probably always link clang_rt.builtins-$arch.lib on Windows if it exists.

However, even better would be to find a 64-bit mul with overflow function in MSVCRT and call that instead.