Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "_dyld_start" mean in my profiling results?

I am profiling some C++ code with callgrind. This is my first time doing so. I am finding that the highest level function (the one which I assume is calling all the shots to start the program running) is called _dyld_start. I am wondering what exactly this is.

Also, on some of my programs that take a long time to run, my main() function takes up about 99% of the time of all the functions being called by _dyld_start; however, on my program that takes a shorter time to run (about half a second) I find that main() is only taking about 85% of _dyld_start's time, the rest is going to dyldbootstrap::start(). I assume that that is a function associated with starting a C++ program. Is it reasonable for it to be taking 85% of _dyld_start's run time?

I am compiling my code using the C++11 standard. I am compiling on my OS/X so I am using clang. My valgrind version is 3.10.0.

like image 633
NeutronStar Avatar asked Jan 13 '15 03:01

NeutronStar


1 Answers

Joshua, any function higher main is part of C run-time support (in wide sense); and if the name of such functions include "ld" or "dyld" - they are part of dynamic linker.

OSX have no support for statically linked applications (https://stackoverflow.com/a/5259427/196561), so every executable file can't be loaded without needed shared libraries. The dynamic linker loads your executable file, parses it for needed shared libraries and loads them. Then linker should link library and executable together (by filling/editing some in-memory tables) and only then it can transfer control to the _start CRT entry point and then to main.

"Executing Mach-O Files", https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/executing_files.html

A Mach-O executable file contains a header consisting of a set of load commands. For programs that use shared libraries or frameworks, one of these commands specifies the location of the linker to be used to load the program. If you use Xcode, this is always /usr/lib/dyld, the standard OS X dynamic linker.

Dyld man (lists some debugging variables to debug dyld work): https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/dyld.1.html

Post about dyld: https://www.mikeash.com/pyblog/friday-qa-2012-11-09-dyld-dynamic-linking-on-os-x.html 2012-11-09: dyld: Dynamic Linking On OS X by Gwynne Raskind ("What does dyld do, anyway?")

like image 127
osgx Avatar answered Sep 26 '22 15:09

osgx