J Di Or Eximen
J Di Or Eximen

Reputation: 55

Function name mangling in clang

I would like create function on c, that after translated to llvm code with clang has specific name. One problem - target function name must contains point ('.'). Is there any possibility to add "MyName." to the name mangling, except the "find and replace"?

Upvotes: 1

Views: 1655

Answers (1)

keyboardsmoke
keyboardsmoke

Reputation: 156

Name mangling is primarily utilized by other binaries importing that function/variable with dllimport.

If you aren't utilizing this method, you can do whatever you want to the name. If you are, you will have to modify whatever is referencing it as well.

To the point, you'd probably create an LLVM IR pass (look at opt and etc.) to set the function name in the target.

Simple Example:

for(auto f = M.getFunctionList().begin(); f != M.getFunctionList().end(); f = M.getFunctionList().begin()) {
    if (F->getName().find("MyMangledFunctionName") != StringRef::npos) {
        F->setName(F->getName() + "."); // add "dot"
    }
}

"M" variable being llvm::Module.

Upvotes: 1

Related Questions