Tony Scudiero
2009-Jan-12 17:35 UTC
[LLVMdev] GlobalVaraible and Function have the same name
Hi all, I just walked across an interesting situation in Module::getOrInsertFunction(Name, Type) in the LLVM C API. In my particular case: One of the first things we do is add a global variable named foo which is a [ 100 x i64 ]. Later we add a function void foo(...) unfortunately, when we do the getOrInsertFunction we get back void (...) * bitcast ([100 x i64]* @foo_ to void (...)*) because the symbol foo already exists in the ValueSymbolTable. Am I correct in interpreting this as a constraint that no two items in the ValueSymbolTable can have the same name, even if they're of entirely different types (in this case Function entry point and global variable) ? Is there any way, short of renaming on our end, around this? Thanks! -Tony S.
Chris Lattner
2009-Jan-12 18:51 UTC
[LLVMdev] GlobalVaraible and Function have the same name
On Jan 12, 2009, at 9:35 AM, Tony Scudiero wrote:> Am I correct in interpreting this as a constraint that no two items in > the ValueSymbolTable > can have the same name, even if they're of entirely different types > (in > this case Function entry point and > global variable)?Yes.> Is there any way, short of renaming on our end, > around this? Thanks!You can use some form of name mangling. This is what C++ compilers do to implement support for overloading. -Chris
Gordon Henriksen
2009-Jan-12 20:19 UTC
[LLVMdev] GlobalVaraible and Function have the same name
On 2009-01-12, at 12:35, Tony Scudiero wrote:> Am I correct in interpreting this as a constraint that no two items > in the ValueSymbolTable can have the same name, even if they're of > entirely different types (in this case Function entry point and > global variable) ? Is there any way, short of renaming on our end, > around this? Thanks!That's correct; LLVM does not support overloading symbols based on type. Neither does the linker, though. If you're implementing a high level language, you may need to implement name mangling. http://en.wikipedia.org/wiki/Name_mangling — Gordon