-mthumb-interwork and weak function symbols

Shaun Jackman sjackman@pathwayconnect.com
Thu Dec 20 10:57:00 GMT 2001


I've run into a bug in gcc.
Here's the recipe to reproduce it
enable -mthumb-interwork
compile one module -marm
have a strong function call a weak function
compile a second module -mthumb
declare a strong function to override the weak function

The effect:
the calling fuction (sys_write below) does in fact call the strong function 
(not the weak stub) but it calls it in arm mode, when it is in fact a thumb 
function.

Attached is an objdump -S that shows this.

Cheers,
Shaun

void __attribute__((weak))
gnputs( const char* str, unsigned count)
{
 209088c:	e1a0c00d 	mov	ip, sp
 2090890:	e92dd800 	stmdb	sp!, {fp, ip, lr, pc}
 2090894:	e24cb004 	sub	fp, ip, #4	; 0x4
 2090898:	e24dd008 	sub	sp, sp, #8	; 0x8
 209089c:	e50b0010 	str	r0, [fp, -#16]
 20908a0:	e50b1014 	str	r1, [fp, -#20]
	(void)str;
	(void)count;
}
 20908a4:	e91b6800 	ldmdb	fp, {fp, sp, lr}
 20908a8:	e12fff1e 	bx	lr

020908ac <sys_write>:


/**
 * Write to the lcd (a syscall callback)
 * @param fd file descriptor
 * @param buf the buffer
 * @param count length of the buffer
 * @return number of bytes unwritten
 */
unsigned
sys_write( int fd, const void* buf, unsigned count)
{
 20908ac:	e1a0c00d 	mov	ip, sp
 20908b0:	e92dd800 	stmdb	sp!, {fp, ip, lr, pc}
 20908b4:	e24cb004 	sub	fp, ip, #4	; 0x4
 20908b8:	e24dd00c 	sub	sp, sp, #12	; 0xc
 20908bc:	e50b0010 	str	r0, [fp, -#16]
 20908c0:	e50b1014 	str	r1, [fp, -#20]
 20908c4:	e50b2018 	str	r2, [fp, -#24]
	(void)fd;
	gnputs( buf, count);
 20908c8:	e51b0014 	ldr	r0, [fp, -#20]
 20908cc:	e51b1018 	ldr	r1, [fp, -#24]
 20908d0:	e59f3010 	ldr	r3, [pc, #10]	; 20908e8 <sys_write+0x3c>
 20908d4:	e1a0e00f 	mov	lr, pc
 20908d8:	e12fff13 	bx	r3
	return 0;
 20908dc:	e3a00000 	mov	r0, #0	; 0x0
}
 20908e0:	e91b6800 	ldmdb	fp, {fp, sp, lr}
 20908e4:	e12fff1e 	bx	lr
 20908e8:	0208d6dc 	andeq	sp, r8, #230686720	; 0xdc00000



More information about the Gcc-bugs mailing list