<div dir="ltr">Hi,<div><br></div><div>I'm a software developer. I build open-source projects in my spare time. One of them uses LLVM as a third party dependency.</div><div>I recently noticed a few issues in llvm on M1 chip.</div><div>These issues exist probably because M1 is still a relatively new thing. But I would like to bring these issues on the table so that you are aware of them.</div><div><br></div><div>First of all, I have to run the build in Rossetta compatible terminal because of this error. If you build llvm on native terminal without Rosetta support, it ends here.</div><div><br></div><div>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">/bin/sh: line 1: 20715 Killed: 9 <span class="gmail-Apple-converted-space">              </span>../../../bin/llvm-tblgen -gen-attrs -I /Users/caojiayin/Desktop/GitHub/llvm-project-master/llvm/include/llvm/IR -I/Users/caojiayin/Desktop/GitHub/llvm-project-master/build_new/include -I/Users/caojiayin/Desktop/GitHub/llvm-project-master/llvm/include /Users/caojiayin/Desktop/GitHub/llvm-project-master/llvm/include/llvm/IR/Attributes.td --write-if-changed -o /Users/caojiayin/Desktop/GitHub/llvm-project-master/build_new/include/llvm/IR/Attributes.inc</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">/bin/sh: line 1: 20713 Killed: 9 <span class="gmail-Apple-converted-space">              </span>../../../bin/llvm-tblgen --gen-directive-impl -I /Users/caojiayin/Desktop/GitHub/llvm-project-master/llvm/lib/Frontend/OpenACC -I/Users/caojiayin/Desktop/GitHub/llvm-project-master/build_new/include -I/Users/caojiayin/Desktop/GitHub/llvm-project-master/llvm/include /Users/caojiayin/Desktop/GitHub/llvm-project-master/llvm/include/llvm/Frontend/OpenACC/ACC.td --write-if-changed -o /Users/caojiayin/Desktop/GitHub/llvm-project-master/build_new/lib/Frontend/OpenACC/ACC.cpp</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">make[2]: *** [include/llvm/IR/Attributes.inc] Error 137</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">make[2]: *** [lib/Frontend/OpenACC/ACC.cpp] Error 137</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">make[1]: *** [include/llvm/IR/CMakeFiles/intrinsics_gen.dir/all] Error 2</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">make[1]: *** Waiting for unfinished jobs....</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">make[1]: *** [lib/Frontend/OpenACC/CMakeFiles/acc_cpp.dir/all] Error 2</span></p></div><div><br></div><div>According to LLVM documents, '<strong style="color:rgb(0,0,0);font-family:"Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:14px">LLVM_TARGET_ARCH</strong><span style="color:rgb(0,0,0);font-family:"Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:14px">:STRING</span>' can be set either to the target arch or host so that the arch of the host will be picked.</div><div>This does work as expected on Intel MacOS, but the same doesn't go true for M1 Mac. The issue manifests itself as crashing during run-time once the builds are generated. For example, there is this example program called 'HowToUseLLJIT', this will result in this error if that macro is set to host.</div><div><br></div><div><b>./bin/HowToUseLLJIT: Unable to find target for this triple (no targets are registered)</b><br></div><div><br></div><div>And if it is set to AArch64 explicitly, this will end up with this error</div><div><br></div><div><b>No available targets are compatible with triple "x86_64-apple-darwin20.2.0"</b></div><div><br></div><div>This error is the second issue I will talk about later in this email. Clearly, changing that '<strong style="color:rgb(0,0,0);font-family:"Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:14px">LLVM_TARGET_ARCH</strong><span style="color:rgb(0,0,0);font-family:"Lucida Grande","Lucida Sans Unicode",Geneva,Verdana,sans-serif;font-size:14px">:STRING</span>' will result in different builds. Maybe CMake script doesn't parse that macro on M1 correctly somehow. I'm not an expert of LLVM, but I hope this could be helpful enough for you guys to reproduce the problem and eventually fix it.</div><div><br></div><div>The second problem is the compatible issue that the example build emits.</div><div>To workaround the problem, I set the triple in code explicitly to 'arm64-apple-darwin20.2.0". And it works after the workaround. Somehow that triple is not correctly set inside LLVM. I also happen to notice this macro in CMake file cache '<b>LLVM_DEFAULT_TARGET_TRIPLE</b>' is x86_64-apple-darwin20.2.0, which might be related.</div><div>This sounds like a bug in LLVM not correctly detect arch under the hood.</div><div><br></div><div>I tried finding resources on internet about how to setup LLVM on M1 Mac and there isn't much.</div><div>So the whole setup process is a bit difficult. It would be nice to have some documents in the future.</div><div><br></div><div>Thanks</div><div>Jiayin</div></div>