{"id":3199,"date":"2017-10-24T13:28:20","date_gmt":"2017-10-24T20:28:20","guid":{"rendered":"http:\/\/mattfife.com\/?p=3199"},"modified":"2017-10-24T13:28:20","modified_gmt":"2017-10-24T20:28:20","slug":"kernel-compiling-and-the-pic-mode-error","status":"publish","type":"post","link":"https:\/\/mattfife.com\/?p=3199","title":{"rendered":"Kernel compiling and the PIC mode error"},"content":{"rendered":"<p>If you see this when compiling an Ubuntu or other kernel (my case was a Yocto kernel on an Ubuntu 17.04 distro)<br \/>\n<code><br \/>\n...<br \/>\nCHK     include\/generated\/uapi\/linux\/version.h<br \/>\nCHK     include\/generated\/utsrelease.h<br \/>\nCC      scripts\/mod\/empty.o<br \/>\n\/usr\/src\/linux-4.4\/scripts\/mod\/empty.c:1:0: error: code model kernel does not support PIC mode<br \/>\n\/* empty file to figure out endianness \/ word size *\/<br \/>\n<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>Then the issue is with your gcc installation. In gcc 6+ versions, PIE (position independent executables) is enabled by default. So in order to compile you need to disable it. Even gcc 5 has the issue. This is a known bug for gcc.\u00a0<a href=\"http:\/\/bugs.launchpad.net\/bugs\/1574982\" rel=\"nofollow\">Bug Link<\/a>.<\/p>\n<p>So far there is no official patch from gcc side, so the workaround is to patch the Makefile of kernel source.<\/p>\n<p>If you are familiar with patching the source file use the codes from this link to create the patch file then try to compile.<a href=\"https:\/\/lists.ubuntu.com\/archives\/kernel-team\/2016-May\/077178.html\" rel=\"nofollow\">Patch File<\/a><\/p>\n<p>Here&#8217;s the patch to add to your kernel Makefile to disable PIE compiling.<br \/>\n<code><\/code><\/p>\n<blockquote><p>diff &#8211;git a\/Makefile b\/Makefile<br \/>\nindex 5c18baa..e342473 100644<br \/>\n&#8212; a\/Makefile<br \/>\n+++ b\/Makefile<br \/>\n@@ -612,6 +612,12 @@ endif # $(dot-config)<br \/>\n# Defaults to vmlinux, but the arch makefile usually adds further targets<br \/>\nall: vmlinux<\/p>\n<p>+# force no-pie for distro compilers that enable pie by default<br \/>\n+KBUILD_CFLAGS += $(call cc-option, -fno-pie)<br \/>\n+KBUILD_CFLAGS += $(call cc-option, -no-pie)<br \/>\n+KBUILD_AFLAGS += $(call cc-option, -fno-pie)<br \/>\n+KBUILD_CPPFLAGS += $(call cc-option, -fno-pie)<\/p>\n<p># The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default<br \/>\n# values of the respective KBUILD_* variables<br \/>\nARCH_CPPFLAGS :=<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you see this when compiling an Ubuntu or other kernel (my case was a Yocto kernel on an Ubuntu 17.04 distro) &#8230; CHK include\/generated\/uapi\/linux\/version.h CHK include\/generated\/utsrelease.h CC scripts\/mod\/empty.o \/usr\/src\/linux-4.4\/scripts\/mod\/empty.c:1:0: error: code model kernel does not support PIC mode \/* empty file to figure out endianness \/ word size *\/ &nbsp; Then the issue is with your gcc installation. In gcc 6+ versions, PIE (position independent executables) is enabled by default. So in order to compile you need to disable&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/mattfife.com\/?p=3199\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6,7,5],"tags":[],"class_list":["post-3199","post","type-post","status-publish","format-standard","hentry","category-technicalproblemsolutions","category-technicalprogramming","category-technical"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4WECr-PB","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/3199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3199"}],"version-history":[{"count":1,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/3199\/revisions"}],"predecessor-version":[{"id":3200,"href":"https:\/\/mattfife.com\/index.php?rest_route=\/wp\/v2\/posts\/3199\/revisions\/3200"}],"wp:attachment":[{"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mattfife.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}