Search code examples
cgccname-mangling

why the Name mangling not happens?


extern int test();
int main()
{
    return test();
}

I build the code by gcc -c -o test.o test.c, and I find there is no name mangling when I run nm test.o. nm outputs test but not _test.

My environment is ubuntu 16.04 gcc 5.4.0


Solution

  • You seem to be expecting global symbols to have an underscore prepended to them. This is something that isn't done in ELF which is the object format that linux uses. Older binary formats like a.out or coff required that, ELF doesn't.

    Btw. the term "mangling" is usually used for C++ symbol mangling which is a different thing.