{"id":5541,"date":"2014-03-31T00:06:17","date_gmt":"2014-03-31T00:06:17","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/31\/creating-and-running-executable-by-hand-collection-of-common-programming-errors\/"},"modified":"2014-03-31T00:06:17","modified_gmt":"2014-03-31T00:06:17","slug":"creating-and-running-executable-by-hand-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/31\/creating-and-running-executable-by-hand-collection-of-common-programming-errors\/","title":{"rendered":"Creating and running executable by hand-Collection of common programming errors"},"content":{"rendered":"<p>Since you said <strong>simplest<\/strong> program, here is a real hack.<\/p>\n<p>This is for Ubuntu 12.04, running x86_64. If you have something else, then this might give you a hint what to do.<\/p>\n<pre><code>mkdir hack_code\ncd hack_code\ncp \/usr\/lib\/ldscripts\/elf_x86_64.x ldsimple.x\n<\/code><\/pre>\n<p>Now modify <code>ldsimple.x<\/code> to say <code>ENTRY(main)<\/code> instead of <code>ENTRY(_start)<\/code> in the beginning.<\/p>\n<p>Create this <code>mymain.c<\/code>:<\/p>\n<pre><code>int main(void)\n{\n    __asm__ __volatile__ (\n        \"movq $60, %rax\\n\"  \/* call sys_exit *\/\n        \"movq $2,  %rdi\\n\"  \/* return code   *\/\n        \"syscall\"           \/* call kernel to exit program *\/\n    );\n    return 0;\n}\n<\/code><\/pre>\n<p>And then:<\/p>\n<pre><code>gcc -c mymain.c\nld -o mymain -T.\/ldsimple.x mymain.o\n<\/code><\/pre>\n<p>Voila: You now have got a program which does not use any library etc.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since you said simplest program, here is a real hack. This is for Ubuntu 12.04, running x86_64. If you have something else, then this might give you a hint what to do. mkdir hack_code cd hack_code cp \/usr\/lib\/ldscripts\/elf_x86_64.x ldsimple.x Now modify ldsimple.x to say ENTRY(main) instead of ENTRY(_start) in the beginning. Create this mymain.c: int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5541","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5541"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5541\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}