This is the mail archive of the libc-ports@sources.redhat.com mailing list for the libc-ports project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix the glibc profiling issue on arm-unknown-linux-gnueabi.


Hello

I noticed that gprof (-pg option) on arm-unknown-linux-gnueabi is broken,
if one would like to profile the library functions. This distribution is built
using the following sources:

binutils: 2.20.51.0.11
gcc: 4.5.1
glibc, glibc-ports: 2.11.2

Here, --enable-profile option is passed while building glibc.

Using our earlier distribution, library function profiling was possible.
This distribution was built using the following sources:
binutils: 2.19.51
gcc: 4.3.3
glibc, glibc-ports: 2.9

I am aware that the reason is the new implementation "__gnu_mcount_nc".

The legacy _mcount implementation assumes r11 points to a 4-word APCS frame.
This is generally not true for EABI targets, particularly not in Thumb mode.

Since gcc 4.4.x the name and calling convention for function profiling
on ARM changed. The new implementation __gnu_mcount_nc with an ABI that
doesn't require the compiler to generate old APCS frames. The "nc" comes
from the fact that we do not need to pass mcount the location of a counter.

This new EABI-compatible profiling interface for EABI targets, requires a
function __gnu_mcount_nc, which is provided by GNU libc versions 2.8
and later.


testcase


#include <stdio.h>

void hello(int i)
{
    printf("Hello World! %d\n", i);
}

int main(void)
{
    int i;
    for (i = 0; i < 10000; i ++) {
        hello(i);
    }
}

command line option
# gcc -pg hello.c -o hello.exe -static -lc_p
# ./hello.exe

Error: Segmentation Fault.

On investigation it was found that some glibc functions such as read, write,
open, uname still had the hook "_mcount" for function profiling.

Solution :
1. Make the library insert the new profiling hook "__gnu_mcount_nc"
2. Stop the poping of LR register after the execution returns from the
profiling function, as the new implementation __gnu_mcount_nc restores
the original LR value before returning.

The following patch fixes this issue for both ARMv7 and thumb2, this has been
tested.

{{{
--- a/glibc-ports-2.11/sysdeps/arm/sysdep.h     2011-01-17
19:15:26.000000000 +0530
+++ b/glibc-ports-2.11/sysdeps/arm/sysdep.h     2011-01-17
19:23:40.000000000 +0530
@@ -89,10 +89,16 @@

 /* If compiled for profiling, call `mcount' at the start of each function.  */
 #ifdef PROF
+# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#define CALL_MCOUNT                    \
+       str     lr,[sp, #-4]!   ;       \
+       bl      PLTJMP(mcount)  ;
+# else
 #define CALL_MCOUNT                    \
        str     lr,[sp, #-4]!   ;       \
        bl      PLTJMP(mcount)  ;       \
        ldr     lr, [sp], #4    ;
+# endif
 #else
 #define CALL_MCOUNT            /* Do nothing.  */
 #endif
@@ -102,8 +108,12 @@
    on this system, the asm identifier `syscall_error' intrudes on the
    C name space.  Make sure we use an innocuous name.  */
 #define        syscall_error   __syscall_error
+# if (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+#define mcount         __gnu_mcount_nc
+# else
 #define mcount         _mcount
 #endif
+#endif

 #if defined(__ARM_EABI__)
 /* Tag_ABI_align8_preserved: This code preserves 8-byte
}}}

Since this is my first patch to the mailing list kindly review and
help me mainline
this patch.


Regards,
Manjunath S Matti
Sony India Software Centre.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]