[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20220531020744.236970-4-chenzhongjin@huawei.com>
Date: Tue, 31 May 2022 10:07:43 +0800
From: Chen Zhongjin <chenzhongjin@...wei.com>
To: <linux-kernel@...r.kernel.org>, <linux-arch@...r.kernel.org>,
<x86@...nel.org>
CC: <jpoimboe@...hat.com>, <peterz@...radead.org>,
<madvenka@...ux.microsoft.com>, <tglx@...utronix.de>,
<mingo@...hat.com>, <bp@...en8.de>, <hpa@...or.com>,
<arnd@...db.de>, <akpm@...ux-foundation.org>,
<andreyknvl@...il.com>, <wangkefeng.wang@...wei.com>,
<andrealmeid@...labora.com>, <mhiramat@...nel.org>,
<mcgrof@...nel.org>, <christophe.leroy@...roup.eu>,
<dmitry.torokhov@...il.com>, <yangtiezhu@...ngson.cn>,
<dave.hansen@...ux.intel.com>
Subject: [PATCH 3/4] objtool: Add generic symbol for relocation type
objtool uses R_X86_64_X as relocation type. Add abstraction
for them so that other architectures can use its own reloc enums.
Signed-off-by: Chen Zhongjin <chenzhongjin@...wei.com>
---
tools/objtool/arch/x86/include/arch/elf.h | 5 ++++-
tools/objtool/arch/x86/special.c | 5 +++--
tools/objtool/check.c | 12 ++++++------
tools/objtool/orc_gen.c | 3 ++-
4 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/tools/objtool/arch/x86/include/arch/elf.h b/tools/objtool/arch/x86/include/arch/elf.h
index 69cc4264b28a..7b737fcfcb9c 100644
--- a/tools/objtool/arch/x86/include/arch/elf.h
+++ b/tools/objtool/arch/x86/include/arch/elf.h
@@ -1,6 +1,9 @@
#ifndef _OBJTOOL_ARCH_ELF
#define _OBJTOOL_ARCH_ELF
-#define R_NONE R_X86_64_NONE
+#define R_NONE R_X86_64_NONE
+#define R_ABS64 R_X86_64_64
+#define R_REL32 R_X86_64_PC32
+#define R_PLT32 R_X86_64_PLT32
#endif /* _OBJTOOL_ARCH_ELF */
diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c
index 7c97b7391279..fbe0745a9ed7 100644
--- a/tools/objtool/arch/x86/special.c
+++ b/tools/objtool/arch/x86/special.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <string.h>
+#include <arch/elf.h>
#include <objtool/special.h>
#include <objtool/builtin.h>
@@ -108,7 +109,7 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
table_offset = text_reloc->addend;
table_sec = text_reloc->sym->sec;
- if (text_reloc->type == R_X86_64_PC32)
+ if (text_reloc->type == R_REL32)
table_offset += 4;
/*
@@ -138,7 +139,7 @@ struct reloc *arch_find_switch_table(struct objtool_file *file,
* indicates a rare GCC quirk/bug which can leave dead
* code behind.
*/
- if (text_reloc->type == R_X86_64_PC32)
+ if (text_reloc->type == R_REL32)
file->ignore_unreachables = true;
return rodata_reloc;
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 190b2f6e360a..11ab13fd99fd 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -650,7 +650,7 @@ static int create_static_call_sections(struct objtool_file *file)
/* populate reloc for 'addr' */
if (elf_add_reloc_to_insn(file->elf, sec,
idx * sizeof(struct static_call_site),
- R_X86_64_PC32,
+ R_REL32,
insn->sec, insn->offset))
return -1;
@@ -691,7 +691,7 @@ static int create_static_call_sections(struct objtool_file *file)
/* populate reloc for 'key' */
if (elf_add_reloc(file->elf, sec,
idx * sizeof(struct static_call_site) + 4,
- R_X86_64_PC32, key_sym,
+ R_REL32, key_sym,
is_sibling_call(insn) * STATIC_CALL_SITE_TAIL))
return -1;
@@ -735,7 +735,7 @@ static int create_retpoline_sites_sections(struct objtool_file *file)
if (elf_add_reloc_to_insn(file->elf, sec,
idx * sizeof(int),
- R_X86_64_PC32,
+ R_REL32,
insn->sec, insn->offset)) {
WARN("elf_add_reloc_to_insn: .retpoline_sites");
return -1;
@@ -787,7 +787,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
if (elf_add_reloc_to_insn(file->elf, sec,
idx * sizeof(int),
- R_X86_64_PC32,
+ R_REL32,
insn->sec, insn->offset)) {
WARN("elf_add_reloc_to_insn: .ibt_endbr_seal");
return -1;
@@ -832,7 +832,7 @@ static int create_mcount_loc_sections(struct objtool_file *file)
if (elf_add_reloc_to_insn(file->elf, sec,
idx * sizeof(unsigned long),
- R_X86_64_64,
+ R_ABS64,
insn->sec, insn->offset))
return -1;
@@ -3711,7 +3711,7 @@ static int validate_ibt_insn(struct objtool_file *file, struct instruction *insn
continue;
off = reloc->sym->offset;
- if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32)
+ if (reloc->type == R_REL32 || reloc->type == R_PLT32)
off += arch_dest_reloc_offset(reloc->addend);
else
off += reloc->addend;
diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c
index a7d060ba14d0..ab4dbfa52b1e 100644
--- a/tools/objtool/orc_gen.c
+++ b/tools/objtool/orc_gen.c
@@ -8,6 +8,7 @@
#include <linux/objtool.h>
+#include <arch/elf.h>
#include <objtool/check.h>
#include <objtool/orc.h>
#include <objtool/warn.h>
@@ -27,7 +28,7 @@ static int write_orc_entry(struct elf *elf, struct section *orc_sec,
orc->bp_offset = bswap_if_needed(orc->bp_offset);
/* populate reloc for ip */
- if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_X86_64_PC32,
+ if (elf_add_reloc_to_insn(elf, ip_sec, idx * sizeof(int), R_REL32,
insn_sec, insn_off))
return -1;
--
2.17.1
Powered by blists - more mailing lists