Loading...
--- Libc/Libc-391/gen/stack_logging.c
+++ Libc/Libc-391.5.22/gen/stack_logging.c
@@ -57,9 +57,17 @@
/*************** Recording stack ***********/
-static void *first_frame_address(void) {
-#if defined(__i386__)
- return __builtin_frame_address(1);
+// The three functions below are marked as noinline to ensure consistent inlining across
+// all versions of GCC and all compiler flags. The malloc stack logging code expects
+// these functions to not be inlined.
+// For details, see <rdar://problem/4199620>.
+//
+// The performance cost of not inlining these functions is negligible, and they're only
+// called when MallocStackLogging is set anyway, so they won't affect normal usage.
+
+static __attribute__((noinline)) void *first_frame_address(void) {
+#if defined(__i386__) || defined(__x86_64__)
+ return __builtin_frame_address(0);
#elif defined(__ppc__) || defined(__ppc64__)
void *addr;
#warning __builtin_frame_address IS BROKEN IN BEAKER: RADAR #2340421
@@ -71,10 +79,10 @@
#endif
}
-static void *next_frame_address(void *addr) {
+static __attribute__((noinline)) void *next_frame_address(void *addr) {
void *ret;
-#if defined(__MACH__) && defined(__i386__)
- __asm__ volatile("movl (%1),%0" : "=r" (ret) : "r" (addr));
+#if defined(__MACH__) && (defined(__i386__) || defined(__x86_64__))
+ __asm__ volatile("mov (%1),%0" : "=r" (ret) : "r" (addr));
#elif defined(__MACH__) && (defined(__ppc__) || defined(__ppc64__))
__asm__ volatile("lwz %0,0x0(%1)" : "=r" (ret) : "b" (addr));
#elif defined(__hpux__)
@@ -88,7 +96,7 @@
return ret;
}
-#if defined(__i386__) || defined (__m68k__)
+#if defined(__i386__) || defined(__x86_64__) || defined (__m68k__)
#define FP_LINK_OFFSET 1
#elif defined(__ppc__) || defined(__ppc64__)
#define FP_LINK_OFFSET 2
@@ -100,7 +108,7 @@
#error ********** Unimplemented architecture
#endif
-void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) {
+__attribute__((noinline)) void thread_stack_pcs(vm_address_t *buffer, unsigned max, unsigned *nb) {
void *addr;
addr = first_frame_address();
*nb = 0;