{"id":21,"date":"2009-08-28T02:23:00","date_gmt":"2009-08-28T09:23:00","guid":{"rendered":"http:\/\/samueldotj.com\/blog\/?p=21"},"modified":"2013-09-04T14:57:46","modified_gmt":"2013-09-04T21:57:46","slug":"debugging-gcc-behavior","status":"publish","type":"post","link":"http:\/\/samueldotj.com\/blog\/debugging-gcc-behavior\/","title":{"rendered":"GCC debugging switches"},"content":{"rendered":"<p>While compiling a FreeBSD kernel I encountered the following error message from GNU assembler<br \/>\n[shell]<br \/>\nError: suffix or operands invalid for &#8216;mov&#8217;<br \/>\n[\/shell]<\/p>\n<p>I was not sure whether the error is because of my changes are not. But still I have to debug the problem and solve it, so I decided to find what is wrong with the <em>mov <\/em>instruction. But since gcc created a temporary file and invoked as to assemble it, I couldn\u2019t find the temp file anymore.<\/p>\n<p>Googled and find the following gcc options to find what gcc does.<\/p>\n<p><strong>gcc \u2013v<\/strong> is verbose mode, which prints all the action\/scripts gcc is doing.<br \/>\n<strong>gcc -###<\/strong> similar to \u2013v but wont execute any commands.<br \/>\n<strong>gcc \u2013save-temps<\/strong> saves all the temporary files generated by the gcc. Useful if you want to see the assembly output passed to gnu assembler.<br \/>\n<strong>gcc \u2013E<\/strong> Just preprocess the c file.<br \/>\n<strong>gcc \u2013S<\/strong> generate assembly file.<\/p>\n<p>With gcc \u2013v \u2013save-temps, I got the temporary assembler file used by assembler. Since reading machine generated assembly file is difficult, I tried to find the C source code corresponding to the error. From nearest .file <a href=\"http:\/\/sourceware.org\/binutils\/docs-2.19\/as\/Pseudo-Ops.html#Pseudo-Ops\">assembler directive<\/a> I found the C file name and from the .loc directive I found the line number. And the following was the inline assembly in the C file.<br \/>\n[c]__asm __volatile(&#8220;<b>movl <\/b>%%ss,%0&#8243; : &#8220;=rm&#8221; (sel));[\/c]<\/p>\n<p>Was surprised what is wrong with this and why my assembler giving error. Googled again and found this link &#8211; <a href=\"http:\/\/kerneltrap.org\/node\/5785\">http:\/\/kerneltrap.org\/node\/5785<\/a>. It seems newer gnu assembler(>=2.16) wont support long read\/write operations(mov) on segment registers(ds,ss&#8230;). So changed the above source to <code>movw %%ss, %o<\/code> and it compiled perfectly. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While compiling a FreeBSD kernel I encountered the following error message from GNU assembler [shell] Error: suffix or operands invalid for &#8216;mov&#8217; [\/shell] I was not sure whether the error is because of my changes are not. But still I have to debug the problem and solve it, so I decided to find what is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,9,11,5,4],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-c","category-gcc","category-kernel","category-programming","category-tools"],"_links":{"self":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/21","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=21"}],"version-history":[{"count":3,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":197,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/posts\/21\/revisions\/197"}],"wp:attachment":[{"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/samueldotj.com\/blog\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}