Port-arm archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: thumb libc SIGILL from __libc_mutex_unlock (Re: thumb compilation)



If compile thread-stub.c without -mthumb, I get the next illegal instruction
from lib/libc/getopt.c:

(gdb) bt
#0  0x00008de8 in getopt ()
#1  0x00008bbc in main ()
(gdb) info registers
r0             0x2      2
r1             0x7fffee24       2147479076
r2             0x1f710  128784
r3             0x0      0
r4             0x8db4   36276
r5             0x7fffee24       2147479076
r6             0x1f710  128784
r7             0x2      2
r8             0x0      0
r9             0x0      0
r10            0x2af94  176020
r11            0x7fffee14       2147479060
r12            0x7fffed74       2147478900
sp             0x7fffedc0       2147478976
lr             0x8bbd   35773
pc             0x8de8   36328
fps            0x0      0
cpsr           0x10     16
(gdb) disassemble 0x00008de8
Dump of assembler code for function getopt:
0x00008db4 <getopt+0>:  undefined
0x00008db8 <getopt+4>:  strmib  r4, [r5], -lr, asr #12
0x00008dbc <getopt+8>:  strmi   r11, [r9], r0, ror #9
0x00008dc0 <getopt+12>: stmvsda r11, {r1, r2, r4, r6, r8, r11, lr}
0x00008dc4 <getopt+16>: ldrmi   r4, [r0], r2, lsl #13
0x00008dc8 <getopt+20>: teqle   r1, r0, lsl #22
0x00008dcc <getopt+24>: stmvsda r3!, {r2, r4, r6, r10, r11, lr}
0x00008dd0 <getopt+28>: bcs     0x26e40
0x00008dd4 <getopt+32>: mrcmi   0, 2, sp, cr3, cr13, {0}
0x00008dd8 <getopt+36>: eorvss  r3, r2, r1, lsl #6
0x00008df8 <getopt+68>: movwcs  r4, #2636       ; 0xa4c
0x00008dfc <getopt+72>: stmvsda r3!, {r0, r1, r4, sp, lr}
0x00008e00 <getopt+76>: blcs    0x26e74
0x00008e04 <getopt+80>: bmi     0x12bd26c
0x00008e08 <getopt+84>: movwcc  r6, #6163       ; 0x1813
0x00008e0c <getopt+88>: ands    r6, r3, r3, lsl r0
0x00008e10 <getopt+92>: stcmil  12, cr4, [r7, #-268]
0x00008e14 <getopt+96>: andvs   r2, r11, r0, lsl #6
0x00008e18 <getopt+100>:        strmib  r6, [r10], -r9, lsr #16
0x00008e1c <getopt+104>:        ldmplia r11, {r0, r1, r3, r7}
0x00008e20 <getopt+108>:        strmi   r6, [r10, #35]
0x00008e24 <getopt+112>:        ldmvcda pc, {r2, r8, r10, r11, r12, lr,pc}
0x00008e28 <getopt+116>:        eorvs   r1, r2, r10, asr r12
0x00008e2c <getopt+120>:        andle   r2, r11, sp, lsr #30
0x00008e30 <getopt+124>:        eorvs   r4, r3, r0, asr #22
0x00008e34 <getopt+128>:        rsbmis  r2, r6, #1048576        ;0x100000
0x00008e38 <getopt+132>:        ldclt   12, cr1, [r12], {48}
0x00008e3c <getopt+136>:        undefined
0x00008e40 <getopt+140>:        ldcltl  6, cr4, [r0], #648
0x00008e44 <getopt+144>:        strmi   r11, [r8, -r2, lsl #24]
0x00008e48 <getopt+148>:        mrcmi   8, 1, r7, cr6, cr8, {2}
0x00008e4c <getopt+152>:        eorvss  r1, r0, r3, asr r12

It appears that gdb is confused by the thumb code since objdump shows
quite different code:

$ obj/tooldir.Linux-2.6.18-6-686-unknown/bin/arm--netbsdelf-objdump -d
lib/libc/obj/getopt.o

lib/libc/obj/getopt.o:     file format elf32-littlearm

Disassembly of section .text:

00000000 <_getopt>:
   0:   b5f0            push    {r4, r5, r6, r7, lr}
   2:   4657            mov     r7, sl
   4:   464e            mov     r6, r9
   6:   4645            mov     r5, r8
   8:   b4e0            push    {r5, r6, r7}
   a:   4689            mov     r9, r1
   c:   4956            ldr     r1, [pc, #344]  (168 <_getopt+0x168>)
   e:   680b            ldr     r3, [r1, #0]
  10:   4682            mov     sl, r0
  12:   4690            mov     r8, r2
  14:   2b00            cmp     r3, #0
  16:   d121            bne     5c <_getopt+0x5c>
  18:   4c54            ldr     r4, [pc, #336]  (16c <_getopt+0x16c>)
  1a:   6823            ldr     r3, [r4, #0]
  1c:   781a            ldrb    r2, [r3, #0]
  1e:   2a00            cmp     r2, #0
  20:   d01d            beq     5e <_getopt+0x5e>
  22:   4e53            ldr     r6, [pc, #332]  (170 <_getopt+0x170>)
  24:   3301            add     r3, #1
  26:   6032            str     r2, [r6, #0]
  28:   6023            str     r3, [r4, #0]
  2a:   6836            ldr     r6, [r6, #0]
  2c:   2e3a            cmp     r6, #58
...

The cat binary shows the same with objdump with offsets matching that of
gdb:

00008db4 <_getopt>:
    8db4:       b5f0            push    {r4, r5, r6, r7, lr}
    8db6:       4657            mov     r7, sl
    8db8:       464e            mov     r6, r9
    8dba:       4645            mov     r5, r8
    8dbc:       b4e0            push    {r5, r6, r7}
    8dbe:       4689            mov     r9, r1
    8dc0:       4956            ldr     r1, [pc, #344]  (8f1c<_getopt+0x168>)
    8dc2:       680b            ldr     r3, [r1, #0]
    8dc4:       4682            mov     sl, r0
    8dc6:       4690            mov     r8, r2
    8dc8:       2b00            cmp     r3, #0
    8dca:       d121            bne     8e10 <_getopt+0x5c>
    8dcc:       4c54            ldr     r4, [pc, #336]  (8f20<_getopt+0x16c>)
    8dce:       6823            ldr     r3, [r4, #0]
    8dd0:       781a            ldrb    r2, [r3, #0]
    8dd2:       2a00            cmp     r2, #0
    8dd4:       d01d            beq     8e12 <_getopt+0x5e>
    8dd6:       4e53            ldr     r6, [pc, #332]  (8f24<_getopt+0x170>)
    8dd8:       3301            add     r3, #1
    8dda:       6032            str     r2, [r6, #0]
    8ddc:       6023            str     r3, [r4, #0]
    8dde:       6836            ldr     r6, [r6, #0]
    8de0:       2e3a            cmp     r6, #58
...

The push instruction appears valid, so am I hitting some alignment
issue?

getopt.c was compiled into libc with:

#   compile  libc/getopt.o
/home/mira/src/netbsd/matt-armv6/src/obj/tooldir.Linux-2.6.18-6-686-unknown/bin/arm--netbsdelf-gcc
-O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
-Wno-sign-compare -Wno-traditional -Wreturn-type -Wswitch -Wshadow
-Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter
-std=gnu99  -Werror -mlong-calls -mthumb -mthumb-interwork   -D_LIBC
-D_REENTRANT -DNLS
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/include
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc -DSOFTFLOAT
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/arch/arm/softfloat
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/softfloat
-DSOFTFLOAT_FOR_GCC -I/home/mira/src/netbsd/matt-armv6/src/sys
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/compat/stdlib
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/compat/../stdlib
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/../../common/lib/libc/quad
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/../../common/lib/libc/string
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/../../common/lib/libc/arch/arm/string
-D__DBINTERFACE_PRIVATE -DI18NMODULE_MAJOR=4 -DCITRUS
-I/home/mira/src/netbsd/matt-armv6/src/libexec/ld.elf_so
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/dlfcn
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/gdtoa -DNO_FENV_H
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/arch/arm/gdtoa
-DCITRUS_ICONV -DWITH_RUNE
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc -DPOSIX_MISTAKE
-DCOMPAT__RES -DUSE_POLL -DPORTMAP -DWIDE_DOUBLE -DALL_STATE
-DUSG_COMPAT  -D_FORTIFY_SOURCE=2  -nostdinc -isystem
/home/mira/rootfs/usr/include -c
/home/mira/src/netbsd/matt-armv6/src/lib/libc/stdlib/getopt.c 
-o getopt.o
/home/mira/src/netbsd/matt-armv6/src/obj/tooldir.Linux-2.6.18-6-686-unknown/bin/arm--netbsdelf-objcopy
-x getopt.o
#   compile  libc/getopt.so
/home/mira/src/netbsd/matt-armv6/src/obj/tooldir.Linux-2.6.18-6-686-unknown/bin/arm--netbsdelf-gcc
-O2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
-Wno-sign-compare -Wno-traditional -Wreturn-type -Wswitch -Wshadow
-Wcast-qual -Wwrite-strings -Wextra -Wno-unused-parameter
-std=gnu99  -Werror -mlong-calls -mthumb -mthumb-interwork   -D_LIBC
-D_REENTRANT -DNLS
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/include
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc -DSOFTFLOAT
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/arch/arm/softfloat
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/softfloat
-DSOFTFLOAT_FOR_GCC -I/home/mira/src/netbsd/matt-armv6/src/sys
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/compat/stdlib
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/compat/../stdlib
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/../../common/lib/libc/quad
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/../../common/lib/libc/string
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/../../common/lib/libc/arch/arm/string
-D__DBINTERFACE_PRIVATE -DI18NMODULE_MAJOR=4 -DCITRUS
-I/home/mira/src/netbsd/matt-armv6/src/libexec/ld.elf_so
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/dlfcn
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/gdtoa -DNO_FENV_H
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc/arch/arm/gdtoa
-DCITRUS_ICONV -DWITH_RUNE
-I/home/mira/src/netbsd/matt-armv6/src/lib/libc -DPOSIX_MISTAKE
-DCOMPAT__RES -DUSE_POLL -DPORTMAP -DWIDE_DOUBLE -DALL_STATE
-DUSG_COMPAT  -D_FORTIFY_SOURCE=2  -nostdinc -isystem
/home/mira/rootfs/usr/include -c    -D_I18N_DYNAMIC -fPIC -DPIC
/home/mira/src/netbsd/matt-armv6/src/lib/libc/stdlib/getopt.c -o
getopt.so
/home/mira/src/netbsd/matt-armv6/src/obj/tooldir.Linux-2.6.18-6-686-unknown/bin/arm--netbsdelf-objcopy
-x getopt.so
...

Target is TI's OMAP 2420 board. Just for reference, libc is compiled
by overriding CPUFLAGS on a per file basis with a -mthumb default:

$ CPUFLAGS_thread_stub=-mthumb-interwork CPUFLAGS_lock=-mthumb-interwork
CPUFLAGS_stackptr=-mthumb-interwork
CPUFLAGS_abortfixup=-mthumb-interwork
CPUFLAGS_srtbegin=-mthumb-interwork
CPUFLAGS_wstring_inst=-mthumb-interwork
CPUFLAGS_wlocale_inst=-mthumb-interwork CPUFLAGS_vec=-mthumb-interwork
CPUFLAGS_valarray_inst=-mthumb-interwork
CPUFLAGS_strstream=-mthumb-interwork
CPUFLAGS_string_inst=-mthumb-interwork
CPUFLAGS_sstream_inst=-mthumb-interwork
CPUFLAGS_ostream_inst=-mthumb-interwork
CPUFLAGS_localename=-mthumb-interwork
CPUFLAGS_locale_inst=-mthumb-interwork
CPUFLAGS_istream=-mthumb-interwork
CPUFLAGS_istream_inst=-mthumb-interwork
CPUFLAGS_fstream_inst=-mthumb-interwork
CPUFLAGS_ext_inst=-mthumb-interwork
CPUFLAGS_eh_personality=-mthumb-interwork
CPUFLAGS_pthread_lock=-mthumb-interwork
CPUFLAGS__context_u=-mthumb-interwork CPUFLAGS_ui=-mthumb-interwork
CPUFLAGS_tests=-mthumb-interwork CPUFLAGS_sanity=-mthumb-interwork
CPUFLAGS_fs=-mthumb-interwork CPUFLAGS_formats=-mthumb-interwork
CPUFLAGS_exceptions=-mthumb-interwork CPUFLAGS_config=-mthumb-interwork
CPUFLAGS_atffile=-mthumb-interwork
CPUFLAGS_application=-mthumb-interwork CPUFLAGS_mcount=-mthumb-interwork
CPUFLAGS_crtn=-mthumb-interwork CPUFLAGS_crti=-mthumb-interwork
CPUFLAGS_atomic_init_testset=-mthumb-interwork
DEF_CPUFLAGS='-mlong-calls -mthumb -mthumb-interwork'
CPUFLAGS='${CPUFLAGS_${.IMPSRC:S/-/_/g:T:R}:U${DEF_CPUFLAGS}}'
MKPOSTFIX=no MKISCSI=no MKPROFILE=no  MKLINT=no USE_HESIOD=no
MKHESIOD=no USE_YP=no MKYP=no USE_INET6=no MKINET6=no USE_KERBEROS=no
MKKERBEROS=no USE_PAM=no MKPAM=no USE_SKEY=no MKSKEY=no MKIPFILTER=no
MKPF=no MKCVS=no MKBFD=no MKGCCCMDS=no USE_SSP=no
../../obj/tooldir.Linux-2.6.18-6-686-unknown/bin/nbmake-evbarm

Flagging getopt to compile with -mthumb-interwork only is may work, but
I'd rather understand why it's producing another SIGILL.

-Mikko


Home | Main Index | Thread Index | Old Index