2

The C standard does not specify how compilers should generate the name of a C function inside an object file. It seems that GCC compatible front-ends simply prepend the name of the C function by an underscore. Microsoft compilers use a different strategy.

However, a lot of languages are able to call C functions (Rust, Go, etc). I assume that the developers had access to some document explaining how the C symbols are translated by the different compilers on the different operating systems.

Is there some publicly available website/document/RFC documenting this point for the different compilers (GCC, Visual C++, etc) or operating systems?

EDIT: On this page http://www.iecc.com/linker/linker05.html in the Name Mangling section, a brief history is given. On this post: What is the reason function names are prefixed with an underscore by the compiler?, we talk about a simple convention. Has this rule been ever written somwhere in some of the compilers' documentation?

yageek
  • 4,115
  • 3
  • 30
  • 48
  • What different Microsoft strategy do you mean? When compiling as C code, MS uses simple preceding underscores like everyone else. – Mark Benningfield Feb 25 '18 at 16:30
  • 5
    It's part of [the ***ABI***](https://en.wikipedia.org/wiki/Application_binary_interface). – Some programmer dude Feb 25 '18 at 16:31
  • @MarkBenningfield I read somewhere that MS uses the name uses an underscore prefix and on 32 bits architecture adds an `@` followed by the size of arguments in bytes. @some-programmer-dude, is there any explicit ABI document somewhere? – yageek Feb 25 '18 at 16:34
  • note/understand that one "brand" of compiler doesnt always do it the same way or historically has not, some have command line options to manipulate is there a leading underscore or not. When trying to mix and link languages you just have to do the work. and re-do the work if you change compilers/tools on either side. Or use assembly as your middle language to combine the two. – old_timer Feb 25 '18 at 16:34
  • Well, there you're talking about C++, not C. – Mark Benningfield Feb 25 '18 at 16:34
  • Nope, I speak about C not C++ mangling. – yageek Feb 25 '18 at 16:35
  • 1
    It is platform/compiler specific. You have to find the rules used in the platform. There is no standard source of the information. The standard doesn’t pontificate on the issue (nor should it). – Jonathan Leffler Feb 25 '18 at 16:39
  • Yes. Precisly! I wanted some help to find out those documents for some compilers. For GCC, I failed to find :( – yageek Feb 25 '18 at 16:40
  • @yageek: gcc is a *compiler* (more accurately, a collection of compilers) which produces code gor various platforms. You need to search for ABIs per platform. There are a couple of links at the end of the first section of [this answer](https://stackoverflow.com/questions/31325157/calling-c-function-which-takes-no-parameters-with-parameters/31325626). – rici Feb 25 '18 at 19:31
  • @rici Thanks for the link :) But I guess the API precises how the parameters are pushed on the stack and so on and does not precise how C compilers should mangle the name of the C function inside ELF object right? – yageek Feb 25 '18 at 19:49
  • The abi also defines names. So not right. – rici Feb 25 '18 at 20:10
  • I took a look on the mentioned documents and they does not seem to speak about mangling of C functions. :( – yageek Feb 25 '18 at 20:16
  • @yageek - Nowhere does the C standard say anything about ELF formats. C compilers are free to use [other formats](https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx) – Bo Persson Feb 25 '18 at 23:01

0 Answers0