harry
harry

Reputation: 1095

Add section attribute to global variable in llvm

int x `__attribute__ ((section("some_name")))`;

I have a global variable x and would like to add __attribute__ ((section("custom_name"))) to it. How would i do that in LLVM?

I created the global variable x as below.

GlobalVariable *x =
        new GlobalVariable(M, Type::getInt32Ty(C), false, GlobalValue::ExternalLinkage, 0,
                           "x");

Upvotes: 2

Views: 1029

Answers (1)

x4444
x4444

Reputation: 2172

You can use void GlobalObject::setSection(StringRef S)
method from parent class GlobalObject.

GlobalVariable *x = new GlobalVariable(...);

x->setSection(".lrodata") // >2GB rodata on Linux x86_64
x->setAlignment(llvm::Align(N));

Upvotes: 1

Related Questions