Reid Spencer
2003-Nov-24 01:00 UTC
[LLVMdev] Getting The Resulting Size of Appending Linkage Array?
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. 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? Reid. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031124/cfa05f98/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20031124/cfa05f98/attachment.sig>
Chris Lattner
2003-Nov-24 18:55 UTC
[LLVMdev] Getting The Resulting Size of Appending Linkage Array?
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/