[RFC/RFT PATCH 09/19] x86/pm-trace: Use RIP-relative accesses for .tracedata

Ard Biesheuvel
2026-01-08T09:28:21Z

Use RIP-relative accesses and 32-bit offsets for .tracedata, to avoid
the need for relocation fixups at boot time. This is a prerequisite for
PIE linking, which only permits 64-bit wide loader-visible absolute
references.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/x86/include/asm/pm-trace.h | 4 ++--
drivers/base/power/trace.c | 6 +++---
2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/include/asm/pm-trace.h b/arch/x86/include/asm/pm-trace.h
index bfa32aa428e5..123faf978473 100644
--- a/arch/x86/include/asm/pm-trace.h
+++ b/arch/x86/include/asm/pm-trace.h
@@ -8,10 +8,10 @@
do { \
if (pm_trace_enabled) { \
const void *tracedata; \
- asm volatile(_ASM_MOV " $1f,%0\n" \
+ asm volatile("lea " _ASM_RIP(1f) ", %0\n" \
".section .tracedata,\"a\"\n" \
"1:\t.word %c1\n\t" \
- _ASM_PTR " %c2\n" \
+ ".long %c2 - .\n" \
".previous" \
:"=r" (tracedata) \
: "i" (__LINE__), "i" (__FILE__)); \
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index d8da7195bb00..111be5825529 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -167,7 +167,7 @@ EXPORT_SYMBOL(set_trace_device);
void generate_pm_trace(const void *tracedata, unsigned int user)
{
unsigned short lineno = *(unsigned short *)tracedata;
- const char *file = *(const char **)(tracedata + 2);
+ const char *file = offset_to_ptr((int *)(tracedata + 2));
unsigned int user_hash_value, file_hash_value;

if (!x86_platform.legacy.rtc)
@@ -187,9 +187,9 @@ static int show_file_hash(unsigned int value)

match = 0;
for (tracedata = __tracedata_start ; tracedata < __tracedata_end ;
- tracedata += 2 + sizeof(unsigned long)) {
+ tracedata += 2 + sizeof(int)) {
unsigned short lineno = *(unsigned short *)tracedata;
- const char *file = *(const char **)(tracedata + 2);
+ const char *file = offset_to_ptr((int *)(tracedata + 2));
unsigned int hash = hash_string(lineno, file, FILEHASH);
if (hash != value)
continue;
--
2.47.3