global allocation IR instruction

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.

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.

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.