0

I am a programmer using Java and C for a few years, recently I am reading the book Advanced C and C++ Compiling, from which I learned that some functions are invoked before the main is called, like the "_start", the "__libc_start_main". Those details must be explained and answered hundreds of time here by C experts.

But I noticed a very very tiny things that, with the common function invocation conventions in C like the cdecl, when we write a function, its name will be prefixed with an underscore '_' after compiled. That means if you have a function called foo, it will be compiled as _foo in the final assembly text. Inversely, if we found a section called _start in the assembly text, it should having a mapping function called "start" in C.

Am I right? If so, the "__libc_start_main" in the assembly text should have its function signature as "_libc_start_main" (one less underscore prefix) in C ?

080482d0 <_start>: 80482d0: 31 ed xor %ebp,%ebp 80482d2: 5e pop %esi 80482d3: 89 e1 mov %esp,%ecx 80482d5: 83 e4 f0 and $0xfffffff0,%esp 80482d8: 50 push %eax 80482d9: 54 push %esp 80482da: 52 push %edx 80482db: 68 50 84 04 08 push $0x8048450 80482e0: 68 e0 83 04 08 push $0x80483e0 80482e5: 51 push %ecx 80482e6: 56 push %esi 80482e7: 68 d0 83 04 08 push $0x80483d0 80482ec: e8 cf ff ff ff call 80482c0 <__libc_start_main@plt> 80482f1: f4 hlt 80482f2: 66 90 xchg %ax,%ax 

I know this is not right obviously because if you google it, hundreds of sites will show you that its signature is exactly same as it is marked and called in assembly. Can any C expert explain this?

int __libc_start_main( int (*main)(int, char **, char **), int argc, char **argv, int (*init)(int, char **, char **), void (*fini)(void), void (*ldso_fini)(void)) ; 
3
  • 2
    You don't mention your OS, but this looks like Linux, in which case no functions get implicit _s. Commented Aug 9, 2017 at 3:42
  • All functions or just those implemention-ralated functions ? Commented Aug 9, 2017 at 4:12
  • no functions... Commented Aug 9, 2017 at 4:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.