Skip to content

Commit

Permalink
elf2flt: xtensa: fix text relocations
Browse files Browse the repository at this point in the history
The commit 5e08f19 ("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.

This fix is a modified version of an original fix by Max Filippov
<[email protected]>. This commit message was his, though his
Signed-off-by has been dropped due to it being a different fix.

The relocation code is used "as-is" but a different entry path
into it ensures that "update_text" is not cleared for Xtensa.

Fixes: 5e08f19 ("Don't always update text in !pic_with_got case")
Reported-by: Niklas Cassel <[email protected]>
Signed-off-by: Greg Ungerer <[email protected]>
  • Loading branch information
Greg Ungerer authored and gregungerer committed Sep 6, 2023
1 parent c5c8043 commit 26dfb54
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions elf2flt.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ output_relocs (
continue;
case R_XTENSA_32:
case R_XTENSA_PLT:
goto good_32bit_resolved_reloc;
goto good_32bit_resolved_reloc_update_text;
default:
goto bad_resolved_reloc;
#elif defined(TARGET_riscv64)
Expand Down Expand Up @@ -856,6 +856,8 @@ output_relocs (
goto good_32bit_resolved_reloc;
#endif
good_32bit_resolved_reloc:
update_text = 0;
good_32bit_resolved_reloc_update_text:
if (bfd_big_endian (abs_bfd))
sym_addr =
(r_mem[0] << 24)
Expand All @@ -869,7 +871,6 @@ output_relocs (
+ (r_mem[2] << 16)
+ (r_mem[3] << 24);
relocation_needed = 1;
update_text = 0;
break;

bad_resolved_reloc:
Expand Down

0 comments on commit 26dfb54

Please sign in to comment.