<div dir="ltr"><div>Hi,</div><div><br></div><div>We have been using a JIT clang modelled after clang-interpreter from version 5.0.0.</div><div>It has been working on linux, osx and windows (x86 and x64).<br></div><div><br></div><div>Recently I attempted to upgrade llvm and clang to 7 and then 8, currently trying <br></div><div>llvm and cfe 8.0.1.</div><div>There are significant changes in using the newer JIT system and I see that there is another iteration coming in the trunk.</div><div><br></div><div>The clang-interpreter example works on mac but on windows I can't get it to work.</div><div>I have built x86 /MD, x64 /MD and an x86 /MT version, all with Visual Studio 2017, Version 15.8.8.</div><div><br></div><div>Initially for me the debug version asserts with the following message and the release version crashes as it fails to resolve the pointer to main.</div><div><br></div><div>Assertion failed: Target.isCompatibleDataLayout(getDataLayout()) && "Can't create a MachineFunction using a Module with a " "Target-incompatible DataLayout attached\n", file d:\bl\llvm\llvm-8.0.1.src\lib\codegen\machinefunction.cpp, line 200</div><div><br></div><div>I inferred that the JIT container and the compiled module are incompatible. I think this is because the code explicitly changes the detected Triple from COFF to ELF.</div><div> // Use ELF on Windows-32 and MingW for now.<br>#ifndef CLANG_INTERPRETER_COFF_FORMAT<br> if (T.isOSBinFormatCOFF())<br> T.setObjectFormat(llvm::Triple::ELF);<br>#endif</div><div><br></div><div>I wondered if maybe this is no longer necessary so tried commenting it out, which resolved the error assertion but now the debug version also just silently fails to find the symbol.</div><div><br></div><div>This is the output from dumping the module, the input C++ I have simplified from the provided example Test.cxx by removing the exception throw and hard coded a printf("hello\n");</div><div><br></div><div>=================================================================<br></div><div>; ModuleID = 'D:\llvm\llvm-8.0.1.src\tools\clang\examples\clang-interpreter\Test.cxx'<br>source_filename = "D:\5Cllvm\5Cllvm-8.0.1.src\5Ctools\5Cclang\5Cexamples\5Cclang-interpreter\5CTest.cxx"<br>target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"<br>target triple = "i686-pc-windows-msvc19.15.26732"<br><br>%struct._iobuf = type { i8* }<br>%struct.__crt_locale_pointers = type { %struct.__crt_locale_data*, %struct.__crt_multibyte_data* }<br>%struct.__crt_locale_data = type opaque<br>%struct.__crt_multibyte_data = type opaque<br><br>$printf = comdat any<br><br>$_vfprintf_l = comdat any<br><br>$__local_stdio_printf_options = comdat any<br><br>$"??_C@_0O@OAOIOGJB@arg?$FL?$CFd?$FN?$DN?8?$CFs?8?6?$AA@" = comdat any<br><br>$"??_C@_06BGKFAKIK@hello?6?$AA@" = comdat any<br><br>$"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA" = comdat any<br><br>@"??_C@_0O@OAOIOGJB@arg?$FL?$CFd?$FN?$DN?8?$CFs?8?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [14 x i8] c"arg[%d]='%s'\0A\00", comdat, align 1<br>@"??_C@_06BGKFAKIK@hello?6?$AA@" = linkonce_odr dso_local unnamed_addr constant [7 x i8] c"hello\0A\00", comdat, align 1<br>@"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA" = linkonce_odr dso_local global i64 0, comdat, align 8<br><br>; Function Attrs: noinline norecurse optnone<br>define dso_local i32 @main(i32 %argc, i8** %argv) #0 {<br>entry:<br> %retval = alloca i32, align 4<br> %argv.addr = alloca i8**, align 4<br> %argc.addr = alloca i32, align 4<br> %I = alloca i32, align 4<br> store i32 0, i32* %retval, align 4<br> store i8** %argv, i8*** %argv.addr, align 4<br> store i32 %argc, i32* %argc.addr, align 4<br> store i32 0, i32* %I, align 4<br> br label %for.cond<br><br>for.cond: ; preds = %for.inc, %entry<br> %0 = load i32, i32* %I, align 4<br> %1 = load i32, i32* %argc.addr, align 4<br> %cmp = icmp slt i32 %0, %1<br> br i1 %cmp, label %for.body, label %for.end<br><br>for.body: ; preds = %for.cond<br> %2 = load i8**, i8*** %argv.addr, align 4<br> %3 = load i32, i32* %I, align 4<br> %arrayidx = getelementptr inbounds i8*, i8** %2, i32 %3<br> %4 = load i8*, i8** %arrayidx, align 4<br> %5 = load i32, i32* %I, align 4<br> %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @"??_C@_0O@OAOIOGJB@arg?$FL?$CFd?$FN?$DN?8?$CFs?8?6?$AA@", i32 0, i32 0), i32 %5, i8* %4)<br> br label %for.inc<br><br>for.inc: ; preds = %for.body<br> %6 = load i32, i32* %I, align 4<br> %inc = add nsw i32 %6, 1<br> store i32 %inc, i32* %I, align 4<br> br label %for.cond<br><br>for.end: ; preds = %for.cond<br> %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @"??_C@_06BGKFAKIK@hello?6?$AA@", i32 0, i32 0))<br> ret i32 0<br>}<br><br>; Function Attrs: noinline optnone<br>define linkonce_odr dso_local i32 @printf(i8* %_Format, ...) #1 comdat {<br>entry:<br> %_Format.addr = alloca i8*, align 4<br> %_Result = alloca i32, align 4<br> %_ArgList = alloca i8*, align 4<br> store i8* %_Format, i8** %_Format.addr, align 4<br> %_ArgList1 = bitcast i8** %_ArgList to i8*<br> call void @llvm.va_start(i8* %_ArgList1)<br> %0 = load i8*, i8** %_ArgList, align 4<br> %1 = load i8*, i8** %_Format.addr, align 4<br> %call = call %struct._iobuf* @__acrt_iob_func(i32 1)<br> %call2 = call i32 @_vfprintf_l(%struct._iobuf* %call, i8* %1, %struct.__crt_locale_pointers* null, i8* %0)<br> store i32 %call2, i32* %_Result, align 4<br> %_ArgList3 = bitcast i8** %_ArgList to i8*<br> call void @llvm.va_end(i8* %_ArgList3)<br> %2 = load i32, i32* %_Result, align 4<br> ret i32 %2<br>}<br><br>; Function Attrs: nounwind<br>declare void @llvm.va_start(i8*) #2<br><br>; Function Attrs: noinline optnone<br>define linkonce_odr dso_local i32 @_vfprintf_l(%struct._iobuf* %_Stream, i8* %_Format, %struct.__crt_locale_pointers* %_Locale, i8* %_ArgList) #1 comdat {<br>entry:<br> %_ArgList.addr = alloca i8*, align 4<br> %_Locale.addr = alloca %struct.__crt_locale_pointers*, align 4<br> %_Format.addr = alloca i8*, align 4<br> %_Stream.addr = alloca %struct._iobuf*, align 4<br> store i8* %_ArgList, i8** %_ArgList.addr, align 4<br> store %struct.__crt_locale_pointers* %_Locale, %struct.__crt_locale_pointers** %_Locale.addr, align 4<br> store i8* %_Format, i8** %_Format.addr, align 4<br> store %struct._iobuf* %_Stream, %struct._iobuf** %_Stream.addr, align 4<br> %0 = load i8*, i8** %_ArgList.addr, align 4<br> %1 = load %struct.__crt_locale_pointers*, %struct.__crt_locale_pointers** %_Locale.addr, align 4<br> %2 = load i8*, i8** %_Format.addr, align 4<br> %3 = load %struct._iobuf*, %struct._iobuf** %_Stream.addr, align 4<br> %call = call i64* @__local_stdio_printf_options()<br> %4 = load i64, i64* %call, align 8<br> %call1 = call i32 @__stdio_common_vfprintf(i64 %4, %struct._iobuf* %3, i8* %2, %struct.__crt_locale_pointers* %1, i8* %0)<br> ret i32 %call1<br>}<br><br>declare dso_local %struct._iobuf* @__acrt_iob_func(i32) #3<br><br>; Function Attrs: nounwind<br>declare void @llvm.va_end(i8*) #2<br><br>declare dso_local i32 @__stdio_common_vfprintf(i64, %struct._iobuf*, i8*, %struct.__crt_locale_pointers*, i8*) #3<br><br>; Function Attrs: noinline nounwind optnone<br>define linkonce_odr dso_local i64* @__local_stdio_printf_options() #4 comdat {<br>entry:<br> ret i64* @"?_OptionsStorage@?1??__local_stdio_printf_options@@9@4_KA"<br>}<br><br>attributes #0 = { noinline norecurse optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>attributes #1 = { noinline optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>attributes #2 = { nounwind }<br>attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>attributes #4 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }<br><br>!llvm.linker.options = !{!0, !1, !2, !3, !4}<br>!llvm.module.flags = !{!5, !6}<br>!llvm.ident = !{!7}<br><br>!0 = !{!"/FAILIFMISMATCH:\22_MSC_VER=1900\22"}<br>!1 = !{!"/FAILIFMISMATCH:\22_ITERATOR_DEBUG_LEVEL=0\22"}<br>!2 = !{!"/FAILIFMISMATCH:\22RuntimeLibrary=MT_StaticRelease\22"}<br>!3 = !{!"/DEFAULTLIB:libcpmt.lib"}<br>!4 = !{!"/FAILIFMISMATCH:\22_CRT_STDIO_ISO_WIDE_SPECIFIERS=0\22"}<br>!5 = !{i32 1, !"NumRegisterParameters", i32 0}<br>!6 = !{i32 1, !"wchar_size", i32 2}<br>!7 = !{!"clang version 8.0.1 (tags/RELEASE_801/final)"}</div><div>======================================================</div><div><br></div><div>I then considered that the change to the triple may be necessary so I think I figured out how to modify the JIT container code to have a matching container by modifying the constructor for the TargetMachine.<br></div><div>Replacing TM(EngineBuilder().selectTarget()),</div><div>with <br></div><div>TM(EngineBuilder().selectTarget(GetTarget(), "", "", MAttrs)),</div><div>where GetTarget just reproduces the Triple code that was in the example....</div><div> static llvm::Triple GetTarget() {<br> const std::string TripleStr = llvm::sys::getProcessTriple();<br> llvm::Triple T(TripleStr);<br><br> // Use ELF on Windows-32 and MingW for now.<br>#ifndef CLANG_INTERPRETER_COFF_FORMAT<br> if (T.isOSBinFormatCOFF())<br> T.setObjectFormat(llvm::Triple::ELF);<br>#endif<br><br> return T;<br> }</div><div><br></div><div>This version of the code also resolves the debug assertion that I had initially but it fails to link with <br></div><div>LLVM ERROR: invalid llvm.linker.options</div><div><br></div><div>I'm not sure what else to try or how to diagnose the problem further.</div><div><br></div><div>Thanks in advance for any help that may be provided.</div><div><br></div><div>Thanks,</div><div>Shane Blackett</div><div><br></div></div>
<br>
<hr><p><font face="Arial" size="1">"This communication is confidential and may contain privileged and/or copyright material. If you are not the intended recipient you must not use, disclose, copy or retain it. If you have received it in error please immediately notify me by return email, delete the emails and destroy any hard copies. Soul Machines Limited does not guarantee the integrity of this communication, or that it is free from errors, viruses or interference."</font></p>
<p><b><font face="Arial" color="#008000" size="1">Please consider the environment before printing this email.</font></b></p>