[LLVMdev] Getting The Resulting Size of Appending Linkage Array?

Chris Lattner sabre at nondot.org
Mon Nov 24 18:55:01 PST 2003


On Sun, 23 Nov 2003, Reid Spencer wrote:

> I think I finally understand how appending linkage type works and what
> it can be used for. What isn't obvious to me is how one gets the size of
> the resulting array.

Understandably so.  :)

> I'm thinking about using this to store bits of source language
> information and understand that it gets concatenated together by the
> linker.  At both compile time and runtime, I want to be able to load an
> arbitrary bytecode file that has possibly been the subject of a previous
> link (thereby combining the appending linkage global arrays). I need to
> locate the global array of interest (I think I can just look it up in
> the Module) and then find out what the resulting size is. The compiler
> needs this to examine previously compiled modules without recompiling
> them from source again. The runtime loader needs to look at it for
> sanity check, security, and other reasons.

> How do I know how big the thing is?

The way we do it in the C/C++ runtime is that the 'gccld' program links in
a crtend.o bytecode file.  This file provides the __main function, but
also provides a terminating null values for the ctor/dtor lists.  In the
case of the ctor/dtor lists, they are then a null terminated list of
function pointers which are inspected at runtime.

If you have the LLVM module available to you, you can always just ask the
GlobalVariable for it's type, and get the size from the array type.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list