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 due to libc_do_syscall.S on thumb2.


Hi Joseph,

A "Segmentation fault" was encountered during profiling the C library
(libc) for thumb2.
Source : glibc-2.13.

The 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 on target:
{{{
#/tool/devel/usr/bin/gcc -pg hello.c -o hello.exe -static -lc_p
#./hello.exe
}}}

Investigation:
Investigation shows that the failure is in brk() syscall, in thumb
mode syscall are
done through a helper function libc_do_syscall(). This mechanism was
introduced to
Fix unwinding for Thumb-2 libraries by following patch, which is
present in glibc-2.13
* [http://sourceware.org/ml/libc-ports/2010-04/msg00001.html]


The exact reason for the failure is:
The problem is that ENTRY() implies CALL_MCOUNT. __libc_do_syscall
relies on passing an argument in IP.
The mcount call will clobber IP and hence a Segmentation fault.

Fix:
The best fix is probably to avoid the mcount call altogether for this function.
This is a magic internal helper routine, so having it show up on a
profile is somewhat unnecessary.

Similar bug has been reported on ubuntu eglibc, kindly refer the below link.
* [https://bugs.launchpad.net/gcc-linaro/+bug/605030]
The idea is taken from the above link.

The attached patch fixes this issue, I have tested it on Thumb2.

Kindly, review this patch and mainline it if no problems found.

Regards,
Manjunath S Matti.
Sony India Software Centre.
--- a/glibc-ports-2.13/sysdeps/unix/sysv/linux/arm/eabi/libc-do-syscall.S	2011-04-18 16:03:32.000000000 +0530
+++ b/glibc-ports-2.13/sysdeps/unix/sysv/linux/arm/eabi/libc-do-syscall.S	2011-04-18 16:03:42.000000000 +0530
@@ -29,6 +29,9 @@
 	.syntax unified
 	.hidden __libc_do_syscall
 
+#undef CALL_MCOUNT
+#define CALL_MCOUNT
+
 ENTRY (__libc_do_syscall)
 	.fnstart
 	push	{r7, lr}

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