public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] mips: reloc: Change R_MIPS_NONE to catch pre-reloc BSS usage
@ 2020-06-05  8:29 Stefan Roese
  2020-06-05 15:51 ` Daniel Schwierzeck
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Roese @ 2020-06-05  8:29 UTC (permalink / raw)
  To: u-boot

This patch changes the R_MIPS_NONE define from 0 to a magic value. This
makes it possible to better detect any forbidden pre-relocation usage
of BSS variables, as they are often zero'ed and then relocation is
stopped too early.

Additionally the error message is improved to also print the faulting
address. This helps finding the root-cause for this breakage by
comparing this address with the values in System.map.

This patch helps a lot when working on pre-relocation code, like the
Octeon DDR init code, where such variables have hit me multiple times
now.

Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: Aaron Williams <awilliams@marvell.com>
Cc: Chandrakala Chavva <cchavva@marvell.com>
---
 arch/mips/include/asm/relocs.h | 2 +-
 arch/mips/lib/reloc.c          | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/arch/mips/include/asm/relocs.h b/arch/mips/include/asm/relocs.h
index 0987c4bb13..b9b0261f62 100644
--- a/arch/mips/include/asm/relocs.h
+++ b/arch/mips/include/asm/relocs.h
@@ -8,7 +8,7 @@
 #ifndef __ASM_MIPS_RELOCS_H__
 #define __ASM_MIPS_RELOCS_H__
 
-#define R_MIPS_NONE		0
+#define R_MIPS_NONE		0xbeef7531
 #define R_MIPS_32		2
 #define R_MIPS_26		4
 #define R_MIPS_HI16		5
diff --git a/arch/mips/lib/reloc.c b/arch/mips/lib/reloc.c
index ffc8c7a1b7..67c8af2f35 100644
--- a/arch/mips/lib/reloc.c
+++ b/arch/mips/lib/reloc.c
@@ -67,7 +67,7 @@ static unsigned long read_uint(uint8_t **buf)
  * intentionally simple, and does the bare minimum needed to fixup the
  * relocated U-Boot - in particular, it does not check for overflows.
  */
-static void apply_reloc(unsigned int type, void *addr, long off)
+static void apply_reloc(unsigned int type, void *addr, long off, uint8_t *buf)
 {
 	uint32_t u32;
 
@@ -92,7 +92,8 @@ static void apply_reloc(unsigned int type, void *addr, long off)
 		break;
 
 	default:
-		panic("Unhandled reloc type %u\n", type);
+		panic("Unhandled reloc type %u (@ %p), bss used before relocation?\n",
+		      type, buf);
 	}
 }
 
@@ -137,7 +138,7 @@ void relocate_code(ulong start_addr_sp, gd_t *new_gd, ulong relocaddr)
 			break;
 
 		addr += read_uint(&buf) << 2;
-		apply_reloc(type, (void *)addr, off);
+		apply_reloc(type, (void *)addr, off, buf);
 	}
 
 	/* Ensure the icache is coherent */
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] mips: reloc: Change R_MIPS_NONE to catch pre-reloc BSS usage
  2020-06-05  8:29 [PATCH] mips: reloc: Change R_MIPS_NONE to catch pre-reloc BSS usage Stefan Roese
@ 2020-06-05 15:51 ` Daniel Schwierzeck
  2020-06-06  4:46   ` Stefan Roese
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Schwierzeck @ 2020-06-05 15:51 UTC (permalink / raw)
  To: u-boot



Am 05.06.20 um 10:29 schrieb Stefan Roese:
> This patch changes the R_MIPS_NONE define from 0 to a magic value. This
> makes it possible to better detect any forbidden pre-relocation usage
> of BSS variables, as they are often zero'ed and then relocation is
> stopped too early.
> 
> Additionally the error message is improved to also print the faulting
> address. This helps finding the root-cause for this breakage by
> comparing this address with the values in System.map.
> 
> This patch helps a lot when working on pre-relocation code, like the
> Octeon DDR init code, where such variables have hit me multiple times
> now.
> 
> Signed-off-by: Stefan Roese <sr@denx.de>
> Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
> Cc: Aaron Williams <awilliams@marvell.com>
> Cc: Chandrakala Chavva <cchavva@marvell.com>
> ---
>  arch/mips/include/asm/relocs.h | 2 +-
>  arch/mips/lib/reloc.c          | 7 ++++---
>  2 files changed, 5 insertions(+), 4 deletions(-)
> 

applied to u-boot-mips/next, thanks.

BTW: in case the relocation table is cutted off, you can increase the
size with CONFIG_MIPS_RELOCATION_TABLE_SIZE.

-- 
- Daniel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] mips: reloc: Change R_MIPS_NONE to catch pre-reloc BSS usage
  2020-06-05 15:51 ` Daniel Schwierzeck
@ 2020-06-06  4:46   ` Stefan Roese
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2020-06-06  4:46 UTC (permalink / raw)
  To: u-boot

On 05.06.20 17:51, Daniel Schwierzeck wrote:
> 
> 
> Am 05.06.20 um 10:29 schrieb Stefan Roese:
>> This patch changes the R_MIPS_NONE define from 0 to a magic value. This
>> makes it possible to better detect any forbidden pre-relocation usage
>> of BSS variables, as they are often zero'ed and then relocation is
>> stopped too early.
>>
>> Additionally the error message is improved to also print the faulting
>> address. This helps finding the root-cause for this breakage by
>> comparing this address with the values in System.map.
>>
>> This patch helps a lot when working on pre-relocation code, like the
>> Octeon DDR init code, where such variables have hit me multiple times
>> now.
>>
>> Signed-off-by: Stefan Roese <sr@denx.de>
>> Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
>> Cc: Aaron Williams <awilliams@marvell.com>
>> Cc: Chandrakala Chavva <cchavva@marvell.com>
>> ---
>>   arch/mips/include/asm/relocs.h | 2 +-
>>   arch/mips/lib/reloc.c          | 7 ++++---
>>   2 files changed, 5 insertions(+), 4 deletions(-)
>>
> 
> applied to u-boot-mips/next, thanks.
> 
> BTW: in case the relocation table is cutted off, you can increase the
> size with CONFIG_MIPS_RELOCATION_TABLE_SIZE.

Yes, I know. But this is not the case here. Its the runtime overwrite
that I'm addressing.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-06  4:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-05  8:29 [PATCH] mips: reloc: Change R_MIPS_NONE to catch pre-reloc BSS usage Stefan Roese
2020-06-05 15:51 ` Daniel Schwierzeck
2020-06-06  4:46   ` Stefan Roese

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