All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/elf2flt: fix text relocations on xtensa
@ 2022-11-30  2:18 Max Filippov
  2022-12-03 21:41 ` Yann E. MORIN
  2022-12-08  9:55 ` Peter Korsgaard
  0 siblings, 2 replies; 3+ messages in thread
From: Max Filippov @ 2022-11-30  2:18 UTC (permalink / raw)
  To: buildroot; +Cc: Thomas Petazzoni, Niklas Cassel

elf2flt 2021.08 has changed endianness swapping logic for relocated
entries in the text segment. This broke little-endian xtensa FLAT images
which now fail to start with the following message:

  binfmt_flat: reloc outside program 0x24c80100 (0 - 0x6e430/0x56a20)

Fix it by restoring old endianness swapping logic for relocated entries
in the text segment when building for xtensa.

Reported-by: Niklas Cassel <niklas.cassel@wdc.com>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
I've tested a couple other prominent candidates, but it looks like
only xtensa has this issue. I've submitted pull request to elf2flt
with the patch below.

 ...-elf2flt-xtensa-fix-text-relocations.patch | 51 +++++++++++++++++++
 1 file changed, 51 insertions(+)
 create mode 100644 package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch

diff --git a/package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch b/package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch
new file mode 100644
index 000000000000..3664775906ea
--- /dev/null
+++ b/package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch
@@ -0,0 +1,51 @@
+From e248d9774506fdd8698b14a7edead113f19ecdb0 Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Tue, 29 Nov 2022 17:47:54 -0800
+Subject: [PATCH] xtensa: fix text relocations
+
+The commit 5e08f1968316 ("Don't always update text in !pic_with_got case")
+changed good_32bit_resolved_reloc to not do endianness swapping for
+relocated entries in the text segment. This broke little-endian xtensa
+FLAT images which after this change fail to start with the following
+message:
+
+  binfmt_flat: reloc outside program 0x24c80100 (0 - 0x6e430/0x56a20)
+
+Fix it by preserving 'update_text' when building for xtensa.
+
+Fixes: 5e08f1968316 ("Don't always update text in !pic_with_got case")
+Reported-by: Niklas Cassel <niklas.cassel@wdc.com>
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ elf2flt.c | 15 ++++++++++++++-
+ 1 file changed, 14 insertions(+), 1 deletion(-)
+
+diff --git a/elf2flt.c b/elf2flt.c
+index b93aecdaced3..cec3f4a22239 100644
+--- a/elf2flt.c
++++ b/elf2flt.c
+@@ -808,7 +808,20 @@ output_relocs (
+ 					continue;
+ 				case R_XTENSA_32:
+ 				case R_XTENSA_PLT:
+-					goto good_32bit_resolved_reloc;
++					if (bfd_big_endian (abs_bfd))
++						sym_addr =
++							(r_mem[0] << 24)
++							+ (r_mem[1] << 16)
++							+ (r_mem[2] << 8)
++							+ r_mem[3];
++					else
++						sym_addr =
++							r_mem[0]
++							+ (r_mem[1] << 8)
++							+ (r_mem[2] << 16)
++							+ (r_mem[3] << 24);
++					relocation_needed = 1;
++					break;
+ 				default:
+ 					goto bad_resolved_reloc;
+ #else
+-- 
+2.30.2
+
-- 
2.30.2

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] package/elf2flt: fix text relocations on xtensa
  2022-11-30  2:18 [Buildroot] [PATCH] package/elf2flt: fix text relocations on xtensa Max Filippov
@ 2022-12-03 21:41 ` Yann E. MORIN
  2022-12-08  9:55 ` Peter Korsgaard
  1 sibling, 0 replies; 3+ messages in thread
From: Yann E. MORIN @ 2022-12-03 21:41 UTC (permalink / raw)
  To: Max Filippov; +Cc: Niklas Cassel, Thomas Petazzoni, buildroot

Max, All,

On 2022-11-29 18:18 -0800, Max Filippov spake thusly:
> elf2flt 2021.08 has changed endianness swapping logic for relocated
> entries in the text segment. This broke little-endian xtensa FLAT images
> which now fail to start with the following message:
> 
>   binfmt_flat: reloc outside program 0x24c80100 (0 - 0x6e430/0x56a20)
> 
> Fix it by restoring old endianness swapping logic for relocated entries
> in the text segment when building for xtensa.
> 
> Reported-by: Niklas Cassel <niklas.cassel@wdc.com>
> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>

Applied to master, thanks.

Regards,
Yann E. MORIN.

> ---
> I've tested a couple other prominent candidates, but it looks like
> only xtensa has this issue. I've submitted pull request to elf2flt
> with the patch below.
> 
>  ...-elf2flt-xtensa-fix-text-relocations.patch | 51 +++++++++++++++++++
>  1 file changed, 51 insertions(+)
>  create mode 100644 package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch
> 
> diff --git a/package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch b/package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch
> new file mode 100644
> index 000000000000..3664775906ea
> --- /dev/null
> +++ b/package/elf2flt/0006-elf2flt-xtensa-fix-text-relocations.patch
> @@ -0,0 +1,51 @@
> +From e248d9774506fdd8698b14a7edead113f19ecdb0 Mon Sep 17 00:00:00 2001
> +From: Max Filippov <jcmvbkbc@gmail.com>
> +Date: Tue, 29 Nov 2022 17:47:54 -0800
> +Subject: [PATCH] xtensa: fix text relocations
> +
> +The commit 5e08f1968316 ("Don't always update text in !pic_with_got case")
> +changed good_32bit_resolved_reloc to not do endianness swapping for
> +relocated entries in the text segment. This broke little-endian xtensa
> +FLAT images which after this change fail to start with the following
> +message:
> +
> +  binfmt_flat: reloc outside program 0x24c80100 (0 - 0x6e430/0x56a20)
> +
> +Fix it by preserving 'update_text' when building for xtensa.
> +
> +Fixes: 5e08f1968316 ("Don't always update text in !pic_with_got case")
> +Reported-by: Niklas Cassel <niklas.cassel@wdc.com>
> +Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
> +---
> + elf2flt.c | 15 ++++++++++++++-
> + 1 file changed, 14 insertions(+), 1 deletion(-)
> +
> +diff --git a/elf2flt.c b/elf2flt.c
> +index b93aecdaced3..cec3f4a22239 100644
> +--- a/elf2flt.c
> ++++ b/elf2flt.c
> +@@ -808,7 +808,20 @@ output_relocs (
> + 					continue;
> + 				case R_XTENSA_32:
> + 				case R_XTENSA_PLT:
> +-					goto good_32bit_resolved_reloc;
> ++					if (bfd_big_endian (abs_bfd))
> ++						sym_addr =
> ++							(r_mem[0] << 24)
> ++							+ (r_mem[1] << 16)
> ++							+ (r_mem[2] << 8)
> ++							+ r_mem[3];
> ++					else
> ++						sym_addr =
> ++							r_mem[0]
> ++							+ (r_mem[1] << 8)
> ++							+ (r_mem[2] << 16)
> ++							+ (r_mem[3] << 24);
> ++					relocation_needed = 1;
> ++					break;
> + 				default:
> + 					goto bad_resolved_reloc;
> + #else
> +-- 
> +2.30.2
> +
> -- 
> 2.30.2
> 
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

* Re: [Buildroot] [PATCH] package/elf2flt: fix text relocations on xtensa
  2022-11-30  2:18 [Buildroot] [PATCH] package/elf2flt: fix text relocations on xtensa Max Filippov
  2022-12-03 21:41 ` Yann E. MORIN
@ 2022-12-08  9:55 ` Peter Korsgaard
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2022-12-08  9:55 UTC (permalink / raw)
  To: Max Filippov; +Cc: Niklas Cassel, Thomas Petazzoni, buildroot

>>>>> "Max" == Max Filippov <jcmvbkbc@gmail.com> writes:

 > elf2flt 2021.08 has changed endianness swapping logic for relocated
 > entries in the text segment. This broke little-endian xtensa FLAT images
 > which now fail to start with the following message:

 >   binfmt_flat: reloc outside program 0x24c80100 (0 - 0x6e430/0x56a20)

 > Fix it by restoring old endianness swapping logic for relocated entries
 > in the text segment when building for xtensa.

 > Reported-by: Niklas Cassel <niklas.cassel@wdc.com>
 > Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
 > ---
 > I've tested a couple other prominent candidates, but it looks like
 > only xtensa has this issue. I've submitted pull request to elf2flt
 > with the patch below.

Committed to 2022.08.x and 2022.02.x, thanks.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

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

end of thread, other threads:[~2022-12-08  9:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-30  2:18 [Buildroot] [PATCH] package/elf2flt: fix text relocations on xtensa Max Filippov
2022-12-03 21:41 ` Yann E. MORIN
2022-12-08  9:55 ` Peter Korsgaard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.