Skip to content

Commit 5d770f1

Browse files
committed
Merge tag 'objtool-urgent-2022-06-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull build tooling updates from Thomas Gleixner: - Remove obsolete CONFIG_X86_SMAP reference from objtool - Fix overlapping text section failures in faddr2line for real - Remove OBJECT_FILES_NON_STANDARD usage from x86 ftrace and replace it with finegrained annotations so objtool can validate that code correctly. * tag 'objtool-urgent-2022-06-19' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/ftrace: Remove OBJECT_FILES_NON_STANDARD usage faddr2line: Fix overlapping text section failures, the sequel objtool: Fix obsolete reference to CONFIG_X86_SMAP
2 parents 727c399 + 7b6c7a8 commit 5d770f1

File tree

6 files changed

+55
-19
lines changed

6 files changed

+55
-19
lines changed

arch/x86/kernel/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ KCSAN_SANITIZE := n
3636

3737
OBJECT_FILES_NON_STANDARD_test_nx.o := y
3838

39-
ifdef CONFIG_FRAME_POINTER
40-
OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y
41-
endif
42-
4339
# If instrumentation of this dir is enabled, boot hangs during first second.
4440
# Probably could be more selective here, but note that files related to irqs,
4541
# boot, dumpstack/stacktrace, etc are either non-interesting or can lead to

arch/x86/kernel/ftrace_64.S

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ SYM_INNER_LABEL(ftrace_caller_end, SYM_L_GLOBAL)
175175

176176
jmp ftrace_epilogue
177177
SYM_FUNC_END(ftrace_caller);
178+
STACK_FRAME_NON_STANDARD_FP(ftrace_caller)
178179

179180
SYM_FUNC_START(ftrace_epilogue)
180181
/*
@@ -282,6 +283,7 @@ SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL)
282283
jmp ftrace_epilogue
283284

284285
SYM_FUNC_END(ftrace_regs_caller)
286+
STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller)
285287

286288

287289
#else /* ! CONFIG_DYNAMIC_FTRACE */
@@ -311,10 +313,14 @@ trace:
311313
jmp ftrace_stub
312314
SYM_FUNC_END(__fentry__)
313315
EXPORT_SYMBOL(__fentry__)
316+
STACK_FRAME_NON_STANDARD_FP(__fentry__)
317+
314318
#endif /* CONFIG_DYNAMIC_FTRACE */
315319

316320
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
317-
SYM_FUNC_START(return_to_handler)
321+
SYM_CODE_START(return_to_handler)
322+
UNWIND_HINT_EMPTY
323+
ANNOTATE_NOENDBR
318324
subq $16, %rsp
319325

320326
/* Save the return values */
@@ -339,7 +345,6 @@ SYM_FUNC_START(return_to_handler)
339345
int3
340346
.Ldo_rop:
341347
mov %rdi, (%rsp)
342-
UNWIND_HINT_FUNC
343348
RET
344-
SYM_FUNC_END(return_to_handler)
349+
SYM_CODE_END(return_to_handler)
345350
#endif

include/linux/objtool.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ struct unwind_hint {
143143
.popsection
144144
.endm
145145

146+
.macro STACK_FRAME_NON_STANDARD_FP func:req
147+
#ifdef CONFIG_FRAME_POINTER
148+
STACK_FRAME_NON_STANDARD \func
149+
#endif
150+
.endm
151+
146152
.macro ANNOTATE_NOENDBR
147153
.Lhere_\@:
148154
.pushsection .discard.noendbr

lib/Kconfig.ubsan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ config UBSAN_UNREACHABLE
9494
bool "Perform checking for unreachable code"
9595
# objtool already handles unreachable checking and gets angry about
9696
# seeing UBSan instrumentation located in unreachable places.
97-
depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || X86_SMAP))
97+
depends on !(OBJTOOL && (STACK_VALIDATION || UNWINDER_ORC || HAVE_UACCESS_VALIDATION))
9898
depends on $(cc-option,-fsanitize=unreachable)
9999
help
100100
This option enables -fsanitize=unreachable which checks for control

scripts/faddr2line

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,25 @@ __faddr2line() {
9595
local print_warnings=$4
9696

9797
local sym_name=${func_addr%+*}
98-
local offset=${func_addr#*+}
99-
offset=${offset%/*}
98+
local func_offset=${func_addr#*+}
99+
func_offset=${func_offset%/*}
100100
local user_size=
101+
local file_type
102+
local is_vmlinux=0
101103
[[ $func_addr =~ "/" ]] && user_size=${func_addr#*/}
102104

103-
if [[ -z $sym_name ]] || [[ -z $offset ]] || [[ $sym_name = $func_addr ]]; then
105+
if [[ -z $sym_name ]] || [[ -z $func_offset ]] || [[ $sym_name = $func_addr ]]; then
104106
warn "bad func+offset $func_addr"
105107
DONE=1
106108
return
107109
fi
108110

111+
# vmlinux uses absolute addresses in the section table rather than
112+
# section offsets.
113+
local file_type=$(${READELF} --file-header $objfile |
114+
${AWK} '$1 == "Type:" { print $2; exit }')
115+
[[ $file_type = "EXEC" ]] && is_vmlinux=1
116+
109117
# Go through each of the object's symbols which match the func name.
110118
# In rare cases there might be duplicates, in which case we print all
111119
# matches.
@@ -114,9 +122,11 @@ __faddr2line() {
114122
local sym_addr=0x${fields[1]}
115123
local sym_elf_size=${fields[2]}
116124
local sym_sec=${fields[6]}
125+
local sec_size
126+
local sec_name
117127

118128
# Get the section size:
119-
local sec_size=$(${READELF} --section-headers --wide $objfile |
129+
sec_size=$(${READELF} --section-headers --wide $objfile |
120130
sed 's/\[ /\[/' |
121131
${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print "0x" $6; exit }')
122132

@@ -126,6 +136,17 @@ __faddr2line() {
126136
return
127137
fi
128138

139+
# Get the section name:
140+
sec_name=$(${READELF} --section-headers --wide $objfile |
141+
sed 's/\[ /\[/' |
142+
${AWK} -v sec=$sym_sec '$1 == "[" sec "]" { print $2; exit }')
143+
144+
if [[ -z $sec_name ]]; then
145+
warn "bad section name: section: $sym_sec"
146+
DONE=1
147+
return
148+
fi
149+
129150
# Calculate the symbol size.
130151
#
131152
# Unfortunately we can't use the ELF size, because kallsyms
@@ -174,10 +195,10 @@ __faddr2line() {
174195

175196
sym_size=0x$(printf %x $sym_size)
176197

177-
# Calculate the section address from user-supplied offset:
178-
local addr=$(($sym_addr + $offset))
198+
# Calculate the address from user-supplied offset:
199+
local addr=$(($sym_addr + $func_offset))
179200
if [[ -z $addr ]] || [[ $addr = 0 ]]; then
180-
warn "bad address: $sym_addr + $offset"
201+
warn "bad address: $sym_addr + $func_offset"
181202
DONE=1
182203
return
183204
fi
@@ -191,9 +212,9 @@ __faddr2line() {
191212
fi
192213

193214
# Make sure the provided offset is within the symbol's range:
194-
if [[ $offset -gt $sym_size ]]; then
215+
if [[ $func_offset -gt $sym_size ]]; then
195216
[[ $print_warnings = 1 ]] &&
196-
echo "skipping $sym_name address at $addr due to size mismatch ($offset > $sym_size)"
217+
echo "skipping $sym_name address at $addr due to size mismatch ($func_offset > $sym_size)"
197218
continue
198219
fi
199220

@@ -202,11 +223,13 @@ __faddr2line() {
202223
[[ $FIRST = 0 ]] && echo
203224
FIRST=0
204225

205-
echo "$sym_name+$offset/$sym_size:"
226+
echo "$sym_name+$func_offset/$sym_size:"
206227

207228
# Pass section address to addr2line and strip absolute paths
208229
# from the output:
209-
local output=$(${ADDR2LINE} -fpie $objfile $addr | sed "s; $dir_prefix\(\./\)*; ;")
230+
local args="--functions --pretty-print --inlines --exe=$objfile"
231+
[[ $is_vmlinux = 0 ]] && args="$args --section=$sec_name"
232+
local output=$(${ADDR2LINE} $args $addr | sed "s; $dir_prefix\(\./\)*; ;")
210233
[[ -z $output ]] && continue
211234

212235
# Default output (non --list):

tools/include/linux/objtool.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ struct unwind_hint {
143143
.popsection
144144
.endm
145145

146+
.macro STACK_FRAME_NON_STANDARD_FP func:req
147+
#ifdef CONFIG_FRAME_POINTER
148+
STACK_FRAME_NON_STANDARD \func
149+
#endif
150+
.endm
151+
146152
.macro ANNOTATE_NOENDBR
147153
.Lhere_\@:
148154
.pushsection .discard.noendbr

0 commit comments

Comments
 (0)