3

I would expect to be able to statically link against a build of libc with debug symbols, then run my program through lldb.

otool -L <my binary>

makes it look like the only dynamically linked library (dll) is:

/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

Which I would guess is the libc dll is (though nm doesn't list everything I'd expect in libc). Maybe just some kind of stub loader.

In /usr/lib/ it seems that Apple does not supply a debug build of libSystem.

How do you debug libc on OSX (10.11.3)?

Possible duplicate of: On Mac OS X, how can you get a debug build of System/LibC for source level debugging?

Nick Desaulniers
  • 2,046
  • 3
  • 25
  • 47

1 Answers1

2

I'm having a hard time following your question, but there are certain points to be made which I think will cover what you're asking:

otool -L will show all dylibs that you are linking against.

/usr/lib/libSystem.B.dylib is an umbrella library that re-exports multiple dylibs, including libc (/usr/lib/system/libsystem_c.dylib). If you want to see what symbols are part of the system's C runtime, you will want to use nm on that dylib, not libSystem.

If you are statically linking in your own libc, then it won't show up in 'otool -L' because it's a static library and is thus part of your executable.

If you staticy linked your own libc into your executable, then using nm on your binary will possibly not show all the symbols you are expecting because the linker will optimize away dead code that is not needed by your executable. You can ensure that everything is added by using the -force_load option to ld. Check out the ld man page for more details on that.

Jeremy Huddleston Sequoia
  • 22,938
  • 5
  • 78
  • 86
  • Thanks for the info on the odd libSystem.B.dylib. I was more curious whether the only way to debug the libc was to download+compile+statically link to it from the Apple open source code drops (that are one release behind, so you probably won't be able to get the source to your current version of OSX). – Nick Desaulniers Mar 05 '16 at 06:54
  • What do you need to debug inside of Libc? Ideally, you should be able to tread it as a black box that "just works" ... if you think there are bugs inside of Libc, please file a radar at http://bugreport.apple.com – Jeremy Huddleston Sequoia Mar 06 '16 at 00:26
  • 2
    I'm trying to teach myself assembly by reverse engineering what libc is doing. – Nick Desaulniers Mar 06 '16 at 08:21