mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: 张忠山 <zzs213@126.com>
Cc: barebox <barebox@lists.infradead.org>
Subject: Re: bugfix: _barebox_image_size wrong if enable
Date: Tue, 18 Jun 2019 09:46:06 +0200	[thread overview]
Message-ID: <20190618074606.iq3i6gb5yazs5bfq@pengutronix.de> (raw)
In-Reply-To: <3bd6cd70.90d9.16b65a8086a.Coremail.zzs213@126.com>

On Mon, Jun 17, 2019 at 09:37:19PM +0800, 张忠山 wrote:
> When a pbl image uncompress and call the normal barebox, In
> barebox_non_pbl_start() it should call relocate_to_adr() to relocate barebox
> to barebox_base. Ofcouse CONFIG_RELOCATABLE enabled.
> 
> And barebox_base calculated by:
> 
> 	#define barebox_image_size	(unsigned int)&_barebox_image_size
> 
> 	unsigned long barebox_size = barebox_image_size +
> 		((unsigned long)&__bss_stop - (unsigned long)&__bss_start);
> 
> _barebox_image_size, __bss_stop, __bss_start all defined in linkscript
> "arch/arm/lib32/barebox.lds.S"
> 
> But when I print there value in function barebox_non_pbl_start() with the
> flowwing code:
> 
> 	putc_ll('X');
> 	putc_ll('\r');
> 	putc_ll('\n');
> 	PUTHEX_LL(barebox_size);
> 	putc_ll('\r');
> 	putc_ll('\n');
> 	PUTHEX_LL((unsigned long)&__bss_start);
> 	putc_ll('\r');
> 	putc_ll('\n');
> 	PUTHEX_LL((unsigned long)&__bss_stop);
> 	putc_ll('\r');
> 	putc_ll('\n');
> 
> The result as floww:
> 
> 	X
> 	00000000
> 	00000000
> 	00000000
> 
> It's so strange, SO objdump it:
> 
> 00017424 <barebox_non_pbl_start>:
>    17424:       e59f61a0        ldr     r6, [pc, #416]  ; 175cc <barebox_non_pbl_start+0x1a8>
>    17428:       e080a001        add     sl, r0, r1
>    1742c:       e59f919c        ldr     r9, [pc, #412]  ; 175d0 <barebox_non_pbl_start+0x1ac>
>    17430:       e1a08000        mov     r8, r0
>    17434:       e92d4890        push    {r4, r7, fp, lr}
>    17438:       e0895006        add     r5, r9, r6
>    1743c:       e59fb190        ldr     fp, [pc, #400]  ; 175d4 <barebox_non_pbl_start+0x1b0>
>    17440:       e3a00058        mov     r0, #88 ; 0x58
>    17444:       e1a07002        mov     r7, r2
>    17448:       ebfffca7        bl      166ec <PUTC_LL>
>    1744c:       e06b5005        rsb     r5, fp, r5
>    17450:       e3a0000d        mov     r0, #13
>    17454:       ebfffca4        bl      166ec <PUTC_LL>
>    17458:       e3a0000a        mov     r0, #10
>    1745c:       ebfffca2        bl      166ec <PUTC_LL>
>    17460:       e1a00005        mov     r0, r5
>    17464:       ebffffe0        bl      173ec <PUTHEX_LL>
>    17468:       e3a0000d        mov     r0, #13
>    1746c:       ebfffc9e        bl      166ec <PUTC_LL>
>    17470:       e3a0000a        mov     r0, #10
>    17474:       ebfffc9c        bl      166ec <PUTC_LL>
>    17478:       e1a0000b        mov     r0, fp
>    1747c:       ebffffda        bl      173ec <PUTHEX_LL>
>    17480:       e3a0000d        mov     r0, #13
>    17484:       ebfffc98        bl      166ec <PUTC_LL>
>    17488:       e3a0000a        mov     r0, #10
>    1748c:       ebfffc96        bl      166ec <PUTC_LL>
>    17490:       e1a00006        mov     r0, r6
>    17494:       e24a6906        sub     r6, sl, #98304  ; 0x18000
>    17498:       ebffffd3        bl      173ec <PUTHEX_LL>
>    1749c:       e3c66dff        bic     r6, r6, #16320  ; 0x3fc0
>    174a0:       e3a0000d        mov     r0, #13
>    ......
>    175c4:       ebffa2c5        bl      e0 <mem_malloc_init>
>    175c8:       ebffa5a5        bl      c64 <start_barebox>
>    175cc:       00000000        andeq   r0, r0, r0
>    175d0:       00000000        andeq   r0, r0, r0
>    175d4:       00000000        andeq   r0, r0, r0
>    175d8:       00022448        andeq   r2, r2, r8, asr #8
>    175dc:       d00dfeed        andle   pc, sp, sp, ror #29
> 
> 
> We can see it save __bss_start and __bss_stop in local literal pool located at
> 175cc and 175d0, The value is zero.  But in barebox.map it's
> 
>                 0x00000000000207b0                . = ALIGN (0x4)
>                 0x00000000000207b0                __bss_start = .
> 		......
>                 0x0000000000022458                __bss_stop = .
>                 0x0000000000022458                _end = .
>                 0x00000000000207b0                _barebox_image_size = __bss_start
> 
> 
> Why?? It's so strange! Is it a bug of toolchain?

No, it is corrected during runtime in relocate_to_current_adr(). It
seems older compilers need a runtime relocation fixup for this.

AFAIR this only happened for linker variables that point to absolute
addresses. Differences between addresses also worked with the older
compilers, and I think this is what your patch does: With this the
linker is smart enough to recognize _barebox_image_size as a relative
size and not an absolute address. So I think your patch is correct.

Unfortunately I can't find any toolchain anymore to reproduce this
issue.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

  reply	other threads:[~2019-06-18  7:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-17 13:37 张忠山
2019-06-18  7:46 ` Sascha Hauer [this message]
2019-06-18 10:17   ` 张忠山
2019-06-24  3:37     ` 张忠山
2019-06-26  7:20     ` Sascha Hauer
2019-06-26  9:39       ` 张忠山
2019-06-27 10:30         ` Sascha Hauer

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=20190618074606.iq3i6gb5yazs5bfq@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=zzs213@126.com \
    /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