So, I've got a case where I am attempting to pass the address of a static symbol from a module written in Tart (the language I am working on), to a module written in C (which is part of Tart's runtime library). This works fine on Linux, but fails on OS X because the address being passed is the "non_lazy_ptr" symbol, not the symbol itself.<div>

<br></div><div>In my .bc file, I've got code that looks like this:</div><div><br></div><div><div>  @gc_safepoint_map = external global [0 x i32]     ; <[0 x i32]*> [#uses=1]</div><div><br></div><div><div>  %init = invoke {} @GC_init(i32* getelementptr inbounds ([0 x i32]* @gc_safepoint_map, i32 0, i32 0))</div>

<div>          to label %nounwind unwind label %catch, !dbg !400 ; <{}> [#uses=0]</div><div><br></div><div>In other words, we have an external symbol that is being passed to an external function. (BTW, gc_safepoint_map is the map of all of the stack offsets containing pointers, indexed by the program counter address of the safe point. It's generated by a custom linker pass.)</div>

<div><br></div><div>However, the code that is being generated looks like this:</div><div><br></div><div><div>        movl    L_gc_safepoint_map$non_lazy_ptr, %eax</div><div>        movl    %eax, (%esp)</div><div>        call    _GC_init</div>

</div><div><br></div><div>In other words, it's passing the 'non_lazy_ptr' version of the symbol directly to GC_init, without dereferencing it. This makes the code go boom.</div><div><br></div><div>OK, so my question is:</div>

<div><ul><li>Where exactly would this dereference normally occur?</li><ul><li>Would it be in the calling module (written in bitcode)? If so, do I need to generate bitcode to dereference the symbol, or is there some means to do this automatically? If I need to generate the bitcode myself, how do I tell whether the current target is one that needs this?</li>

<li>Conversely, would I need to write code on the callee side (written in C). In this case, I don't have access to target data, just cmake config variables. Again, I'd need to come up with some test I can write in cmake language that lets me know whether or not I need to do the special dereference.</li>

<li>Alternatively perhaps there is some linker flag I can set that makes this problem go away.</li></ul></ul><div>Any suggestions?</div></div><div><br></div>-- <br>-- Talin<br>
</div></div>