{"id":2903,"date":"2021-03-27T14:15:17","date_gmt":"2021-03-27T21:15:17","guid":{"rendered":"https:\/\/rglinuxtech.com\/?p=2903"},"modified":"2021-03-30T15:41:15","modified_gmt":"2021-03-30T22:41:15","slug":"compiler-fun-with-clang-kernel-nvidia-and-vmware","status":"publish","type":"post","link":"https:\/\/rglinuxtech.com\/?p=2903","title":{"rendered":"Compiler &#8211; Fun with CLANG &#8211; Kernel, NVIDIA, and VMware&#8230;"},"content":{"rendered":"<p>I have been carrying out some preliminary tests to see how feasible it is to compile the Linux Kernel, and NVIDIA drivers, and VMware, using the &#8216;alternative&#8217; to GCC &#8211; <strong>CLANG<\/strong>..<\/p>\n<p>The kernel compile is relatively easy, and well documented:<\/p>\n<p><code><strong><span style=\"font-family: Courier New, Courier, monospace;\"># make CC=clang HOSTCC=clang -j8 (for a 4-core system)<\/span><\/strong><\/code><\/p>\n<p>The compile seems to be <em>slower<\/em> than GCC, but completes without problems, and boots\/runs OK:<\/p>\n<p><code><strong><span style=\"font-family: Courier New, Courier, monospace;\"># uname -a<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">Linux rg400g4 5.11.10 #1 SMP Fri Mar 26 20:56:15 PDT 2021 x86_64 x86_64 x86_64 GNU\/Linux<\/span><\/strong><\/code><\/p>\n<p>I was able to get the latest NVIDIA driver to compile using:<\/p>\n<p><code><span style=\"font-family: Courier New, Courier, monospace;\"><strong># export CC=clang<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong># export CXX=clang++<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong># .\/NVIDIA-Linux-x86_64-460.67.run -s --install-libglvnd<\/strong><\/span><\/code><\/p>\n<p>This worked, but gave a rather confused warning:<\/p>\n<p><code><span style=\"font-family: Courier New, Courier, monospace;\"><strong>WARNING: Ignoring CC version mismatch:<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>The kernel was built with clang version 12.0.0 (Fedora<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>12.0.0-0.2.rc1.fc34), GNU ld version 2.35.1-41.fc34, but the<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>current compiler version is clang version 12.0.0 (Fedora<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>12.0.0-0.2.rc1.fc34).<\/strong><\/span><\/code><\/p>\n<p>Once again, the compile seemed to take longer than GCC, but completed successfully:<\/p>\n<p><code><span style=\"font-family: Courier New, Courier, monospace;\"><strong># lsmod |grep nv<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>nvidia_drm 61440 0<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>nvidia_modeset 1208320 1 nvidia_drm<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>nvidia 34009088 1 nvidia_modeset<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>drm_kms_helper 212992 1 nvidia_drm<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>drm<\/strong><\/span><\/code><\/p>\n<p>A manual compile from extracted <strong><span style=\"font-family: Courier New, Courier, monospace;\">!\/NVIDIA-Linux-x86_64-460.67.run\/kernel<\/span><\/strong> showed a large number of &#8216;warnings&#8217;:<\/p>\n<p><code><strong><span style=\"font-family: Courier New, Courier, monospace;\"># export CC=clang<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\"># export CXX=clang++<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\"># make<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">.............<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">\/home\/rgadsdon\/NVIDIA-Linux-x86_64-460.67\/kernel\/nvidia-uvm\/uvm_map_external.c:104:59: warning: implicit conversion from enumeration type 'const UvmGpuCachingType' to different enumeration type 'UvmRmGpuCachingType' [-Wenum-conversion]<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">pte_buffer-&gt;mapping_info.cachingType = map_rm_params-&gt;caching_type;<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">~ ~~~~~~~~~~~~~~~^~~~~~~~~~~~<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">&lt;&lt; repeated.. &gt;&gt;<\/span><\/strong><br \/>\n<strong><span style=\"font-family: Courier New, Courier, monospace;\">.............<\/span><\/strong><\/code><\/p>\n<p><strong>VMware<\/strong> was interesting, and the usual <span style=\"font-family: Courier New, Courier, monospace;\"><strong>vmware-modconfig<\/strong><\/span>&#8230;. was confused, and failed as it could not find gcc, despite prior CC\/HOSTCC exports to clang etc:<br \/>\n<code><span style=\"font-family: Courier New, Courier, monospace;\"><strong># vmware-modconfig --console --install-all <\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>[AppLoader] GLib does not have GSettings support.<\/strong><\/span><br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong>Failed to get gcc information....<\/strong><\/span><\/code><\/p>\n<p>This was due to the fact that it was still trying to find gcc, and was failing, as gcc was not specified..<\/p>\n<p>(Just to confirm, the <em>Fedora 34<\/em> gcc version\u00a0 &#8211; <strong>gcc 11<\/strong>.. &#8211; <span style=\"text-decoration: underline;\">does<\/span> work OK with the <span style=\"font-family: Courier New, Courier, monospace;\"><strong>vmware-modconfig<\/strong><\/span> command, when compiling with gcc..)<\/p>\n<p>The simplest workaround for this is to use the patched <strong>vmmon<\/strong>\/<strong>vmnet<\/strong> source in the (current) <strong><span style=\"font-family: Courier New, Courier, monospace;\">vmware-host-modules-workstation-16.1.0<\/span><\/strong> directory, and run:<br \/>\n<span style=\"font-family: Courier New, Courier, monospace;\"><strong># make CC=clang HOSTCC=clang<\/strong><\/span> followed by (su) <strong><span style=\"font-family: Courier New, Courier, monospace;\">#make install<\/span><\/strong> . I found that in this case separate <span style=\"font-family: Courier New, Courier, monospace;\"><strong># export CC=clang<\/strong><\/span> and <strong><span style=\"font-family: Courier New, Courier, monospace;\"># export HOSTCC=clang<\/span><\/strong> followed by <span style=\"font-family: Courier New, Courier, monospace;\"><strong># make<\/strong><\/span> failed, but the inline command did work..<\/p>\n<p>The resulting system booted OK, and NVIDIA and VMware both ran successfully.<br \/>\nI was not able to detect any obvious performance issues, but the system was not stress tested at this time&#8230;.\u00a0\u00a0 This was an interesting exercise, but I am going to stay with <strong>gcc<\/strong>, for the time being..<\/p>\n<p>As a historical note, this was the first time I had compiled the Kernel without using &#8216;vanilla&#8217; GCC, since the days &#8211; many years ago &#8211; when I had to use EGCS&#8230;<\/p>\n<p><em>Robert Gadsdon.\u00a0 March 27th, 2021.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have been carrying out some preliminary tests to see how feasible it is to compile the Linux Kernel, and NVIDIA drivers, and VMware, using the &#8216;alternative&#8217; to GCC &#8211; CLANG.. The kernel compile is relatively easy, and well documented: # make CC=clang HOSTCC=clang -j8 (for a 4-core system) The compile seems to be slower than GCC, <span class=\"excerpt-dots\">&hellip;<\/span> <a class=\"more-link\" href=\"https:\/\/rglinuxtech.com\/?p=2903\"><span class=\"more-msg\">Continue reading &rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2377,5,10,1617,14,15,18,19,20,1535,25],"tags":[2378,2036,2379,1173,277,1175,402],"class_list":["post-2903","post","type-post","status-publish","format-standard","hentry","category-clang","category-compilation","category-fedora","category-gcc","category-kernel","category-linux-2","category-nvidia","category-opinion","category-performance-2","category-quirks","category-vmware","tag-clang","tag-compile-tests","tag-gcc-alternative","tag-kernel","tag-nvidia-2","tag-success","tag-vmware-2"],"_links":{"self":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/2903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2903"}],"version-history":[{"count":9,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/2903\/revisions"}],"predecessor-version":[{"id":2912,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=\/wp\/v2\/posts\/2903\/revisions\/2912"}],"wp:attachment":[{"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rglinuxtech.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}