{"id":542,"date":"2023-07-24T23:21:18","date_gmt":"2023-07-24T23:21:18","guid":{"rendered":"https:\/\/blogs.gentoo.org\/gsoc\/?p=542"},"modified":"2023-07-24T23:22:05","modified_gmt":"2023-07-24T23:22:05","slug":"weekly-report-6-llvm-libc","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/gsoc\/2023\/07\/24\/weekly-report-6-llvm-libc\/","title":{"rendered":"Weekly report 6, LLVM libc"},"content":{"rendered":"<p>Hi! This week I have been working on LLVM\/Clang support for<br \/>\nCrossdev. This is currently done by swapping out the different Crossdev<br \/>\nstages for ones that make sense for LLVM.<\/p>\n<p>Currently it replaces stage0 with checking whether LLVM can target the<br \/>\ntarget triple&#8217;s architecture by checking the LLVM_TARGETS USE-flag.<\/p>\n<p>Stage1, which normally installs libc headers and compiles a -stage1 C<br \/>\ncompiler is replaced by installing libc headers and compiling<br \/>\ncompiler-rt.<\/p>\n<p>Stage2 (kernel headers), is the same.<\/p>\n<p>Stage3 (libc install), is the same.<\/p>\n<p>Stage4, which compiles a full compiler is skipped completely.<\/p>\n<p>Another needed change was to make the compiler-rt ebuild cross-aware,<br \/>\nwith changes like making the assembler and C compiler target the target triple, and<br \/>\nincluding headers from the crossdev \/usr\/${CTARGET}\/usr\/include<br \/>\ndirectory instead of using the host&#8217;s libc headers. I got some help from<br \/>\nwikky here, thanks!<\/p>\n<p>Currently doing &#8216;crossdev &#8211;llvm -t riscv64-gentoo-linux-musl &amp;&amp;<br \/>\nriscv64-gentoo-linux-musl-emerge dash&#8217; produces a working binary that<br \/>\ncan be run using qemu-user like this &#8216;qemu-riscv64 -L<br \/>\n\/usr\/riscv64-gentoo-linux-musl \/usr\/riscv64-gentoo-linux-musl\/bin\/dash&#8217;<br \/>\nwhich I think is very cool! However, there is still some issues with<br \/>\ndynamically linking libraries built with the cross compiler. For example<br \/>\nxz-utils installs liblzma.so which fails with &#8220;exec format<br \/>\nerror&#8221;. (http:\/\/sprunge.us\/HkSmms). I am currently looking into that.<\/p>\n<p>Another thing I&#8217;m still a little uncertain about is where to put all<br \/>\nenvironment variables and compilation options, whether it&#8217;s crossdev&#8217;s<br \/>\njob or the ebuilds&#8217;. This is something I will come back to, and I have<br \/>\nsome changes locally on my computer<br \/>\nCrossdev patches:<br \/>\nhttps:\/\/github.com\/alfredfo\/crossdev\/commit\/ec65dee4b4c359bf3e0fc374d31e05b147fa3f0d<br \/>\nCompiler-rt patches:<br \/>\nhttps:\/\/github.com\/alfredfo\/catcream_repo\/blob\/master\/sys-libs\/compiler-rt\/compiler-rt-17.0.0.9999.ebuild<\/p>\n<p>Later during the week I made ebuilds for LLVM libc and<br \/>\nlibc-hdrgen (generates LLVM libc headers from TableGen specification<br \/>\nfiles). Normally you build LLVM libc together with libc-hdrgen, but when<br \/>\ncross compiling it&#8217;s a better idea to split these and keep libc-hdrgen a<br \/>\ntool installed on the build host. I have played with only building<br \/>\nlibc headers for bootstrapping with crossdev but I haven&#8217;t figured it all out yet.<br \/>\nTo only install headers you can use the install-libc-headers target, but<br \/>\nit seems like CMake still wants to build things. There&#8217;s also the scudo<br \/>\nallocator that needs to be statically linked to LLVM libc. My idea is to<br \/>\nmake a USE=static-scudo flag for compiler-rt that gets set in crossdev<br \/>\nwhen compiling compiler-rt for a LLVM libc target.<br \/>\nThese are also kept locally until I&#8217;ve figured out how to cross compile<br \/>\nin stages.<\/p>\n<p>Many &#8220;small random issues&#8221; and technicalities have also poped up during<br \/>\nthis week that&#8217;ve taken quite a long time, but are not really worth<br \/>\ndigging into here.<\/p>\n<p>Next week I will continue with this until I can use it to work on LLVM<br \/>\nlibc, worst case scenario I could temporarily make a &#8220;franken LLVM libc ebuild&#8221; that<br \/>\ndoes everything (headers, compiler-rt, scudo, llvm libc) in one shot,<br \/>\nbut it should definitely be possible to do it separately.<\/p>\n<p>I also forgot to update my llvm-common changes with the new<br \/>\nelisp-site-file-install function that was inspired by my PR \ud83d\ude41<br \/>\n&#8230; will fix that tomorrow.<\/p>\n<p>Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi! This week I have been working on LLVM\/Clang support for Crossdev. This is currently done by swapping out the different Crossdev stages for ones that make sense for LLVM. Currently it replaces stage0 with checking whether LLVM can target &hellip; <a href=\"https:\/\/blogs.gentoo.org\/gsoc\/2023\/07\/24\/weekly-report-6-llvm-libc\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":177,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17,1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts\/542"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/users\/177"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/comments?post=542"}],"version-history":[{"count":1,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts\/542\/revisions"}],"predecessor-version":[{"id":543,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts\/542\/revisions\/543"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/media?parent=542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/categories?post=542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/tags?post=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}