mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Re: [PATCH] cramfs: probe(): fix cdev lookup
       [not found]           ` <87bphx6gp4.fsf@macbook.be.48ers.dk>
@ 2009-12-17 10:32             ` Uwe Kleine-König
  0 siblings, 0 replies; only message in thread
From: Uwe Kleine-König @ 2009-12-17 10:32 UTC (permalink / raw)
  To: Peter Korsgaard; +Cc: u-boot-v2

Hello Peter,

On Thu, Dec 17, 2009 at 11:24:55AM +0100, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer@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@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@cassiopeia:~$ gcc test.c -o test
	ukleinek@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/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-12-17 10:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1260907745-7444-1-git-send-email-jacmet@sunsite.dk>
     [not found] ` <4B27F157.8050103@pengutronix.de>
     [not found]   ` <87zl5knfj8.fsf@macbook.be.48ers.dk>
     [not found]     ` <4B27F42A.5030001@pengutronix.de>
     [not found]       ` <20091216130836.GA16638@pengutronix.de>
     [not found]         ` <20091217100206.GK15126@pengutronix.de>
     [not found]           ` <87bphx6gp4.fsf@macbook.be.48ers.dk>
2009-12-17 10:32             ` [PATCH] cramfs: probe(): fix cdev lookup Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox