[PATCH] cramfs: probe(): fix cdev lookup

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Thu Dec 17 05:32:44 EST 2009


Hello Peter,

On Thu, Dec 17, 2009 at 11:24:55AM +0100, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer at pengutronix.de> writes:
> 
>  >> > doh! I'm out of brown paper bags.
>  >> instead of sizeof("...") - 1, strlen should work.
> 
>  Sascha> Yes, it works, but adds to the binary space. This doesn't matter in this
>  Sascha> case since the binary size does not really matter for the sandbox, but
>  Sascha> we don't want other people to copy such things.
> 
> Notice that this is in fs/cramfs/crams.c, so not specific to sandbox. I
> would imagine gcc would be smart enough to replace strlen("/dev/") with
> the constant 5, but apparently not:
> 
> nm -S fs/cramfs/cramfs.o{.orig,}|grep cramfs_probe
> 0000000000000053 000000000000015d t cramfs_probe
> 0000000000000053 000000000000016f t cramfs_probe
hmmmm, I have here:

	ukleinek at cassiopeia:~$ cat test.c
	#include <string.h>

	size_t strlen(const char *s)
	{
		return 2;
	}

	int main(int argc, char **argv)
	{
		printf("strlen(\"Peter Korsgaard\") = %d\n", strlen("Peter Korsgaard"));
		return 0;
	}

	ukleinek at cassiopeia:~$ gcc test.c -o test
	ukleinek at cassiopeia:~$ ./test
	strlen("Peter Korsgaard") = 15

So the compiler *is* smart.  (Maybe even smarter than most people
expect.)

Compiling that with an arm compiler and disassembling yields:

	00000000 <strlen>:
	   0:	e1a0c00d 	mov	ip, sp
	   4:	e92dd800 	push	{fp, ip, lr, pc}
	   8:	e24cb004 	sub	fp, ip, #4	; 0x4
	   c:	e24dd008 	sub	sp, sp, #8	; 0x8
	  10:	e50b0010 	str	r0, [fp, #-16]
	  14:	e3a03002 	mov	r3, #2	; 0x2
	  18:	e1a00003 	mov	r0, r3
	  1c:	e24bd00c 	sub	sp, fp, #12	; 0xc
	  20:	e89da800 	ldm	sp, {fp, sp, pc}

	00000024 <main>:
	  24:	e1a0c00d 	mov	ip, sp
	  28:	e92dd800 	push	{fp, ip, lr, pc}
	  2c:	e24cb004 	sub	fp, ip, #4	; 0x4
	  30:	e24dd008 	sub	sp, sp, #8	; 0x8
	  34:	e50b0010 	str	r0, [fp, #-16]
	  38:	e50b1014 	str	r1, [fp, #-20]
	  3c:	e59f0014 	ldr	r0, [pc, #20]	; 58 <main+0x34>
	  40:	e3a0100f 	mov	r1, #15	; 0xf
	  44:	ebfffffe 	bl	0 <printf>
	  48:	e3a03000 	mov	r3, #0	; 0x0
	  4c:	e1a00003 	mov	r0, r3
	  50:	e24bd00c 	sub	sp, fp, #12	; 0xc
	  54:	e89da800 	ldm	sp, {fp, sp, pc}
	  58:	00000000 	.word	0x00000000

So the 15 is hardcoded as you can see at address 40.

Best regards
Uwe

-- 
Pengutronix e.K.                              | Uwe Kleine-König            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |



More information about the barebox mailing list