-->

Where did OSX's x86-64 assembly libc routines

2020-07-16 09:51发布

问题:

First, some useful links to OSX's Libc code:

  • Git: https://github.com/aosm/Libc.git (with tags for the different iterations of OSX)
  • HTML: http://www.opensource.apple.com/source/Libc/

There, one can see that Libc 825.40.1 (OSX 10.8.5) still has public asm implementations of functions like memcpy. Notably in x86_64/string/bcopy_sse42.s. However, since version 997.1.1 (OSX 10.9), most of them seem to be gone. A few are left in x86_64/string though. As can be seen here: http://www.opensource.apple.com/source/Libc/Libc-997.90.3/x86_64/string/.

Has the source been closed on the others? Looking at the diff between OSX 10.8 and 10.9 doesn't indicate a place where they may have moved inside of the source tree.

When debugging binaries running on OSX 10.9, it's hard to miss the references to _platform_memmove. Indeed, if we look at the source of bcopy.c, we see:

#include <platform/string.h>

void bcopy(const void *src, void *dst, size_t n) {
    _platform_memmove(dst, src, n);
}

So perhaps that could yield something useful. Yet for some reason I can't find (_)platform_memmove, either through lack of grepping prowess, or macro trickery. Can someone help me find it?

EDIT: I tried looking for platform/string.h, but just like that mailing list poster, I couldn't locate it within the source tree.

EDIT: Compiling a source file calling memcpy with Xcode's clang (near to 3.4) on OSX 10.9.4 and running it under Instruments shows that _platform_memmove$VARIANT$Nehalem is being called. Which leads me to believe that the specialized asm variants still exist somewhere.

EDIT: dumping libsystem.dylib doesn't give me the comments, but at least it gives me the assembly, there appear to be routines for:

  • Ivy Bridge (delegates to Nehalem)
  • Nehalem (chosen on my system, a 2011 Core i7)
  • Merom
  • SSE4.2 (presumably similar to the SSE 4.2 version found in older Libc's)
  • SSE3
  • SSE2
  • scalar
  • Unknown
标签: c macos libc