[LLVMdev] Boehm GC + static variables?

James Williams junk at giantblob.com
Sun Jan 31 06:12:21 PST 2010


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.

This should be safe assuming that:
- 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)
- llvm.global_ctors for a given module is run before any other code can
reference static variables belonging to that module.

Can anyone confirm if I can rely on these assumptions?

-- James


On 31 January 2010 12:53, James Williams <junk at giantblob.com> wrote:

> Hi,
>
> I'm running LLVM bitcode generated by my compiler under lli. The bitcode is
> linked against Boehm GC (lli -load=/usr/lib/libgc.so).
>
> 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.
>
> 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?
>
> Thanks in advance,
> -- James Williams
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100131/1d991e86/attachment.html>


More information about the llvm-dev mailing list