<div dir="ltr"><div>Hi Edward,</div><div><br></div><div>Thanks for the information, it really helped make it more clear to me what's going on.</div><div><br></div><div>I would ideally like to get these validate errors on Windows down to 0 (without marking them as expected fail).</div><div>So I will probably make a ticket for this.</div><div><br></div><div>Cheers,</div><div>Tamar</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 20, 2015 at 1:28 AM, Edward Z. Yang <span dir="ltr"><<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Excerpts from lonetiger's message of 2015-08-11 12:43:34 -0700:<br>
<span>> 1) Has to do with checkProddableBlock and #10672 and #10563<br>
><br>
> static void checkProddableBlock (ObjectCode *oc, void *addr, size_t size )<br>
> {<br>
>    ProddableBlock* pb;<br>
><br>
>    for (pb = oc->proddables; pb != NULL; pb = pb->next) {<br>
>       char* s = (char*)(pb->start);<br>
>       char* e = s + pb->size;<br>
>       char* a = (char*)addr;<br>
>       if (a >= s && (a+size) <= e) return;<br>
>    }<br>
>    barf("checkProddableBlock: invalid fixup in runtime linker: %p", addr);<br>
> }<br>
><br>
> From what I have found, these errors seem to happen because oc->proddables is initially NULL,<br>
> the for loop is skipped. From what I can tell, this function is checking if there's a "proddable"<br>
> that fits within the supplied address and size. So if there is no proddables to begin with, should this<br>
> check just not be skipped and the callee of this call not use this ObjectCode instead of erroring out?<br>
<br>
</span>Relocating objects consists of iterating over a list of "relocations",<br>
which essentially says, "please modify the word of memory at addr to<br>
point to the actual location of some symbol."<br>
<br>
The essential effect is that GHC is going to scribble over some memory<br>
that the object told it to.  So it's a /really really/ idea to make sure<br>
that we aren't scribbling over something random, like some GHC<br>
structures. checkProddableBlock ensures that the memory location to<br>
be relocated ACTUALLY resides in the object code we are loading.<br>
<br>
If we put it this way, it's pretty obvious what the bug has to be:<br>
we are processing a relocation for some code that we didn't actually<br>
make a proddable block for.  This can happen if we didn't understand<br>
the section.<br>
<br>
I've updated #10672 and #10563 accordingly.<br>
<span><br>
> 2) The second question is about static int ocGetNames_PEi386 ( ObjectCode* oc )<br>
> I am getting a test failure because it is claiming that .eh_frame section is misaligned.<br>
> This comes from this code:<br>
><br>
>   if (kind != SECTIONKIND_OTHER && end >= start) {<br>
>            if ((((size_t)(start)) % 4) != 0) {<br>
>                errorBelch("Misaligned section %s: %p", (char*)secname, start);<br>
>                stgFree(secname);<br>
>                return 0;<br>
>            }<br>
><br>
> Where start is defined as:<br>
><br>
> start = ((UChar*)(oc->image)) + sectab_i->PointerToRawData;<br>
> and  oc->image is a memory location received by allocateImageAndTrampolines.<br>
><br>
> In the case of my test failure it is because the .eh_frame section seems to begin at 0x30F<br>
> since oc->image will always be 4 aligned (so it doesn't really matter in the check) it gives that error because PointerToRawData isn't aligned by 4.<br>
><br>
> So my question is would it not be better just to check the alignment flag in the PE section header instead of checking the load address (which is always going to aligned to 4?) and The file pointer to<br>
> the first page of the section within the COFF file to determine the alignment? Like objdump and dumpbin do?<br>
><br>
> e.g.<br>
><br>
> 9 .eh_frame     00000038  00000000  00000000  0000030f  2**2<br>
>                   CONTENTS, ALLOC, LOAD, RELOC, READONLY, DATA<br>
><br>
> Is the output from objdump which correctly determines the alignment from the section. From what I understand from the PE specification<br>
> the on disk address doesn't have to be aligned by 4:<br>
><br>
> "For object files, the value *should* be aligned on a 4-byte boundary for best performance."<br>
><br>
> I'm wondering if we are incorrectly erroring out here, instead of using the section and making sure we pad it to the alignment boundary.<br>
<br>
</span>It should be fine to make the code more flexible to accept arbitrary<br>
alignments.  However, I would expect you would have to make some code<br>
to make this work.<br>
<br>
If you are interested in doing this, make sure you add tests to the test<br>
suite which specifically construct objects with sections which are not<br>
4-byte aligned.  Please also feel free to open a bug to track this work.<br>
<br>
Thanks,<br>
Edward<br>
</blockquote></div><br></div>