efi_loader: Handle RELA absolute relocations properly
authorAlexander Graf <agraf@suse.de>
Sun, 4 Nov 2018 21:25:22 +0000 (22:25 +0100)
committerAlexander Graf <agraf@suse.de>
Sun, 2 Dec 2018 20:59:37 +0000 (21:59 +0100)
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.

Reported-by: Auer, Lukas <lukas.auer@aisec.fraunhofer.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
lib/efi_loader/efi_runtime.c

index abcf03c5a42eee50c93401334c3563fa11f07117..ca66d33e588200684000480f8bf39a0f66110c34 100644 (file)
@@ -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