[PATCH] ppc64: Don't look for the TOC pointer all the time

Laurent Dufour ldufour at linux.vnet.ibm.com
Tue May 19 02:19:57 PDT 2015


When dealing with the purgatory's relocation, the TOC pointer is computed
by looking at the ".toc" section's address.

This should be done only once and the result kept back to avoid scanning
all the ELF section each time a TOC relative relocation is processed.

Signed-off-by: Laurent Dufour <ldufour at linux.vnet.ibm.com>
---
 kexec/arch/ppc64/kexec-elf-rel-ppc64.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/kexec/arch/ppc64/kexec-elf-rel-ppc64.c b/kexec/arch/ppc64/kexec-elf-rel-ppc64.c
index 9b191d0025a4..18d9f2f8e000 100644
--- a/kexec/arch/ppc64/kexec-elf-rel-ppc64.c
+++ b/kexec/arch/ppc64/kexec-elf-rel-ppc64.c
@@ -1,4 +1,4 @@
-#include <stdio.h>
+ #include <stdio.h>
 #include <elf.h>
 #include <string.h>
 #include "../../kexec.h"
@@ -40,13 +40,17 @@ static struct mem_shdr *toc_section(const struct mem_ehdr *ehdr)
 unsigned long my_r2(const struct mem_ehdr *ehdr)
 {
 	struct mem_shdr *shdr;
+	static unsigned long r2 = 0;
 
-	shdr = toc_section(ehdr);
-	if (!shdr) {
-		die("TOC reloc without a toc section?");
+	if (!r2) {
+		shdr = toc_section(ehdr);
+		if (!shdr) {
+			die("TOC reloc without a toc section?");
+		}
+		r2 = shdr->sh_addr + 0x8000;
 	}
 
-	return shdr->sh_addr + 0x8000;
+	return r2;
 }
 
 static void do_relative_toc(unsigned long value, uint16_t *location,
-- 
1.9.1




More information about the kexec mailing list