I've implemented this by adding calls to GC_add_roots(<first global in module>,<last global in module>+1) to the llvm.global_ctors before any other static initialization code for the module.<br><br>This should be safe assuming that:<br>
- global variables are laid out in memory in the order they appear in their module (and ideally contiguously without being interleaved with any other values)<br>- llvm.global_ctors for a given module is run before any other code can reference static variables belonging to that module.<br>
<br>Can anyone confirm if I can rely on these assumptions?<br><br>-- James<br><br><br><div class="gmail_quote">On 31 January 2010 12:53, James Williams <span dir="ltr"><<a href="mailto:junk@giantblob.com">junk@giantblob.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi,<br><br>I'm running LLVM bitcode generated by my compiler under lli. The bitcode is linked against Boehm GC (lli -load=/usr/lib/libgc.so).<br>
<br>It looks like Boehm GC isn't scanning global variables and as a result objects referenced only through globals are being prematurely collected. I understand that Boehm GC needs to see the data segment containing my global variables as a root. For native executables It's smart enough to pick this up from the sections in the ELF executable but this doesn't apply when LLVM bitcode is running under lli.<br>

<br>Is there some way I can hook into the code generator's placement of new data segments as bitcode is compiled to native code so I can add roots for the segments as required by Boehm GC?<br><br>Thanks in advance,<br>
<font color="#888888">
-- James Williams<br>
</font></blockquote></div><br>