[LLVMdev] Need advice on fixing my static roots pass

Devang Patel dpatel at apple.com
Mon Aug 8 10:31:13 PDT 2011


On Aug 5, 2011, at 4:06 PM, Talin wrote:

> A recent change to the way metadata works has broken my StaticRoots pass, and I need some advice.
> 
> I was using metadata to store information about static roots because of a convenient feature of metadata nodes: the arguments to an MDNode are treated as weak references, which means that a metadata node that points to a global value won't prevent the dead global pass from removing that global. This is very handy for managing static garbage collection roots, because ordinarily the static roots table contains pointers to the global variables, and those pointers would prevent the global from being considered dead - which means that your final executable would have a bunch of unused cruft in it. But by storing the static roots in metadata, and then constructing the root table from that metadata after the global elimination pass has finished, we end up with a roots table that only includes the roots that are actually used.
> 
> So my first question is - am I abusing the metadata system by doing this? That is, am I relying on undefined behavior here? The reason I ask this is because the scheme I outlined in the previous paragraph no longer works with the current LLVM tip - the metadata nodes that used to contain references to global variables are now all NULL,

… after linking… ?

> regardless of whether the global variable was dead or not.

A concise test case would help understand your situation. As per my understanding following matches what you're doing and it works.

@x = global i32 0
!t = !{!0}
!0 = metadata !{i32 *@x}

-
Devang



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110808/e92edf73/attachment.html>


More information about the llvm-dev mailing list