LLVM Discussion Forums

How to add a writeable llvm section by IRbuilder?

I want to encrypt the special constant and store it to somewhere section writeable by IRbuilder.
The data could be very large, I wonder whether I can assign some of the global variable to an special new section( has the different name, not like bss or other section).
So that the binary could be added that writeable section which only store my target data.

Yes you can specify a section for a global in clang
https://clang.llvm.org/docs/AttributeReference.html#section-declspec-allocate
which means you can do it in LLVM-IR. I’d need to check if the IRBuilder exposes the
functionality but you can certainly modify the section directly with the GlobalVariable (as describe here https://llvm.org/docs/LangRef.html#global-variables)

FWIW, there is a clang mailing list that is often the faster way to get help
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
and there is a generic llvm one as well
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Cheers,
Johannes

Thanks a lot.
I’ve solved it using GV->setSection function