bugTiny C Compiler - Bugs: bug #42021, Tinycc on arm do not generate...

 
 

bug #42021: Tinycc on arm do not generate working code

Submitted by:  Domingo Alvarez Duarte <mingodad>
Submitted on:  Tue 01 Apr 2014 04:31:00 PM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: None
Open/Closed: Open

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

(Jump to the original submission Jump to the original submission)

Wed 02 Apr 2014 01:08:35 PM UTC, comment #6:

It seems that valgrind is not that much usable on arm, then I tried also gdb and get several messages like this debugging test-query-tcc:


Breakpoint 1697, main () at test-query.c:44
44 int main() {
#0 main () at test-query.c:44

Breakpoint 138, sqlite3_open_v2 () at src/sqlite3.c:57185
57185 szLeft -= szCell[r] + 2;
#0 sqlite3_open_v2 () at src/sqlite3.c:57185
#1 0xbefff610 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? sqlite3_open_v2 ()
Breakpoint 564, openDatabase () at src/sqlite3.c:56907
56907 int leafData; /* True if pPage is a leaf of a LEAFDATA tree */
#0 openDatabase () at src/sqlite3.c:56907
#1 0xb6ffb488 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? openDatabase ()
Breakpoint 117, sqlite3_initialize () at src/sqlite3.c:54636
54636 ** list, *pPgnoNext is set to zero.
#0 sqlite3_initialize () at src/sqlite3.c:54636
#1 0x00000000 in ?? ()

?? sqlite3_initialize ()
Breakpoint 1088, sqlite3MutexInit () at src/sqlite3.c:18213
18213 SQLITE_PRIVATE int sqlite3MutexInit(void){
#0 sqlite3MutexInit () at src/sqlite3.c:18213
#1 0x00000000 in ?? ()

?? sqlite3MutexInit ()
Breakpoint 903, sqlite3DefaultMutex () at src/sqlite3.c:18892
18892 return &sMutex;
#0 sqlite3DefaultMutex () at src/sqlite3.c:18892
#1 0x0000e260 in sqlite3MutexInit () at src/sqlite3.c:18225

sqlite3MutexInit sqlite3DefaultMutex ()
Breakpoint 650, pthreadMutexInit () at src/sqlite3.c:18628
18628 static int pthreadMutexInit(void){ return SQLITE_OK; }
#0 pthreadMutexInit () at src/sqlite3.c:18628
#1 0x0000e2c8 in sqlite3MutexInit () at src/sqlite3.c:18234

sqlite3MutexInit pthreadMutexInit ()
Breakpoint 1086, sqlite3MutexAlloc () at src/sqlite3.c:18271
18271 if( !sqlite3GlobalConfig.bCoreMutex ){
#0 sqlite3MutexAlloc () at src/sqlite3.c:18271
#1 0xbefff588 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? sqlite3MutexAlloc ()
Breakpoint 646, pthreadMutexAlloc () at src/sqlite3.c:18683
18683 switch( iType ){
#0 pthreadMutexAlloc () at src/sqlite3.c:18683
#1 0xbefff638 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? pthreadMutexAlloc ()
Breakpoint 131, sqlite3_mutex_enter () at src/sqlite3.c:18292
18292 if( p ){
#0 sqlite3_mutex_enter () at src/sqlite3.c:18292
#1 0xbefff588 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? sqlite3_mutex_enter ()
Breakpoint 648, pthreadMutexEnter () at src/sqlite3.c:18780
18780 pthread_mutex_lock(&p->mutex);
#0 pthreadMutexEnter () at src/sqlite3.c:18780
#1 0xbefff570 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? pthreadMutexEnter ()
Breakpoint 1064, sqlite3MallocInit () at src/sqlite3.c:19399
19399 if( sqlite3GlobalConfig.m.xMalloc==0 ){
#0 sqlite3MallocInit () at src/sqlite3.c:19399
#1 0x000c460c in sqlite3Config ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

sqlite3Config sqlite3MallocInit ()
Breakpoint 1078, sqlite3MemSetDefault () at src/sqlite3.c:16379
16379 sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
#0 sqlite3MemSetDefault () at src/sqlite3.c:16379
#1 0xbefff568 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? sqlite3MemSetDefault ()
Breakpoint 80, sqlite3_config () at src/sqlite3.c:54820
54820 if( pCur->isIncrblobHandle && !pCur->aOverflow ){
#0 sqlite3_config () at src/sqlite3.c:54820
#1 0xb6eeb608 in ?? () from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? sqlite3_config ()
Breakpoint 1086, sqlite3MutexAlloc () at src/sqlite3.c:18271
18271 if( !sqlite3GlobalConfig.bCoreMutex ){
#0 sqlite3MutexAlloc () at src/sqlite3.c:18271
#1 0xbefff568 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

?? sqlite3MutexAlloc ()
Breakpoint 646, pthreadMutexAlloc () at src/sqlite3.c:18683
18683 switch( iType ){
#0 pthreadMutexAlloc () at src/sqlite3.c:18683

Domingo Alvarez Duarte <mingodad>
Tue 01 Apr 2014 07:42:40 PM UTC, comment #5:

Here is a small program with only sqlite3Strlen30 function:

------
tcc -g -O0 -o strlen30-tcc strlen30.c
tcc -g -O0 -o strlen30-tcc.o -c strlen30.c
objdump -Dxls strlen30-tcc.o > strlen30-tcc.o.asm
gcc -g -O0 -o strlen30-gcc strlen30.c
gcc -g -O0 -o strlen30-gcc.o -c strlen30.c
objdump -Dxls strlen30-gcc.o > strlen30-gcc.o.asm

valgrind --tool=memcheck ./strlen30-gcc
valgrind --tool=memcheck ./strlen30-tcc

------
#include <stdio.h>

/*

    • Compute a string length that is limited to what can be stored in
    • lower 30 bits of a 32-bit signed integer.

**

    • The value returned will never be negative. Nor will it ever be greater
    • than the actual length of the string. For very long strings (greater
    • than 1GiB) the value returned might be less than the true string length.

*/
static int sqlite3Strlen30(const char *z){
const char *z2 = z;
if( z==0 ) return 0;
while( *z2 ){ z2++; } //<<<<<<<<<<<<<<<<< line 14
return 0x3fffffff & (int)(z2 - z);
}

int main(int argc, char *argv[]) {
printf("%d\n", sqlite3Strlen30("tinycc-arm"));
return 0;
}

------
==11412== Memcheck, a memory error detector
==11412== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==11412== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==11412== Command: ./strlen30-tcc
==11412==
disInstr(arm): unhandled instruction: 0xE3511000
cond=14(0xE) 27:20=53(0x35) 4:4=0 3:0=0(0x0)
==11412== valgrind: Unrecognised instruction at address 0x8254.
==11412== at 0x8254: sqlite3Strlen30 (strlen30.c:14)
==11412== Your program just tried to execute an instruction that Valgrind
==11412== did not recognise. There are two possible reasons for this.
==11412== 1. Your program has a bug and erroneously jumped to a non-code
==11412== location. If you are running Memcheck and you just saw a
==11412== warning about a bad jump, it's probably your program's fault.
==11412== 2. The instruction is legitimate but Valgrind doesn't handle it,
==11412== i.e. it's Valgrind's fault. If you think this is the case or
==11412== you are not sure, please let us know and we'll try to fix it.
==11412== Either way, Valgrind will now raise a SIGILL signal which will
==11412== probably kill your program.
==11412==
==11412== Process terminating with default action of signal 4 (SIGILL)
==11412== Illegal opcode at address 0x8254
==11412== at 0x8254: sqlite3Strlen30 (strlen30.c:14)
==11412==
==11412== HEAP SUMMARY:
==11412== in use at exit: 0 bytes in 0 blocks
==11412== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==11412==
==11412== All heap blocks were freed -- no leaks are possible
==11412==
==11412== For counts of detected and suppressed errors, rerun with: -v
==11412== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
./strlen30-mk: line 9: 11412 Illegal instruction valgrind --tool=memcheck ./strlen30-tcc

-------- strlen30-tcc.o.asm

                1. <sqlite3Strlen30>:

sqlite3Strlen30():
/home/mingo/dev/fossil/strlen30.c:11
0: e1a0c00d mov ip, sp
4: e92d0003 push {r0, r1}
8: e92d5800 push {fp, ip, lr}
c: e1a0b00d mov fp, sp
10: e24bd004 sub sp, fp, #4
14: e59b000c ldr r0, [fp, #12]
18: e50b0004 str r0, [fp, #-4]
/home/mingo/dev/fossil/strlen30.c:13
1c: e59b000c ldr r0, [fp, #12]
20: e3500000 cmp r0, #0
24: 1a000001 bne 30 <sqlite3Strlen30+0x30>
28: e3a00000 mov r0, #0
2c: ea00000d b 68 <sqlite3Strlen30+0x68>
/home/mingo/dev/fossil/strlen30.c:14
30: e51b0004 ldr r0, [fp, #-4]
34: e5d01000 ldrb r1, [r0]
38: e3511000 cmp r1, #0
3c: 0a000004 beq 54 <sqlite3Strlen30+0x54>
40: e51b0004 ldr r0, [fp, #-4]
44: e1a01000 mov r1, r0
48: e2800001 add r0, r0, #1
4c: e50b0004 str r0, [fp, #-4]
50: eafffff6 b 30 <sqlite3Strlen30+0x30>
/home/mingo/dev/fossil/strlen30.c:15
54: e51b0004 ldr r0, [fp, #-4]
58: e59b100c ldr r1, [fp, #12]
5c: e0400001 sub r0, r0, r1
60: e3c00103 bic r0, r0, #-1073741824 ; 0xc0000000
64: e1a00000 nop ; (mov r0, r0)
68: e89ba800 ldm fp, {fp, sp, pc}

0000006c <main>:
main():
/home/mingo/dev/fossil/strlen30.c:18
6c: e1a0c00d mov ip, sp
70: e92d0003 push {r0, r1}
74: e92d5800 push {fp, ip, lr}
78: e1a0b00d mov fp, sp
7c: e24bd004 sub sp, fp, #4
/home/mingo/dev/fossil/strlen30.c:19
80: e59f0000 ldr r0, [pc] ; 88 <sqlite3Strlen30+0x88>
84: ea000000 b 8c <sqlite3Strlen30+0x8c>
88: 00000000 andeq r0, r0, r0
88: R_ARM_ABS32 L.6
8c: ebfffffe bl 0 <sqlite3Strlen30>
8c: R_ARM_PC24 sqlite3Strlen30
90: e1a01000 mov r1, r0
94: e59f0000 ldr r0, [pc] ; 9c <sqlite3Strlen30+0x9c>
98: ea000000 b a0 <sqlite3Strlen30+0xa0>
9c: 00000000 andeq r0, r0, r0
9c: R_ARM_ABS32 L.5
a0: ebfffffe bl 0 <printf>
a0: R_ARM_PC24 printf
/home/mingo/dev/fossil/strlen30.c:20
a4: e3a00000 mov r0, #0
a8: e1a00000 nop ; (mov r0, r0)
ac: e89ba800 ldm fp, {fp, sp, pc}

-------strlen30-gcc.o.asm

                1. <sqlite3Strlen30>:

sqlite3Strlen30():
/home/mingo/dev/fossil/strlen30.c:11
0: b480 push {r7}
2: b085 sub sp, #20
4: af00 add r7, sp, #0
6: 6078 str r0, [r7, #4]
/home/mingo/dev/fossil/strlen30.c:12
8: 687b ldr r3, [r7, #4]
a: 60fb str r3, [r7, #12]
/home/mingo/dev/fossil/strlen30.c:13
c: 687b ldr r3, [r7, #4]
e: 2b00 cmp r3, #0
10: d101 bne.n 16 <sqlite3Strlen30+0x16>
/home/mingo/dev/fossil/strlen30.c:13 (discriminator 1)
12: 2300 movs r3, #0
14: e00c b.n 30 <sqlite3Strlen30+0x30>
/home/mingo/dev/fossil/strlen30.c:14
16: e002 b.n 1e <sqlite3Strlen30+0x1e>
/home/mingo/dev/fossil/strlen30.c:14 (discriminator 2)
18: 68fb ldr r3, [r7, #12]
1a: 3301 adds r3, #1
1c: 60fb str r3, [r7, #12]
/home/mingo/dev/fossil/strlen30.c:14 (discriminator 1)
1e: 68fb ldr r3, [r7, #12]
20: 781b ldrb r3, [r3, #0]
22: 2b00 cmp r3, #0
24: d1f8 bne.n 18 <sqlite3Strlen30+0x18>
/home/mingo/dev/fossil/strlen30.c:15
26: 68fa ldr r2, [r7, #12]
28: 687b ldr r3, [r7, #4]
2a: 1ad3 subs r3, r2, r3
2c: f023 4340 bic.w r3, r3, #3221225472 ; 0xc0000000
/home/mingo/dev/fossil/strlen30.c:16
30: 4618 mov r0, r3
32: 3714 adds r7, #20
34: 46bd mov sp, r7
36: f85d 7b04 ldr.w r7, [sp], #4
3a: 4770 bx lr

0000003c <main>:
main():
/home/mingo/dev/fossil/strlen30.c:18
3c: b580 push {r7, lr}
3e: b082 sub sp, #8
40: af00 add r7, sp, #0
42: 6078 str r0, [r7, #4]
44: 6039 str r1, [r7, #0]
/home/mingo/dev/fossil/strlen30.c:19
46: f240 0000 movw r0, #0
46: R_ARM_THM_MOVW_ABS_NC .LC0
4a: f2c0 0000 movt r0, #0
4a: R_ARM_THM_MOVT_ABS .LC0
4e: f7ff ffd7 bl 0 <sqlite3Strlen30>
52: 4603 mov r3, r0
54: f240 0000 movw r0, #0
54: R_ARM_THM_MOVW_ABS_NC .LC1
58: f2c0 0000 movt r0, #0
58: R_ARM_THM_MOVT_ABS .LC1
5c: 4619 mov r1, r3
5e: f7ff fffe bl 0 <printf>
5e: R_ARM_THM_CALL printf
/home/mingo/dev/fossil/strlen30.c:20
62: 2300 movs r3, #0
/home/mingo/dev/fossil/strlen30.c:21
64: 4618 mov r0, r3
66: 3708 adds r7, #8
68: 46bd mov sp, r7
6a: bd80 pop {r7, pc}

Domingo Alvarez Duarte <mingodad>
Tue 01 Apr 2014 07:05:17 PM UTC, comment #4:

Here is the result of running vallgrind --tool=memcheck ./test-query-tcc , the same run but with ./test-query-gcc shows no errors/leaks

-----
==9714== Memcheck, a memory error detector
==9714== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==9714== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==9714== Command: ./test-query-tcc
==9714==
--9714-- Line number overflow detected (65520 --> 19) in src/sqlite3.c
==9714== Invalid read of size 4
==9714== at 0xE7B4: sqlite3DefaultMutex (src/sqlite3.c:18892)
==9714== Address 0xbdc3948c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE260: sqlite3MutexInit (src/sqlite3.c:18225)
==9714== Address 0xbdc39484 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE5F4: pthreadMutexInit (src/sqlite3.c:18628)
==9714== Address 0xbdc3948c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE2C8: sqlite3MutexInit (src/sqlite3.c:18234)
==9714== Address 0xbdc39484 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE2D4: sqlite3MutexInit (src/sqlite3.c:18240)
==9714== Address 0xbdc394a4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBAD1C: sqlite3_initialize (src/sqlite3.c:120182)
==9714== Address 0xbdc3949c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE6E4: pthreadMutexAlloc (src/sqlite3.c:18725)
==9714== Address 0xbdc39484 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE3D0: sqlite3MutexAlloc (src/sqlite3.c:18275)
==9714== Address 0xbdc3947c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE3D4: sqlite3MutexAlloc (src/sqlite3.c:18275)
==9714== Address 0xbdc3949c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBAD3C: sqlite3_initialize (src/sqlite3.c:120191)
==9714== Address 0xbdc39494 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE72C: pthreadMutexEnter (src/sqlite3.c:18780)
==9714== Address 0xbdc39484 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE454: sqlite3_mutex_enter (src/sqlite3.c:18293)
==9714== Address 0xbdc3947c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBAD48: sqlite3_initialize (src/sqlite3.c:120193)
==9714== Address 0xbdc39494 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBB9E4: sqlite3_config (src/sqlite3.c:120560)
==9714== Address 0xbdc39464 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE1FC: sqlite3MemSetDefault (src/sqlite3.c:16379)
==9714== Address 0xbdc3945c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xEB44: sqlite3MallocInit (src/sqlite3.c:19402)
==9714== Address 0xbdc3947c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xEB7C: sqlite3MallocInit (src/sqlite3.c:19404)
==9714== Address 0xbdc39474 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE1B8: sqlite3MemInit (src/sqlite3.c:16351)
==9714== Address 0xbdc3947c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xEDD0: sqlite3MallocInit (src/sqlite3.c:19434)
==9714== Address 0xbdc39474 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xEDD4: sqlite3MallocInit (src/sqlite3.c:19434)
==9714== Address 0xbdc394a4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBAD7C: sqlite3_initialize (src/sqlite3.c:120195)
==9714== Address 0xbdc3949c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF1E8: sqlite3Malloc (src/sqlite3.c:19551)
==9714== Address 0xbdc3942c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE198: sqlite3MemRoundup (src/sqlite3.c:16315)
==9714== Address 0xbdc393fc is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF030: mallocWithAlarm (src/sqlite3.c:19507)
==9714== Address 0xbdc393f4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0x92E8: sqlite3StatusSet (src/sqlite3.c:14215)
==9714== Address 0xbdc393fc is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF040: mallocWithAlarm (src/sqlite3.c:19509)
==9714== Address 0xbdc393f4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE02C: sqlite3MemMalloc (src/sqlite3.c:16233)
==9714== Address 0xbdc393fc is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF128: mallocWithAlarm (src/sqlite3.c:19518)
==9714== Address 0xbdc393f4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE0C0: sqlite3MemSize (src/sqlite3.c:16268)
==9714== Address 0xbdc393e4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF63C: sqlite3MallocSize (src/sqlite3.c:19690)
==9714== Address 0xbdc393dc is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF640: sqlite3MallocSize (src/sqlite3.c:19690)
==9714== Address 0xbdc393fc is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF140: mallocWithAlarm (src/sqlite3.c:19526)
==9714== Address 0xbdc393f4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0x9238: sqlite3StatusAdd (src/sqlite3.c:14203)
==9714== Address 0xbdc393fc is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF150: mallocWithAlarm (src/sqlite3.c:19528)
==9714== Address 0xbdc393f4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF15C: mallocWithAlarm (src/sqlite3.c:19530)
==9714== Address 0xbdc393f4 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF170: mallocWithAlarm (src/sqlite3.c:19531)
==9714== Address 0xbdc39434 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF1F4: sqlite3Malloc (src/sqlite3.c:19552)
==9714== Address 0xbdc3942c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE790: pthreadMutexLeave (src/sqlite3.c:18864)
==9714== Address 0xbdc3941c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE4E8: sqlite3_mutex_leave (src/sqlite3.c:18317)
==9714== Address 0xbdc39414 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF208: sqlite3Malloc (src/sqlite3.c:19552)
==9714== Address 0xbdc3942c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xF234: sqlite3Malloc (src/sqlite3.c:19557)
==9714== Address 0xbdc3944c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xFB24: sqlite3MallocZero (src/sqlite3.c:19820)
==9714== Address 0xbdc39444 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xFB4C: sqlite3MallocZero (src/sqlite3.c:19825)
==9714== Address 0xbdc39464 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xE644: pthreadMutexAlloc (src/sqlite3.c:18685)
==9714== Address 0xbdc3945c is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBADC4: sqlite3_initialize (src/sqlite3.c:120200)
==9714== Address 0xbdc39494 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBAE4C: sqlite3_initialize (src/sqlite3.c:120215)
==9714== Address 0xbdc39494 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
==9714== Invalid read of size 4
==9714== at 0xBAE74: sqlite3_initialize (src/sqlite3.c:120233)
==9714== Address 0xbdc39494 is just below the stack ptr. To suppress, use: --workaround-gcc296-bugs=yes
==9714==
disInstr(arm): unhandled instruction: 0xE3511000
cond=14(0xE) 27:20=53(0x35) 4:4=0 3:0=0(0x0)
==9714== valgrind: Unrecognised instruction at address 0x142a8.
==9714== at 0x142A8: sqlite3Strlen30 (src/sqlite3.c:21819)
==9714== Your program just tried to execute an instruction that Valgrind
==9714== did not recognise. There are two possible reasons for this.
==9714== 1. Your program has a bug and erroneously jumped to a non-code
==9714== location. If you are running Memcheck and you just saw a
==9714== warning about a bad jump, it's probably your program's fault.
==9714== 2. The instruction is legitimate but Valgrind doesn't handle it,
==9714== i.e. it's Valgrind's fault. If you think this is the case or
==9714== you are not sure, please let us know and we'll try to fix it.
==9714== Either way, Valgrind will now raise a SIGILL signal which will
==9714== probably kill your program.
==9714==
==9714== Process terminating with default action of signal 4 (SIGILL)
==9714== Illegal opcode at address 0x142A8
==9714== at 0x142A8: sqlite3Strlen30 (src/sqlite3.c:21819)
==9714==
==9714== HEAP SUMMARY:
==9714== in use at exit: 32 bytes in 1 blocks
==9714== total heap usage: 1 allocs, 0 frees, 32 bytes allocated
==9714==
==9714== LEAK SUMMARY:
==9714== definitely lost: 0 bytes in 0 blocks
==9714== indirectly lost: 0 bytes in 0 blocks
==9714== possibly lost: 32 bytes in 1 blocks
==9714== still reachable: 0 bytes in 0 blocks
==9714== suppressed: 0 bytes in 0 blocks
==9714== Rerun with --leak-check=full to see details of leaked memory
==9714==
==9714== For counts of detected and suppressed errors, rerun with: -v
==9714== ERROR SUMMARY: 66 errors from 47 contexts (suppressed: 0 from 0)
Illegal instruction

Domingo Alvarez Duarte <mingodad>
Tue 01 Apr 2014 06:59:15 PM UTC, comment #3:

Here is the same function disassembled with objdump -Dxls
-----
0000b614 <sqlite3Strlen30>:
sqlite3Strlen30():
/home/mingo/dev/fossil/src/sqlite3.c:21816
b614: e1a0c00d mov ip, sp
b618: e92d0003 push {r0, r1}
b61c: e92d5800 push {fp, ip, lr}
b620: e1a0b00d mov fp, sp
b624: e24bd004 sub sp, fp, #4
b628: e59b000c ldr r0, [fp, #12]
b62c: e50b0004 str r0, [fp, #-4]
/home/mingo/dev/fossil/src/sqlite3.c:21818
b630: e59b000c ldr r0, [fp, #12]
b634: e3500000 cmp r0, #0
b638: 1a000001 bne b644 <sqlite3_db_status+0xaed8>
b63c: e3a00000 mov r0, #0
b640: ea00000d b b67c <sqlite3_db_status+0xaf10>
/home/mingo/dev/fossil/src/sqlite3.c:21819
b644: e51b0004 ldr r0, [fp, #-4]
b648: e5d01000 ldrb r1, [r0]
b64c: e3511000 cmp r1, #0
b650: 0a000004 beq b668 <sqlite3_db_status+0xaefc>
b654: e51b0004 ldr r0, [fp, #-4]
b658: e1a01000 mov r1, r0
b65c: e2800001 add r0, r0, #1
b660: e50b0004 str r0, [fp, #-4]
b664: eafffff6 b b644 <sqlite3_db_status+0xaed8>
/home/mingo/dev/fossil/src/sqlite3.c:21820
b668: e51b0004 ldr r0, [fp, #-4]
b66c: e59b100c ldr r1, [fp, #12]
b670: e0400001 sub r0, r0, r1
b674: e3c00103 bic r0, r0, #-1073741824 ; 0xc0000000
b678: e1a00000 nop ; (mov r0, r0)
b67c: e89ba800 ldm fp, {fp, sp, pc}

-----

Domingo Alvarez Duarte <mingodad>
Tue 01 Apr 2014 06:52:41 PM UTC, comment #2:

Here is the function:


SQLITE_PRIVATE int sqlite3Strlen30(const char *z){
const char *z2 = z;
if( z==0 ) return 0;
while( *z2 ){ z2++; } //<<<<<< here is the line src/sqlite3.c:21819
return 0x3fffffff & (int)(z2 - z);
}


The error that existed before on translate.c also was a segfault on a "while" condition !!!!!

Domingo Alvarez Duarte <mingodad>
Tue 01 Apr 2014 06:45:51 PM UTC, comment #1:

Trying to generate the callgraph using valgrind gives this error:
Vallgrind with test-query-gcc works as expected.


#gcc -g -O0 -o test-query-gcc test-query.c src/sqlite3.c -ldl -lpthread
#tcc -g -O0 -o test-query-tcc test-query.c src/sqlite3.c -ldl -lpthread
valgrind --tool=callgrind ./test-query-gcc
valgrind --tool=callgrind ./test-query-tcc


==8772== Callgrind, a call-graph generating cache profiler
==8772== Copyright (C) 2002-2012, and GNU GPL'd, by Josef Weidendorfer et al.
==8772== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==8772== Command: ./test-query-tcc
==8772==
==8772== For interactive control, run 'callgrind_control -h'.
--8772-- Line number overflow detected (65520 --> 19) in src/sqlite3.c
disInstr(arm): unhandled instruction: 0xE3511000
cond=14(0xE) 27:20=53(0x35) 4:4=0 3:0=0(0x0)
==8772== valgrind: Unrecognised instruction at address 0x142a8.
==8772== at 0x142A8: sqlite3Strlen30 (src/sqlite3.c:21819)
==8772== Your program just tried to execute an instruction that Valgrind
==8772== did not recognise. There are two possible reasons for this.
==8772== 1. Your program has a bug and erroneously jumped to a non-code
==8772== location. If you are running Memcheck and you just saw a
==8772== warning about a bad jump, it's probably your program's fault.
==8772== 2. The instruction is legitimate but Valgrind doesn't handle it,
==8772== i.e. it's Valgrind's fault. If you think this is the case or
==8772== you are not sure, please let us know and we'll try to fix it.
==8772== Either way, Valgrind will now raise a SIGILL signal which will
==8772== probably kill your program.
==8772==
==8772== Process terminating with default action of signal 4 (SIGILL)
==8772== Illegal opcode at address 0x142A8
==8772== at 0x142A8: sqlite3Strlen30 (src/sqlite3.c:21819)
==8772==
==8772== Events : Ir
==8772== Collected : 288965
==8772==
==8772== I refs: 288,965
./test-query-mk: line 6: 8772 Illegal instruction valgrind --tool=callgrind ./test-query-tcc


Domingo Alvarez Duarte <mingodad>
Tue 01 Apr 2014 04:31:00 PM UTC, original submission:

Making tests with tinycc on arm ubuntu 13.10 on nexus 5, it compile sqlite3 but the resulting executable do not produce the same results compared to the same program compiled with gcc.

The code bellow assume we are on the root folder for fossil-scm sources and "fossil.fossil" is the name of fossil-scm main database.


#include <stdio.h>
#include <stdarg.h>
#include "src/sqlite3.h"

static int mydb_exists(sqlite3 db, const char zSql, ...){
va_list ap;
int rc;
va_start(ap, zSql);
sqlite3_stmt *pStmt;
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
va_end(ap);
printf("%s:%d -> %d %s\n", _FILE_, _LINE_, rc, zSql);
rc = sqlite3_step(pStmt);
printf("%s:%d -> %d %s\n", _FILE_, _LINE_, rc, zSql);
if( rc !=SQLITE_ROW ) {
rc = 0;
}else{
rc = 1;
}
sqlite3_finalize(pStmt);
return rc;
}

static const char *sql = "SELECT "
" blob.rid AS blobRid, "
" uuid AS uuid, "
" datetime(event.mtime) AS timestamp, "
" coalesce(ecomment, comment) AS comment, "
" coalesce(euser, user) AS user, "
" blob.rid IN leaf AS leaf, "
" bgcolor AS bgColor, "
" event.type AS eventType, "
" (SELECT group_concat(substr(tagname,5), ', ') FROM tag, tagxref "
" WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid "
" AND tagxref.rid=blob.rid AND tagxref.tagtype>0) AS tags, "
" tagid AS tagid, "
" brief AS brief, "
" event.mtime AS mtime "
" FROM event CROSS JOIN blob "
"WHERE blob.rid=event.objid "
" AND NOT EXISTS(SELECT 1 FROM tagxref WHERE tagid=5 AND tagtype>0 AND rid=blob.rid) ORDER BY event.mtime DESC LIMIT 20";

int main() {

sqlite3 *db;
int rc = sqlite3_open_v2(
"fossil.fossil", &db,
SQLITE_OPEN_READWRITE, NULL);
printf("%d Exists %d\n", rc, mydb_exists(db, sql));
sqlite3_close(db);
return 0;
}


-----
gcc -o test-query-gcc test-query.c src/sqlite3.c -ldl -lpthread
tcc -o test-query-tcc test-query.c src/sqlite3.c -ldl -lpthread
-----

And get results from the test-query-gcc but no results from test-query-tcc, now I'll try to get more close to the problem.

Domingo Alvarez Duarte <mingodad>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by mingodad (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup