pythonic
pythonic

Reputation: 21675

Which function in glibc calls the main function

I am trying to understand how Linux launches a program. I read somewhere that some function in glibc calls the main function. Profiling with callgrind and looking at the call-graphs in Kcachegrind, I see below main which calls main. But I don't understand this, a function can't be named such. So my question is which function in the glibc actually starts the main function.

Upvotes: 8

Views: 1183

Answers (1)

Claudio
Claudio

Reputation: 2217

Following valgrind's own help you'll find this explanation for the option --show-below-main:

By default, stack traces for errors do not show any functions that appear beneath main because most of the time it's uninteresting C library stuff and/or gobbledygook. Alternatively, if main is not present in the stack trace, stack traces will not show any functions below main-like functions such as glibc's __libc_start_main. Furthermore, if main-like functions are present in the trace, they are normalised as (below main), in order to make the output more deterministic.

As such, below main is not the function which calls main itself, but __libc_start_main.

Upvotes: 11

Related Questions