mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Peter Korsgaard <jacmet@sunsite.dk>
Cc: u-boot-v2@lists.infradead.org
Subject: Re: [PATCH] cramfs: probe(): fix cdev lookup
Date: Thu, 17 Dec 2009 11:32:44 +0100	[thread overview]
Message-ID: <20091217103244.GF19548@pengutronix.de> (raw)
In-Reply-To: <87bphx6gp4.fsf@macbook.be.48ers.dk>

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

           reply	other threads:[~2009-12-17 10:32 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <87bphx6gp4.fsf@macbook.be.48ers.dk>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091217103244.GF19548@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=jacmet@sunsite.dk \
    --cc=u-boot-v2@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox