{"id":25,"date":"2008-11-22T05:36:00","date_gmt":"2008-11-22T13:36:00","guid":{"rendered":"http:\/\/samueldotj.com\/blog\/?p=25"},"modified":"2013-09-04T15:19:34","modified_gmt":"2013-09-04T22:19:34","slug":"porting-to-intel-c-compiler","status":"publish","type":"post","link":"http:\/\/samueldotj.com\/blog\/porting-to-intel-c-compiler\/","title":{"rendered":"Porting to \u201cIntel C Compiler\u201d"},"content":{"rendered":"<p>In this post, I will explain how to easy it is to compile\/port C programs and makefiles designed for GCC(GNU compiler collection) can be used with <a href=\"http:\/\/software.intel.com\/en-us\/c-compilers\">ICC<\/a>(Intel C Compiler)<\/p>\n<p>The necessity for using ICC happened to me because gcc was generating too big object files. Ace is using ACPI-CA(<a href=\"http:\/\/acpica.org\/\">http:\/\/acpica.org\/<\/a>) as it is ACPI driver. After compilation the ACPI library is around 7M in debug version and around 500K in non-debug version. But from http:\/\/acpica.org\/download\/changes.txt it seems Microsoft C compiler produce smaller code.<br \/>\n[shell]<br \/>\n  Non-Debug Version: \u00a081.2K Code, 17.0K Data, \u00a098.2K Total<br \/>\n  Debug Version: \u00a0 \u00a0 155.8K Code, 49.1K Data, 204.9K Total<br \/>\n[\/shell]<\/p>\n<p>So I decided to try \u201cIntel Compiler\u201d as replacement for GCC. Things were easy, since icc has options which is similar to gcc.<br \/>\nYou can get the details of portability options from icc documentation &#8211; <a href=\"http:\/\/www.intel.com\/software\/products\/compilers\/docs\/clin\/main_cls\/index.htm\">http:\/\/www.intel.com\/software\/products\/compilers\/docs\/clin\/main_cls\/index.htm<\/a>.<\/p>\n<p>I just changed my make.conf file to check the compiler in use and use appropriate options. I removed <strong>-fno-leading-underscore<\/strong> and <strong>\u2013Wall<\/strong>. I removed \u2013Wall because it was giving lot of warnings, we have to fix our code sometime soon. I removed -fno-leading-underscore because there is no equivalent option in icc, however icc does not adds underscores to symbols anyway.<\/p>\n<p>I added <strong><code>\u2013O1<\/code><\/strong> option because the kernel was panicked during boot with invalid opcode exception, I believe it was because of some MMX register usage by icc. So I settled with \u2013O1 now.<br \/>\n[shell]<br \/>\nifeq ($(CC),gcc)<br \/>\n    DEBUG_FLAGS= -gdwarf-2 -g3<br \/>\n    CFLAGS+= -Wall -Wno-multichar $(DEFINES) -nostartfiles -ffreestanding -funsigned-char -fno-leading-underscore -c -fno-stack-protector $(DEBUG_FLAGS) $(CUSTOM_FLAG)<br \/>\nelse<br \/>\n    DEBUG_FLAGS= -gdwarf-2 -g<br \/>\n    CFLAGS+= -O1 -Wno-multichar $(DEFINES) -nostartfiles -ffreestanding -funsigned-char -c -fno-stack-protector $(DEBUG_FLAGS) $(CUSTOM_FLAG)<br \/>\nendif<br \/>\n[\/shell]<\/p>\n<p>I also made some static variables in kernel\/i386\/gdb_stub.c to non-static because icc appends .0 to static variables but it forgets the same name when referenced in a inline assembly code in the same file. After removing the static attribute it is working fine.<\/p>\n<p><strong>Compilation time:<\/strong><br \/>\ngcc compiler took the following time to compile Ace source code.<br \/>\n[shell]<br \/>\nreal    0m51.125s<br \/>\nuser    0m36.975s<br \/>\nsys     0m11.185s<br \/>\n[\/shell]<\/p>\n<p>icc compiler took the following time to compile Ace source code.<br \/>\n[shell]<br \/>\nreal    1m44.366s<br \/>\nuser    0m59.107s<br \/>\nsys     0m20.946s<br \/>\n[\/shell]<\/p>\n<p><strong>Size:<\/strong><br \/>\nGcc produced double the size of kernel.sys produced by icc. (I used GNU linker(ld) and ar).<br \/>\ngcc output size:<br \/>\n[c]<br \/>\n$ ls -lh \/home\/samuel\/Projects\/Ace3\/obj\/<br \/>\n-rw-rw-r\u2013 1 samuel samuel 372K 2008-11-22 18:17 acpi.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel 545K 2008-11-22 18:17 arch.a<br \/>\n-rwxrwxr-x 1 samuel samuel 1.3M 2008-11-22 18:17 kernel.sys<br \/>\n-rw-rw-r\u2013 1 samuel samuel  62K 2008-11-22 18:17 libds.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  40K 2008-11-22 18:17 libheap.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  39K 2008-11-22 18:17 libstring.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel 9.5K 2008-11-22 18:17 libsync.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  91K 2008-11-22 18:17 pic.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  23K 2008-11-22 18:17 pit.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  21K 2008-11-22 18:17 rtc.a<br \/>\n[\/c]<br \/>\nicc output:<br \/>\n[c]<br \/>\n$ ls -lh \/home\/samuel\/Projects\/Ace3\/obj\/<br \/>\n-rw-rw-r\u2013 1 samuel samuel 352K 2008-11-22 16:25 acpi.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel 230K 2008-11-22 16:24 arch.a<br \/>\n-rwxrwxr-x 1 samuel samuel 528K 2008-11-22 16:25 kernel.sys<br \/>\n-rw-rw-r\u2013 1 samuel samuel  38K 2008-11-22 16:23 libds.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  22K 2008-11-22 16:23 libheap.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  21K 2008-11-22 16:23 libstring.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  11K 2008-11-22 16:23 libsync.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  19K 2008-11-22 16:24 pic.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel 8.4K 2008-11-22 16:24 pit.a<br \/>\n-rw-rw-r\u2013 1 samuel samuel  13K 2008-11-22 16:24 rtc.a<br \/>\n[\/c]<\/p>\n<p>Conclusion: So it is easy to switch to icc instead of gcc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I will explain how to easy it is to compile\/port C programs and makefiles designed for GCC(GNU compiler collection) can be used with ICC(Intel C Compiler) The necessity for using ICC happened to me because gcc was generating too big object files. Ace is using ACPI-CA(http:\/\/acpica.org\/) as it is ACPI driver. After [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3,10,9],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-ace","category-c","category-compiler","category-gcc"],"_links":{"self":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":3,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"predecessor-version":[{"id":202,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions\/202"}],"wp:attachment":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}