[LLVMdev] Why are functions renamed for .cpp files with llvm-gcc?
Owen Anderson
resistor at mac.com
Wed Jun 17 02:04:49 PDT 2009
On Jun 17, 2009, at 1:39 AM, Fabian Scheler wrote:
> Hi Arto,
>
>> I wonder why there is a difference in how
>> llvm-gcc compiles .c and .cpp files.
>>
>> Example:
>>
>> ---bar.cpp----
>> int bar() {
>> return 42;
>> }
>> --------------
>>
>> $ llvm-gcc -emit-llvm -c bar.cpp
>>
>> Now running bar.o through llvm-dis gives:
>> --------------------------------
>> define i32 @_Z3barv() nounwind {
>> < clip >
>> }
>> --------------------------------
>>
>> Above, function 'bar' has been renamed to '_Z3barv'.
>>
>> If, however, 'bar.cpp' is renamed 'bar.c',
>> we get 'define i32 @bar()' as expected.
>
> The answer is: C++ name mangling
To elaborate a little bit, it's how C++ encodes namespaces, function
overloading, etc. It's a standard thing, and necessary for cross-
compiler compatibility. If you want your C++ functions to appear like
C functions, you need to use extern "C" { }
--Owen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2620 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090617/0f74cceb/attachment.bin>
More information about the llvm-dev
mailing list