From: Alexander Potapenko <glider@google.com>
To: glider@google.com
Cc: quic_jiangenj@quicinc.com, linux-kernel@vger.kernel.org,
kasan-dev@googlegroups.com, x86@kernel.org,
Aleksandr Nogikh <nogikh@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Dmitry Vyukov <dvyukov@google.com>,
Ingo Molnar <mingo@redhat.com>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Marco Elver <elver@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH 6/7] x86: objtool: add support for R_X86_64_REX_GOTPCRELX
Date: Wed, 16 Apr 2025 10:54:44 +0200 [thread overview]
Message-ID: <20250416085446.480069-7-glider@google.com> (raw)
In-Reply-To: <20250416085446.480069-1-glider@google.com>
When compiling modules with -fsanitize-coverage=trace-pc-guard, Clang
will emit R_X86_64_REX_GOTPCRELX relocations for the
__start___sancov_guards and __stop___sancov_guards symbols. Although
these relocations can be resolved within the same binary, they are left
over by the linker because of the --emit-relocs flag.
This patch makes it possible to resolve the R_X86_64_REX_GOTPCRELX
relocations at runtime, as doing so does not require a .got section.
In addition, add a missing overflow check to R_X86_64_PC32/R_X86_64_PLT32.
Cc: x86@kernel.org
Signed-off-by: Alexander Potapenko <glider@google.com>
---
arch/x86/include/asm/elf.h | 1 +
arch/x86/kernel/module.c | 8 ++++++++
arch/x86/um/asm/elf.h | 1 +
tools/objtool/arch/x86/decode.c | 1 +
4 files changed, 11 insertions(+)
diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
index 1fb83d47711f9..15d0438467e94 100644
--- a/arch/x86/include/asm/elf.h
+++ b/arch/x86/include/asm/elf.h
@@ -63,6 +63,7 @@ typedef struct user_i387_struct elf_fpregset_t;
#define R_X86_64_8 14 /* Direct 8 bit sign extended */
#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
#define R_X86_64_PC64 24 /* Place relative 64-bit signed */
+#define R_X86_64_REX_GOTPCRELX 42 /* R_X86_64_GOTPCREL with optimizations */
/*
* These are used to set parameters in the core dumps.
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
index 8984abd91c001..6c8b524bfbe3b 100644
--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -133,6 +133,14 @@ static int __write_relocate_add(Elf64_Shdr *sechdrs,
case R_X86_64_PC32:
case R_X86_64_PLT32:
val -= (u64)loc;
+ if ((s64)val != *(s32 *)&val)
+ goto overflow;
+ size = 4;
+ break;
+ case R_X86_64_REX_GOTPCRELX:
+ val -= (u64)loc;
+ if ((s64)val != *(s32 *)&val)
+ goto overflow;
size = 4;
break;
case R_X86_64_PC64:
diff --git a/arch/x86/um/asm/elf.h b/arch/x86/um/asm/elf.h
index 62ed5d68a9788..f314478ce9bc3 100644
--- a/arch/x86/um/asm/elf.h
+++ b/arch/x86/um/asm/elf.h
@@ -119,6 +119,7 @@ do { \
#define R_X86_64_8 14 /* Direct 8 bit sign extended */
#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
#define R_X86_64_PC64 24 /* Place relative 64-bit signed */
+#define R_X86_64_REX_GOTPCRELX 42 /* R_X86_64_GOTPCREL with optimizations */
/*
* This is used to ensure we don't load something for the wrong architecture.
diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c
index fe1362c345647..8736524d60344 100644
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -93,6 +93,7 @@ bool arch_pc_relative_reloc(struct reloc *reloc)
case R_X86_64_PLT32:
case R_X86_64_GOTPC32:
case R_X86_64_GOTPCREL:
+ case R_X86_64_REX_GOTPCRELX:
return true;
default:
--
2.49.0.604.gff1f9ca942-goog
next prev parent reply other threads:[~2025-04-16 8:55 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-16 8:54 [PATCH 0/7] RFC: coverage deduplication for KCOV Alexander Potapenko
2025-04-16 8:54 ` [PATCH 1/7] kcov: apply clang-format to kcov code Alexander Potapenko
2025-04-17 16:47 ` Marco Elver
2025-06-18 14:23 ` Alexander Potapenko
2025-04-16 8:54 ` [PATCH 2/7] kcov: factor out struct kcov_state Alexander Potapenko
2025-04-17 16:42 ` Marco Elver
2025-06-18 17:41 ` Alexander Potapenko
2025-06-25 16:36 ` Alexander Potapenko
2025-04-16 8:54 ` [PATCH 3/7] kcov: x86: introduce CONFIG_KCOV_ENABLE_GUARDS Alexander Potapenko
2025-04-17 19:43 ` Marco Elver
2025-04-22 5:27 ` Joey Jiao
2025-04-24 13:58 ` Alexander Potapenko
2025-04-24 14:03 ` Marco Elver
2025-04-16 8:54 ` [PATCH 4/7] kcov: add `trace` and `trace_size` to `struct kcov_state` Alexander Potapenko
2025-04-16 8:54 ` [PATCH 5/7] kcov: add ioctl(KCOV_UNIQUE_ENABLE) Alexander Potapenko
2025-04-22 9:29 ` Marco Elver
2025-04-23 13:08 ` Alexander Potapenko
2025-04-23 13:16 ` Alexander Potapenko
2025-04-23 13:30 ` Alexander Potapenko
2025-04-30 2:21 ` Joey Jiao
2025-04-30 6:32 ` Alexander Potapenko
2025-04-16 8:54 ` Alexander Potapenko [this message]
2025-04-16 14:21 ` [PATCH 6/7] x86: objtool: add support for R_X86_64_REX_GOTPCRELX Uros Bizjak
2025-04-17 15:37 ` Alexander Potapenko
2025-04-17 15:49 ` Ard Biesheuvel
2025-04-16 8:54 ` [PATCH 7/7] mm/kasan: define __asan_before_dynamic_init, __asan_after_dynamic_init Alexander Potapenko
2025-04-22 6:46 ` Marco Elver
2025-04-22 8:02 ` Alexander Potapenko
2025-04-16 10:52 ` [PATCH 0/7] RFC: coverage deduplication for KCOV Dmitry Vyukov
2025-04-17 4:04 ` Joey Jiao
2025-04-17 12:43 ` Alexander Potapenko
2025-04-17 8:13 ` Alexander Potapenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250416085446.480069-7-glider@google.com \
--to=glider@google.com \
--cc=andreyknvl@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=jpoimboe@kernel.org \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nogikh@google.com \
--cc=peterz@infradead.org \
--cc=quic_jiangenj@quicinc.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®