ARM GCC rename static functions?
Pan ruochen
panruochen@gmail.com
Mon Jun 27 15:59:00 GMT 2011
Hi All,
I found ARM GCC renamed some of static functions.
Here is my test code:
$cat 1.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ucontext.h>
static void my_signal_handler(int signum, siginfo_t* siginfo,
ucontext_t *lpContext)
{
mcontext_t *mc = &lpContext->uc_mcontext;
fprintf(stderr, "[CORE]: Catch exception at 0x%x\n", mc->arm_pc);
}
static int register_signal_handler(int sig, void *handler)
{
int ret = -EINVAL;
sigset_t signal_set;
if (sigemptyset(&signal_set) >= 0) {
struct sigaction sa = {
.sa_handler = handler,
.sa_mask = signal_set,
.sa_flags = SA_SIGINFO,
.sa_restorer = NULL
};
ret = sigaction(sig, &sa, NULL);
if( ret < 0 )
fprintf(stderr, "failed to install signal hander.\n");
}
return ret;
}
int main()
{
register_signal_handler(SIGSEGV,my_signal_handler);
register_signal_handler(SIGILL, my_signal_handler);
register_signal_handler(SIGBUS, my_signal_handler);
return 0;
}
Then I did:
$arm-none-linux-gnueabi-gcc -O2 1.c
$arm-none-linux-gnueabi-objdump -dr -j .text a.out
a.out: file format elf32-littlearm
Disassembly of section .text:
000084a4 <_start>:
84a4: e3a0b000 mov fp, #0
84a8: e3a0e000 mov lr, #0
84ac: e49d1004 pop {r1} ; (ldr r1, [sp], #4)
84b0: e1a0200d mov r2, sp
84b4: e52d2004 push {r2} ; (str r2, [sp, #-4]!)
84b8: e52d0004 push {r0} ; (str r0, [sp, #-4]!)
84bc: e59fc010 ldr ip, [pc, #16] ; 84d4 <_start+0x30>
84c0: e52dc004 push {ip} ; (str ip, [sp, #-4]!)
84c4: e59f000c ldr r0, [pc, #12] ; 84d8 <_start+0x34>
84c8: e59f300c ldr r3, [pc, #12] ; 84dc <_start+0x38>
84cc: ebffffdf bl 8450 <_init+0x38>
84d0: ebffffdb bl 8444 <_init+0x2c>
84d4: 00008634 .word 0x00008634
84d8: 00008610 .word 0x00008610
84dc: 00008638 .word 0x00008638
000084e0 <call_gmon_start>:
84e0: e59f3014 ldr r3, [pc, #20] ; 84fc <call_gmon_start+0x1c>
84e4: e59f0014 ldr r0, [pc, #20] ; 8500 <call_gmon_start+0x20>
84e8: e08f3003 add r3, pc, r3
84ec: e7932000 ldr r2, [r3, r0]
84f0: e3520000 cmp r2, #0
84f4: 012fff1e bxeq lr
84f8: eaffffd7 b 845c <_init+0x44>
84fc: 000083c8 .word 0x000083c8
8500: 00000030 .word 0x00000030
00008504 <__do_global_dtors_aux>:
8504: e59f3010 ldr r3, [pc, #16] ; 851c <__do_global_dtors_aux+0x18>
8508: e5d32000 ldrb r2, [r3]
850c: e3520000 cmp r2, #0
8510: 03a02001 moveq r2, #1
8514: 05c32000 strbeq r2, [r3]
8518: e12fff1e bx lr
851c: 000108fc .word 0x000108fc
00008520 <frame_dummy>:
8520: e59f0020 ldr r0, [pc, #32] ; 8548 <frame_dummy+0x28>
8524: e92d4008 push {r3, lr}
8528: e5903000 ldr r3, [r0]
852c: e3530000 cmp r3, #0
8530: 08bd8008 popeq {r3, pc}
8534: e59f3010 ldr r3, [pc, #16] ; 854c <frame_dummy+0x2c>
8538: e3530000 cmp r3, #0
853c: 08bd8008 popeq {r3, pc}
8540: e12fff33 blx r3
8544: e8bd8008 pop {r3, pc}
8548: 000107c4 .word 0x000107c4
854c: 00000000 .word 0x00000000
00008550 <my_signal_handler>:
8550: e59f300c ldr r3, [pc, #12] ; 8564 <my_signal_handler+0x14>
8554: e592205c ldr r2, [r2, #92] ; 0x5c
8558: e5930000 ldr r0, [r3]
855c: e59f1004 ldr r1, [pc, #4] ; 8568 <my_signal_handler+0x18>
8560: eaffffc9 b 848c <_init+0x74>
8564: 000108f8 .word 0x000108f8
8568: 00008710 .word 0x00008710
0000856c <T.25>:
856c: e92d4070 push {r4, r5, r6, lr}
8570: e24dde11 sub sp, sp, #272 ; 0x110
8574: e28d4090 add r4, sp, #144 ; 0x90
8578: e1a06000 mov r6, r0
857c: e1a00004 mov r0, r4
8580: ebffffac bl 8438 <_init+0x20>
8584: e3500000 cmp r0, #0
8588: b3e04015 mvnlt r4, #21
858c: ba000012 blt 85dc <T.25+0x70>
8590: e28d5004 add r5, sp, #4
8594: e3a01000 mov r1, #0
8598: e3a0208c mov r2, #140 ; 0x8c
859c: e1a00005 mov r0, r5
85a0: ebffffb0 bl 8468 <_init+0x50>
85a4: e1a01004 mov r1, r4
85a8: e3a02080 mov r2, #128 ; 0x80
85ac: e59f4050 ldr r4, [pc, #80] ; 8604 <T.25+0x98>
85b0: e28d0008 add r0, sp, #8
85b4: e58d4004 str r4, [sp, #4]
85b8: ebffffad bl 8474 <_init+0x5c>
85bc: e3a03004 mov r3, #4
85c0: e1a00006 mov r0, r6
85c4: e1a01005 mov r1, r5
85c8: e3a02000 mov r2, #0
85cc: e58d3088 str r3, [sp, #136] ; 0x88
85d0: ebffffb0 bl 8498 <_init+0x80>
85d4: e2504000 subs r4, r0, #0
85d8: ba000002 blt 85e8 <T.25+0x7c>
85dc: e1a00004 mov r0, r4
85e0: e28dde11 add sp, sp, #272 ; 0x110
85e4: e8bd8070 pop {r4, r5, r6, pc}
85e8: e59f1018 ldr r1, [pc, #24] ; 8608 <T.25+0x9c>
85ec: e3a02021 mov r2, #33 ; 0x21
85f0: e5913000 ldr r3, [r1]
85f4: e59f0010 ldr r0, [pc, #16] ; 860c <T.25+0xa0>
85f8: e3a01001 mov r1, #1
85fc: ebffff9f bl 8480 <_init+0x68>
8600: eafffff5 b 85dc <T.25+0x70>
8604: 00008550 .word 0x00008550
8608: 000108f8 .word 0x000108f8
860c: 00008734 .word 0x00008734
00008610 <main>:
8610: e92d4008 push {r3, lr}
8614: e3a0000b mov r0, #11
8618: ebffffd3 bl 856c <T.25>
861c: e3a00004 mov r0, #4
8620: ebffffd1 bl 856c <T.25>
8624: e3a00007 mov r0, #7
8628: ebffffcf bl 856c <T.25>
862c: e3a00000 mov r0, #0
8630: e8bd8008 pop {r3, pc}
00008634 <__libc_csu_fini>:
8634: e12fff1e bx lr
00008638 <__libc_csu_init>:
8638: e92d47f0 push {r4, r5, r6, r7, r8, r9, sl, lr}
863c: e1a08000 mov r8, r0
8640: e1a07001 mov r7, r1
8644: e1a06002 mov r6, r2
8648: ebffff72 bl 8418 <_init>
864c: e59f30a4 ldr r3, [pc, #164] ; 86f8 <__libc_csu_init+0xc0>
8650: e59f00a4 ldr r0, [pc, #164] ; 86fc <__libc_csu_init+0xc4>
8654: e59fa0a4 ldr sl, [pc, #164] ; 8700 <__libc_csu_init+0xc8>
8658: e0639000 rsb r9, r3, r0
865c: e08fa00a add sl, pc, sl
8660: e1b09149 asrs r9, r9, #2
8664: e08aa003 add sl, sl, r3
8668: 08bd87f0 popeq {r4, r5, r6, r7, r8, r9, sl, pc}
866c: e3a04001 mov r4, #1
8670: e1a00008 mov r0, r8
8674: e1a01007 mov r1, r7
8678: e1a02006 mov r2, r6
867c: e2495001 sub r5, r9, #1
8680: e1a0e00f mov lr, pc
8684: e59af000 ldr pc, [sl]
8688: e1540009 cmp r4, r9
868c: e0055004 and r5, r5, r4
8690: 28bd87f0 popcs {r4, r5, r6, r7, r8, r9, sl, pc}
8694: e3550000 cmp r5, #0
8698: 0a000007 beq 86bc <__libc_csu_init+0x84>
869c: e1a00008 mov r0, r8
86a0: e1a01007 mov r1, r7
86a4: e1a02006 mov r2, r6
86a8: e3a04002 mov r4, #2
86ac: e1a0e00f mov lr, pc
86b0: e59af004 ldr pc, [sl, #4]
86b4: e1540009 cmp r4, r9
86b8: 28bd87f0 popcs {r4, r5, r6, r7, r8, r9, sl, pc}
86bc: e2845001 add r5, r4, #1
86c0: e1a00008 mov r0, r8
86c4: e1a01007 mov r1, r7
86c8: e1a02006 mov r2, r6
86cc: e1a0e00f mov lr, pc
86d0: e79af104 ldr pc, [sl, r4, lsl #2]
86d4: e2854001 add r4, r5, #1
86d8: e1a00008 mov r0, r8
86dc: e1a01007 mov r1, r7
86e0: e1a02006 mov r2, r6
86e4: e1a0e00f mov lr, pc
86e8: e79af105 ldr pc, [sl, r5, lsl #2]
86ec: e1540009 cmp r4, r9
86f0: 3afffff1 bcc 86bc <__libc_csu_init+0x84>
86f4: e8bd87f0 pop {r4, r5, r6, r7, r8, r9, sl, pc}
86f8: ffffff04 .word 0xffffff04
86fc: ffffff08 .word 0xffffff08
8700: 00008254 .word 0x00008254
The ARM GCC renames the static function name from register_signal_handler to
T.25, which will bring extra confusions in reading the unassembly code.
Why does gcc do these renaming stuff?
--
Best Regards,
Pan Ruochen
More information about the Gcc-help
mailing list