<div dir="ltr">No, it does not seem writable. The following program crashes at the first line in main().<div><br></div><div>__declspec(dllexport) void foo(void) {}<br>extern void (*_imp__foo)(void);</div><div><br></div><div>

int main() {</div><div>  _imp__foo = 0;<br>  return 0;</div><div>}</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 24, 2014 at 2:08 PM, Reid Kleckner <span dir="ltr"><<a href="mailto:rnk@google.com" target="_blank">rnk@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Can I use it do this?<div><br style="font-family:arial,sans-serif;font-size:13px"><span style="font-family:arial,sans-serif;font-size:13px">__declspec(dllimport) v</span><span style="font-family:arial,sans-serif;font-size:13px">oid hello(void);</span><br style="font-family:arial,sans-serif;font-size:13px">


<span style="font-family:arial,sans-serif;font-size:13px">extern void (*__imp__hello)(void);</span><br></div><div>void my_hello(void) { ... }</div><div>int main() {</div><div>  __imp__hello = my_hello;<br>}</div><div><br>


</div><div>I think the __imp_ pointers are writable.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Thu, Apr 24, 2014 at 1:57 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>On Thu, Apr 24, 2014 at 1:29 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>




<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><br><div class="gmail_quote">On Thu, Apr 24, 2014 at 1:12 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br>





<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="overflow:hidden">Using __imp_ symbols locally is I think not a good coding style. One<br>

should just take an address using "&" operator rather than appending<br>
__imp_ prefix. However, there are programs in the wild that depends<br>
on this link.exe's behavior, so we need this feature.</div></blockquote></div><br></div>I wonder if we should have a warning about this?</div></div></blockquote><div><br></div></div><div>Ideally, yes, but there's no good way to print a warning message when some symbol is actually linked. In this patch I create __imp_ symbols unconditionally for all dllexported symbols. Creating them is not visible to user -- using them should be warned.</div>


<div>

<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">I also wonder whether the cause in the wild is source code being shared between the DLL and the users of the DLL and being written "generically".</div>





</div>
</blockquote></div></div><br></div><div class="gmail_extra">The program I spotted in the wild is ffmpeg. That has /include:__imp_<i>sym</i> where <i>sym</i> is a defined function in ffmpeg (/include is equivalent to --undefined). Not sure why it has such option as it is basically no-op to link.exe.</div>




<div class="gmail_extra"><br></div><div class="gmail_extra">I don't think writing code generically cannot really justify to use __imp_ symbols, as you can just use "&", so I'm still wondering what this feature is really for...</div>




</div>
<br></div></div><div class="">_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></div></blockquote></div><br></div>
</blockquote></div><br></div>