[LLVMdev] global allocation IR instruction
Herbie Robinson
HerbieRobinson at verizon.net
Sun Apr 19 16:13:38 PDT 2015
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.
More information about the llvm-dev
mailing list