Skip to content

Commit 69505e3

Browse files
jpoimboePeter Zijlstra
authored andcommitted
bug: Use normal relative pointers in 'struct bug_entry'
With CONFIG_GENERIC_BUG_RELATIVE_POINTERS, the addr/file relative pointers are calculated weirdly: based on the beginning of the bug_entry struct address, rather than their respective pointer addresses. Make the relative pointers less surprising to both humans and tools by calculating them the normal way. Signed-off-by: Josh Poimboeuf <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Mark Rutland <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Acked-by: Sven Schnelle <[email protected]> # s390 Acked-by: Michael Ellerman <[email protected]> (powerpc) Acked-by: Catalin Marinas <[email protected]> Tested-by: Mark Rutland <[email protected]> [arm64] Link: https://lkml.kernel.org/r/f0e05be797a16f4fc2401eeb88c8450dcbe61df6.1652362951.git.jpoimboe@kernel.org
1 parent a7fed5c commit 69505e3

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

arch/arm64/include/asm/asm-bug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
14472: .string file; \
1515
.popsection; \
1616
\
17-
.long 14472b - 14470b; \
17+
.long 14472b - .; \
1818
.short line;
1919
#else
2020
#define _BUGVERBOSE_LOCATION(file, line)
@@ -25,7 +25,7 @@
2525
#define __BUG_ENTRY(flags) \
2626
.pushsection __bug_table,"aw"; \
2727
.align 2; \
28-
14470: .long 14471f - 14470b; \
28+
14470: .long 14471f - .; \
2929
_BUGVERBOSE_LOCATION(__FILE__, __LINE__) \
3030
.short flags; \
3131
.popsection; \

arch/powerpc/include/asm/bug.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#ifdef CONFIG_DEBUG_BUGVERBOSE
1414
.macro __EMIT_BUG_ENTRY addr,file,line,flags
1515
.section __bug_table,"aw"
16-
5001: .4byte \addr - 5001b, 5002f - 5001b
16+
5001: .4byte \addr - .
17+
.4byte 5002f - .
1718
.short \line, \flags
1819
.org 5001b+BUG_ENTRY_SIZE
1920
.previous
@@ -24,7 +25,7 @@
2425
#else
2526
.macro __EMIT_BUG_ENTRY addr,file,line,flags
2627
.section __bug_table,"aw"
27-
5001: .4byte \addr - 5001b
28+
5001: .4byte \addr - .
2829
.short \flags
2930
.org 5001b+BUG_ENTRY_SIZE
3031
.previous
@@ -49,15 +50,16 @@
4950
#ifdef CONFIG_DEBUG_BUGVERBOSE
5051
#define _EMIT_BUG_ENTRY \
5152
".section __bug_table,\"aw\"\n" \
52-
"2:\t.4byte 1b - 2b, %0 - 2b\n" \
53-
"\t.short %1, %2\n" \
53+
"2: .4byte 1b - .\n" \
54+
" .4byte %0 - .\n" \
55+
" .short %1, %2\n" \
5456
".org 2b+%3\n" \
5557
".previous\n"
5658
#else
5759
#define _EMIT_BUG_ENTRY \
5860
".section __bug_table,\"aw\"\n" \
59-
"2:\t.4byte 1b - 2b\n" \
60-
"\t.short %2\n" \
61+
"2: .4byte 1b - .\n" \
62+
" .short %2\n" \
6163
".org 2b+%3\n" \
6264
".previous\n"
6365
#endif

arch/riscv/include/asm/bug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
typedef u32 bug_insn_t;
3131

3232
#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
33-
#define __BUG_ENTRY_ADDR RISCV_INT " 1b - 2b"
34-
#define __BUG_ENTRY_FILE RISCV_INT " %0 - 2b"
33+
#define __BUG_ENTRY_ADDR RISCV_INT " 1b - ."
34+
#define __BUG_ENTRY_FILE RISCV_INT " %0 - ."
3535
#else
3636
#define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
3737
#define __BUG_ENTRY_FILE RISCV_PTR " %0"

arch/s390/include/asm/bug.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"1: .asciz \""__FILE__"\"\n" \
1616
".previous\n" \
1717
".section __bug_table,\"awM\",@progbits,%2\n" \
18-
"2: .long 0b-2b,1b-2b\n" \
18+
"2: .long 0b-.\n" \
19+
" .long 1b-.\n" \
1920
" .short %0,%1\n" \
2021
" .org 2b+%2\n" \
2122
".previous\n" \
@@ -30,7 +31,7 @@
3031
asm_inline volatile( \
3132
"0: mc 0,0\n" \
3233
".section __bug_table,\"awM\",@progbits,%1\n" \
33-
"1: .long 0b-1b\n" \
34+
"1: .long 0b-.\n" \
3435
" .short %0\n" \
3536
" .org 1b+%1\n" \
3637
".previous\n" \

arch/x86/include/asm/bug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#ifdef CONFIG_X86_32
1919
# define __BUG_REL(val) ".long " __stringify(val)
2020
#else
21-
# define __BUG_REL(val) ".long " __stringify(val) " - 2b"
21+
# define __BUG_REL(val) ".long " __stringify(val) " - ."
2222
#endif
2323

2424
#ifdef CONFIG_DEBUG_BUGVERBOSE

lib/bug.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
77
CONFIG_BUG - emit BUG traps. Nothing happens without this.
88
CONFIG_GENERIC_BUG - enable this code.
9-
CONFIG_GENERIC_BUG_RELATIVE_POINTERS - use 32-bit pointers relative to
10-
the containing struct bug_entry for bug_addr and file.
9+
CONFIG_GENERIC_BUG_RELATIVE_POINTERS - use 32-bit relative pointers for bug_addr and file
1110
CONFIG_DEBUG_BUGVERBOSE - emit full file+line information for each BUG
1211
1312
CONFIG_BUG and CONFIG_DEBUG_BUGVERBOSE are potentially user-settable
@@ -53,10 +52,10 @@ extern struct bug_entry __start___bug_table[], __stop___bug_table[];
5352

5453
static inline unsigned long bug_addr(const struct bug_entry *bug)
5554
{
56-
#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
57-
return bug->bug_addr;
55+
#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
56+
return (unsigned long)&bug->bug_addr_disp + bug->bug_addr_disp;
5857
#else
59-
return (unsigned long)bug + bug->bug_addr_disp;
58+
return bug->bug_addr;
6059
#endif
6160
}
6261

@@ -131,10 +130,10 @@ void bug_get_file_line(struct bug_entry *bug, const char **file,
131130
unsigned int *line)
132131
{
133132
#ifdef CONFIG_DEBUG_BUGVERBOSE
134-
#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
135-
*file = bug->file;
133+
#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
134+
*file = (const char *)&bug->file_disp + bug->file_disp;
136135
#else
137-
*file = (const char *)bug + bug->file_disp;
136+
*file = bug->file;
138137
#endif
139138
*line = bug->line;
140139
#else

0 commit comments

Comments
 (0)