Skip to content

Commit b8ec60e

Browse files
MaskRayIngo Molnar
authored and
Ingo Molnar
committed
x86/speculation, objtool: Use absolute relocations for annotations
.discard.retpoline_safe sections do not have the SHF_ALLOC flag. These sections referencing text sections' STT_SECTION symbols with PC-relative relocations like R_386_PC32 [0] is conceptually not suitable. Newer LLD will report warnings for REL relocations even for relocatable links [1]: ld.lld: warning: vmlinux.a(drivers/i2c/busses/i2c-i801.o):(.discard.retpoline_safe+0x120): has non-ABS relocation R_386_PC32 against symbol '' Switch to absolute relocations instead, which indicate link-time addresses. In a relocatable link, these addresses are also output section offsets, used by checks in tools/objtool/check.c. When linking vmlinux, these .discard.* sections will be discarded, therefore it is not a problem that R_X86_64_32 cannot represent a kernel address. Alternatively, we could set the SHF_ALLOC flag for .discard.* sections, but I think non-SHF_ALLOC for sections to be discarded makes more sense. Note: if we decide to never support REL architectures (e.g. arm, i386), we can utilize R_*_NONE relocations (.reloc ., BFD_RELOC_NONE, sym), making .discard.* sections zero-sized. That said, the section content waste is 4 bytes per entry, much smaller than sizeof(Elf{32,64}_Rel). [0] commit 1c0c1fa ("objtool: Use relative pointers for annotations") [1] ClangBuiltLinux#1937 Signed-off-by: Fangrui Song <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Cc: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fef44eb commit b8ec60e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

arch/x86/include/asm/alternative.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#define ANNOTATE_IGNORE_ALTERNATIVE \
5959
"999:\n\t" \
6060
".pushsection .discard.ignore_alts\n\t" \
61-
".long 999b - .\n\t" \
61+
".long 999b\n\t" \
6262
".popsection\n\t"
6363

6464
/*
@@ -352,7 +352,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
352352
.macro ANNOTATE_IGNORE_ALTERNATIVE
353353
.Lannotate_\@:
354354
.pushsection .discard.ignore_alts
355-
.long .Lannotate_\@ - .
355+
.long .Lannotate_\@
356356
.popsection
357357
.endm
358358

arch/x86/include/asm/nospec-branch.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
.macro ANNOTATE_RETPOLINE_SAFE
197197
.Lhere_\@:
198198
.pushsection .discard.retpoline_safe
199-
.long .Lhere_\@ - .
199+
.long .Lhere_\@
200200
.popsection
201201
.endm
202202

@@ -334,7 +334,7 @@
334334
#define ANNOTATE_RETPOLINE_SAFE \
335335
"999:\n\t" \
336336
".pushsection .discard.retpoline_safe\n\t" \
337-
".long 999b - .\n\t" \
337+
".long 999b\n\t" \
338338
".popsection\n\t"
339339

340340
typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE];

include/linux/objtool.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
#define ANNOTATE_NOENDBR \
4949
"986: \n\t" \
5050
".pushsection .discard.noendbr\n\t" \
51-
".long 986b - .\n\t" \
51+
".long 986b\n\t" \
5252
".popsection\n\t"
5353

5454
#define ASM_REACHABLE \
5555
"998:\n\t" \
5656
".pushsection .discard.reachable\n\t" \
57-
".long 998b - .\n\t" \
57+
".long 998b\n\t" \
5858
".popsection\n\t"
5959

6060
#else /* __ASSEMBLY__ */
@@ -66,7 +66,7 @@
6666
#define ANNOTATE_INTRA_FUNCTION_CALL \
6767
999: \
6868
.pushsection .discard.intra_function_calls; \
69-
.long 999b - .; \
69+
.long 999b; \
7070
.popsection;
7171

7272
/*
@@ -118,7 +118,7 @@
118118
.macro ANNOTATE_NOENDBR
119119
.Lhere_\@:
120120
.pushsection .discard.noendbr
121-
.long .Lhere_\@ - .
121+
.long .Lhere_\@
122122
.popsection
123123
.endm
124124

@@ -141,7 +141,7 @@
141141
.macro REACHABLE
142142
.Lhere_\@:
143143
.pushsection .discard.reachable
144-
.long .Lhere_\@ - .
144+
.long .Lhere_\@
145145
.popsection
146146
.endm
147147

0 commit comments

Comments
 (0)