{"id":18933,"date":"2009-03-05T10:00:00","date_gmt":"2009-03-05T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/03\/05\/fixups-are-not-the-same-as-rewriting-code-theyre-just-fixups\/"},"modified":"2009-03-05T10:00:00","modified_gmt":"2009-03-05T10:00:00","slug":"fixups-are-not-the-same-as-rewriting-code-theyre-just-fixups","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090305-00\/?p=18933","title":{"rendered":"Fixups are not the same as rewriting code, they&#8217;re just fixups"},"content":{"rendered":"<p>Classically speaking, a linker cannot rewrite the code the compiler generated; its job is merely to resolve symbols. Of course, resolving symbols means that references to those symbols in the code generated by the compiler turn from &#8220;I don&#8217;t know&#8221; to &#8220;Here it is.&#8221; Somebody named George <a href=\"http:\/\/groups.google.com\/groups?selm=2EAD77B3-CB96-4FB7-9019-70D272D4B65B%40microsoft.com\"> appeared to be confused by this<\/a>, believing that all changes by the linker counted as &#8220;rewriting code.&#8221;<\/p>\n<p> Obviously if the linker weren&#8217;t allowed to change anything at all, there wouldn&#8217;t be much point to having a linker. For example, you wouldn&#8217;t be able to access functions or variables in a separate compilation unit (for example, from a library) because the compiler doesn&#8217;t know what the final address is; that&#8217;s what the linker is supposed to figure out. (Indeed, if <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/xsa71f43.aspx\"> function-level linking<\/a> is enabled, then even calls within a compilation unit are left as <i>insert address here<\/i>.) The linker resolves symbols and patches up code references that used to say <i>insert address here<\/i> so that they contain the actual address. <\/p>\n<p> I think George took my statement a bit too literally. The linker can&#8217;t change a direct call to an indirect call; that&#8217;s not something that the compiler told the linker how to do. All the linker can do is patch up <i>insert address here<\/i> fixups. It can&#8217;t say &#8220;Oh, I&#8217;m going to take your two <code>mov<\/code> instructions and reverse the destination registers, and then flip the arguments to the subsequent <code>sub<\/code> instruction.&#8221; (I&#8217;m talking about classical linking; the introduction of <a href=\"http:\/\/msdn.microsoft.com\/msdnmag\/issues\/02\/05\/Hood\/\"> link-time code generation<\/a> further blurs the line between the compiler and the linker.) <\/p>\n<p> George also made the common mistake not only of calling this Web site a &#8220;document from MSDN&#8221; but also applying the same description to a <i>Microsoft Systems Journal<\/i> article from 1997. The back issues of MSJ are included in MSDN as a courtesy. Neither the back issues nor the contents of this Web site are under MSDN editorial control. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Classically speaking, a linker cannot rewrite the code the compiler generated; its job is merely to resolve symbols. Of course, resolving symbols means that references to those symbols in the code generated by the compiler turn from &#8220;I don&#8217;t know&#8221; to &#8220;Here it is.&#8221; Somebody named George appeared to be confused by this, believing that [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-18933","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Classically speaking, a linker cannot rewrite the code the compiler generated; its job is merely to resolve symbols. Of course, resolving symbols means that references to those symbols in the code generated by the compiler turn from &#8220;I don&#8217;t know&#8221; to &#8220;Here it is.&#8221; Somebody named George appeared to be confused by this, believing that [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/18933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=18933"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/18933\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=18933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=18933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=18933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}