Skip to contentSkip to conversation

efi_loader: Handle RELA absolute relocations properly

PATCH New Alexander Graf 3 participants 3 messages Nov 4, 2018 – Nov 5, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi_loader: Handle RELA absolute relocations properly

With RELA absolute relocations, the relocation target contains our link offset which we need to remove from the equation again. We did this properly in the relative relocation path, but not in the absolute one.

So let's do this for the absolute one as well. That way, u-boot can have a TEXT_OFFSET of != 0 and still relocate itself properly.

This fixes a bug where efi_loader did not work on the RISC-V QEMU port. With this patch, I can successfully run UEFI applications on the RISC-V QEMU port.

---
 lib/efi_loader/efi_runtime.c | 3 +++
 1 file changed, 3 insertions(+)
lib/efi_loader/efi_runtime.c +3 -0
index abcf03c5a4..ca66d33e58 100644
@@ -380,6 +380,9 @@ void efi_runtime_relocate(ulong offset, struct efi_mem_desc *map)
 			ulong symidx = rel->info >> SYM_INDEX;
 			extern struct dyn_sym __dyn_sym_start[];
 			newaddr = __dyn_sym_start[symidx].addr + offset;
+#ifdef IS_RELA
+			newaddr -= CONFIG_SYS_TEXT_BASE;
+#endif
 			break;
 		}
 #endif
Signature · 1 line
2.12.3
#1 lore raw

PATCH 1/1 efi_loader: Handle RELA absolute relocations properly

Quoted 12 lines · Alexander Graf

With RELA absolute relocations, the relocation target contains our link offset which we need to remove from the equation again. We did this properly in the relative relocation path, but not in the absolute one.

So let's do this for the absolute one as well. That way, u-boot can have a TEXT_OFFSET of != 0 and still relocate itself properly.

This fixes a bug where efi_loader did not work on the RISC-V QEMU port. With this patch, I can successfully run UEFI applications on the RISC-V QEMU port.

Quoted 6 lines
---
 lib/efi_loader/efi_runtime.c | 3 +++
 1 file changed, 3 insertions(+)
#2 lore raw

PATCH 1/1 efi_loader: Handle RELA absolute relocations properly

In reply to Alexander Graf
Quoted 16 lines · Alexander Graf

With RELA absolute relocations, the relocation target contains our link
offset which we need to remove from the equation again. We did this properly in the relative relocation path, but not in the absolute one.

So let's do this for the absolute one as well. That way, u-boot can have
a TEXT_OFFSET of != 0 and still relocate itself properly.

This fixes a bug where efi_loader did not work on the RISC-V QEMU port.
With this patch, I can successfully run UEFI applications on the RISC-V
QEMU port.

Quoted 7 lines
---
 lib/efi_loader/efi_runtime.c | 3 +++
 1 file changed, 3 insertions(+)

Thanks for the patch! That explains why it was working on the Andes targets.

Lukas