Hi all, In order to allocate memory on the stack there is AllocaInst instruction. What is the similar instruction/way to allocate memory on the global area? Thanks, Tehila. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150419/54298396/attachment.html>
Tehila Mayzels wrote:> Hi all, > > In order to allocate memory on the stack there is AllocaInst instruction. > > What is the similar instruction/way to allocate memory on the global area?There isn't one. Create a call to malloc, if you're linking against a library that supplies malloc.
Thanks a lot for the quick response! Tehila. -----Original Message----- From: Nick Lewycky [mailto:nicholas at mxc.ca] Sent: Sunday, April 19, 2015 11:59 PM To: Tehila Mayzels Cc: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] global allocation IR instruction Tehila Mayzels wrote:> Hi all, > > In order to allocate memory on the stack there is AllocaInst instruction. > > What is the similar instruction/way to allocate memory on the global area?There isn't one. Create a call to malloc, if you're linking against a library that supplies malloc.
On 4/19/15 4:59 PM, Nick Lewycky wrote:> Tehila Mayzels wrote: >> Hi all, >> >> In order to allocate memory on the stack there is AllocaInst >> instruction. >> >> What is the similar instruction/way to allocate memory on the global >> area? > > There isn't one. Create a call to malloc, if you're linking against a > library that supplies malloc. > _______________________________________________Or create a global variable with a name that isn't typically accessible. The compiler prefixes variables like this with "llvm." (mostly). The "." in the name makes it inaccessible from C, but linkers should be happy with it. You can search the llvm sources for "llvm.global_ctors" to see this getting done. It's probably a good idea to avoid names which begin with "llvm." for your own internal symbol. Whether you use malloc or create a variable depends on what you are trying to do. The global variable can't create memory leaks, but also can't be recursive.