{"id":14573,"date":"2010-03-17T07:00:00","date_gmt":"2010-03-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/03\/17\/what-is-dll-import-hinting\/"},"modified":"2010-03-17T07:00:00","modified_gmt":"2010-03-17T07:00:00","slug":"what-is-dll-import-hinting","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100317-00\/?p=14573","title":{"rendered":"What is DLL import hinting?"},"content":{"rendered":"<p><i>Binding<\/i> and <i>hinting<\/i> are two types of optimizations to improve the load-time performance of a module (executable or DLL). We&#8217;ll start with hinting, then look at binding, and then look at how it affects delay-loading.\n The import table for a module contains a list of DLLs and a list of functions from that DLL which the module wishes to link to. The basic idea is that for each target DLL, the linker loads the DLL and then obtains the address of each imported function and from that DLL, <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/07\/20\/672695.aspx\"> records the results in the loaded module&#8217;s table of imported function addresses<\/a>.\n <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/07\/28\/681473.aspx\"> <i>Hinting<\/i><\/a> is a technique for speeding up this lookup.\n In addition to recording the name of the function the module wishes to link to, the linker also records the index of the function in the target DLL&#8217;s export table. For example, suppose we had a DLL named <code>FLINT<\/code> whose export table looks like this:<\/p>\n<table>\n<tr>\n<td>1<\/td>\n<td><code>Barney<\/code><\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><code>Fred<\/code><\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><code>Wilma<\/code><\/td>\n<\/tr>\n<\/table>\n<p> I&#8217;ve numbered the entries for reasons you&#8217;ll see soon.\n You wrote a DLL which imports all three of these functions. The import table for your DLL goes something like this:<\/p>\n<table>\n<tr>\n<td colspan=\"2\">Import from <code>FLINT<\/code><\/td>\n<\/tr>\n<tr> <\/tr>\n<tr>\n<td rowspan=\"3\" width=\"10\"><\/td>\n<td>Fred (hint = 2)<\/td>\n<\/tr>\n<tr>\n<td>Wilma (hint = 3)<\/td>\n<\/tr>\n<tr>\n<td>Barney (hint = 1)<\/td>\n<\/tr>\n<\/table>\n<p> When your DLL gets loaded, the module loader loads the target DLL <code>FLINT.DLL<\/code>, and then it goes about resolving the imports. First up is <code>Fred<\/code>. But instead of just searching the export table of <code>FLINT.DLL<\/code> for the function <code>Fred<\/code>, it sees the hint and says, &#8220;Hey, let me look in slot&nbsp;2 first.&#8221; And lo and behold, there the function is in slot&nbsp;2. Yay, a full search of the export table was not necessary; the hint sent us directly to the correct slot.\n The hint is just a hint, though. If <code>FLINT.DLL<\/code> doesn&#8217;t have the function <code>Fred<\/code> in slot&nbsp;2, then the loader just does things the old-fashioned way, by searching the export table for the <code>Fred<\/code> function.\n In general, hints are fairly resilient as long as the DLL doesn&#8217;t change too much. If <code>FLINT.DLL<\/code> is updated, say by a security patch, the list of functions typically does not change, so the position in the exported names table remains unchanged. It&#8217;s only if a function is added to or removed from <code>FLINT.DLL<\/code> do the hints begin to lose their effectiveness.<\/p>\n<p> <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2010\/03\/18\/9980802.aspx\"> Next time, we&#8217;ll look at <i>binding<\/i><\/a>, which is an optimization even more powerful than hinting, but which is also more fragile. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Binding and hinting are two types of optimizations to improve the load-time performance of a module (executable or DLL). We&#8217;ll start with hinting, then look at binding, and then look at how it affects delay-loading. The import table for a module contains a list of DLLs and a list of functions from that DLL which [&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-14573","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Binding and hinting are two types of optimizations to improve the load-time performance of a module (executable or DLL). We&#8217;ll start with hinting, then look at binding, and then look at how it affects delay-loading. The import table for a module contains a list of DLLs and a list of functions from that DLL which [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14573","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=14573"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14573\/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=14573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=14573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=14573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}