FFI question

Richard A. O'Keefe ok at cs.otago.ac.nz
Tue May 4 01:56:24 UTC 2004


"Andreas Raab" <andreas.raab at gmx.de> asked:
	Wait a second - isn't name mangling standardized?

No, it isn't.
What's more, the very *existence* of name mangling is not standardised;
a C++ compiler could use a linker which works directly with overloaded
names without any kind of name mangling.

	I cannot imagine how you'd link against a C++ library if each
	compiler mangles the name in the way she wants to...
	
With trepidation, how else?  There are so many other ways that C++
compilation can vary that you couldn't expect a C++ library to be
compatible with any other compiler than the one it was compiled with anyway.

Specific example of name mangling:

f% cat >foo.cc
int f(double x) { return 1; }
int f(int x) { return x; }
int f(char *x) { return 2; }
<EOF>
f% CC -c -o x1 foo.cc
f% nm x1
Index]   Value      Size    Type  Bind  Other Shndx   Name
[4]     |        16|      56|FUNC |GLOB |0    |2      |__1cBf6Fd_i_
[3]     |        88|      40|FUNC |GLOB |0    |2      |__1cBf6Fi_i_
[2]     |       144|      40|FUNC |GLOB |0    |2      |__1cBf6Fpc_i_
[1]     |         0|       0|FILE |LOCL |0    |ABS    |foo.cc
f% gcc -c -o x2 foo.cc
f% nm x2
[Index]   Value      Size    Type  Bind  Other Shndx   Name
[2]     |         0|       0|SECT |LOCL |0    |3      |
[5]     |         0|       0|SECT |LOCL |0    |2      |
[4]     |         0|       0|NOTY |LOCL |0    |3      |__FRAME_BEGIN__
[6]     |         0|      44|FUNC |GLOB |0    |2      |f__Fd
[7]     |        44|      32|FUNC |GLOB |0    |2      |f__Fi
[8]     |        76|      28|FUNC |GLOB |0    |2      |f__FPc
[1]     |         0|       0|FILE |LOCL |0    |ABS    |foo.cc
[3]     |         0|       0|NOTY |LOCL |0    |2      |gcc2_compiled.
f% rm x1 x2 foo.cc

Note that the names are mangled quite differently.



More information about the Squeak-dev mailing list