arm: fix building by adding a feature
Subsystems (2)
v2 cover arm: fix building by adding a feature
The main motivator of this series is to get the arm build fixed. 522667917 "lib: backtrace printing" added a common backtrace() function, but we missed that arm's __builtin_return_address only accepts the input 0, and thus the function, which calls it with all values 0 to 20, can't compile on arm. To fix backtrace() for arm, the easiest thing to do is to override it with a backtrace that works. So this series makes some cleanups to stack tracing support and adds the support for ARM.
v2:
- replace .flat with .elf, not just any ol' flat string (drew)
- fall back to addr2line if config["ADDR2LINE"] doesn't exist (Peter)
- remove unnecessary initialization (Peter)
- add Peter's r-b's to patches 1..7
Andrew Jones (8):
x86: change exit to abort again
x86: trivial: there's no dump_stack.o
pretty_print_stacks: keep the 'STACK:' line
pretty_print_stacks: use elf file for the kernel
pretty_print_stacks: addr2line may need a cross prefix
stack: share api prototypes
stack: copy common asm/stack.h bits to all arches
arm: stack: add dump_stack support
arm/Makefile.arm | 4 ++++ configure | 2 ++ lib/arm/asm/stack.h | 11 +++++++++++ lib/arm/processor.c | 1 + lib/arm/stack.c | 41 +++++++++++++++++++++++++++++++++++++++++ lib/arm64/asm/stack.h | 8 ++++++++ lib/powerpc/asm/stack.h | 8 ++++++++ lib/ppc64/asm/stack.h | 8 ++++++++ lib/stack.h | 9 +++++---- lib/x86/asm/stack.h | 3 --- lib/x86/desc.c | 2 +- scripts/pretty_print_stacks.py | 14 +++++++++++--- x86/Makefile.common | 2 +- 13 files changed, 101 insertions(+), 12 deletions(-) create mode 100644 lib/arm/stack.c
Signature · 1 line
2.4.11
PATCH v2 1/8 x86: change exit to abort again
This is needed again because ed0a50e5 "x86: lib: debug dump on unhandled exceptions" must have missed it in a rebase.
--- lib/x86/desc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/x86/desc.c +1 -1
@@ -96,7 +96,7 @@ static void unhandled_exception(struct ex_regs *regs, bool cpu)#endif );dump_frame_stack ((void *) regs->rip, (void *) regs->rbp); -exit (7 ); +abort (); }static void check_exception_table (struct ex_regs *regs)
Signature · 1 line
2.4.11
PATCH v2 2/8 x86: trivial: there's no dump_stack.o
In reply to Andrew Jones--- x86/Makefile.common | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
x86/Makefile.common +1 -1
@@ -20,7 +20,7 @@ $(libcflat): CFLAGS += -ffreestanding -I lib CFLAGS += -m$(bits) CFLAGS += -O1 -# dump_stack.o relies on frame pointers. +# stack.o relies on frame pointers. KEEP_FRAME_POINTER := y libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
Signature · 1 line
2.4.11
PATCH v2 3/8 pretty_print_stacks: keep the 'STACK:' line
In reply to Andrew JonesIt's sometimes useful to have the addresses for searching in a disassembly. Anyway, there's no reason to drop it.
--- scripts/pretty_print_stacks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/pretty_print_stacks.py +2 -1
@@ -67,8 +67,9 @@ def main(): if line == '': break + puts(line) + if not line.strip().startswith('STACK:'): - puts(line) continue try:
Signature · 1 line
2.4.11
PATCH v2 4/8 pretty_print_stacks: use elf file for the kernel
In reply to Andrew Jonesx86 doesn't seem to care, but other architectures do.
--- scripts/pretty_print_stacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/pretty_print_stacks.py +1 -1
@@ -58,7 +58,7 @@ def main(): sys.stderr.write('usage: %s <kernel>\n' % sys.argv[0]) sys.exit(1) - binary = sys.argv[1] + binary = sys.argv[1].replace(".flat", ".elf") try: while True:
Signature · 1 line
2.4.11
PATCH v2 5/8 pretty_print_stacks: addr2line may need a cross prefix
In reply to Andrew Jones--- configure | 2 ++ scripts/pretty_print_stacks.py | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-)
configure +2 -0
@@ -7,6 +7,7 @@ ld=ld objcopy=objcopy objdump=objdump ar=ar +addr2line=addr2line arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'` host=$arch cross_prefix=
@@ -154,6 +155,7 @@ LD=$cross_prefix$ld OBJCOPY=$cross_prefix$objcopy OBJDUMP=$cross_prefix$objdump AR=$cross_prefix$ar +ADDR2LINE=$cross_prefix$addr2line API=$api TEST_DIR=$testdir FIRMWARE=$firmware
scripts/pretty_print_stacks.py +8 -1
@@ -5,6 +5,8 @@ import subprocess import sys import traceback +config = {} + # Subvert output buffering. def puts(string): sys.stdout.write(string)
@@ -25,7 +27,7 @@ def pretty_print_stack(binary, line): # Output like this: # 0x004002be: start64 at path/to/kvm-unit-tests/x86/cstart64.S:208 # (inlined by) test_ept_violation at path/to/kvm-unit-tests/x86/vmx_tests.c:1719 (discriminator 1) - cmd = ['addr2line', '-e', binary, '-i', '-f', '--pretty', '--address'] + cmd = [config.get('ADDR2LINE', 'addr2line'), '-e', binary, '-i', '-f', '--pretty', '--address'] cmd.extend(addrs) p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
@@ -60,6 +62,11 @@ def main(): binary = sys.argv[1].replace(".flat", ".elf") + with open("config.mak") as config_file: + for line in config_file: + name, val = line.partition("=")[::2] + config[name.strip()] = val.strip() + try: while True: # Subvert input buffering.
Signature · 1 line
2.4.11
PATCH v2 6/8 stack: share api prototypes
In reply to Andrew Jones--- lib/stack.h | 9 +++++---- lib/x86/asm/stack.h | 3 --- 2 files changed, 5 insertions(+), 7 deletions(-)
lib/stack.h +5 -4
@@ -4,7 +4,10 @@#include <libcflat.h> #include <asm/stack.h> -#ifndef HAVE_ARCH_BACKTRACE_FRAME +#ifdef HAVE_ARCH_BACKTRACE_FRAME +extern int backtrace_frame (const void *frame,const void **return_addrs, +int max_depth); +#else static inline int backtrace_frame(const void *frame __unused, const void **return_addrs __unused, int max_depth __unused)
@@ -13,8 +16,6 @@ backtrace_frame(const void *frame __unused, const void **return_addrs __unused, }#endif -#ifndef HAVE_ARCH_BACKTRACE -int backtrace (const void **return_addrs,int max_depth); -#endif +extern int backtrace (const void **return_addrs,int max_depth);#endif
lib/x86/asm/stack.h +0 -3
@@ -6,9 +6,6 @@#endif #define HAVE_ARCH_BACKTRACE_FRAME -int backtrace_frame (const void *frame,const void **return_addrs,int max_depth); -#define HAVE_ARCH_BACKTRACE -int backtrace (const void **return_addrs,int max_depth);#endif
Signature · 1 line
2.4.11
PATCH v2 7/8 stack: copy common asm/stack.h bits to all arches
In reply to Andrew Jones--- lib/arm/asm/stack.h | 8 ++++++++ lib/arm64/asm/stack.h | 8 ++++++++ lib/powerpc/asm/stack.h | 8 ++++++++ lib/ppc64/asm/stack.h | 8 ++++++++ 4 files changed, 32 insertions(+)
lib/arm/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMARM_STACK_H_ +#define _ASMARM_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
lib/arm64/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMARM64_STACK_H_ +#define _ASMARM64_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
lib/powerpc/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMPOWERPC_STACK_H_ +#define _ASMPOWERPC_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
lib/ppc64/asm/stack.h +8 -0
@@ -0,0 +1,8 @@ +#ifndef _ASMPPC64_STACK_H_ +#define _ASMPPC64_STACK_H_ + +#ifndef _STACK_H_ +#error Do not directly include <asm/stack.h>. Just use <stack.h>. +#endif + +#endif
Signature · 1 line
2.4.11
PATCH v2 8/8 arm: stack: add dump_stack support
In reply to Andrew JonesThis actually fixes the arm build too, as arm's __builtin_return_address doesn't allow any input other than zero, and thus the common backtrace() wasn't compiling.
--- arm/Makefile.arm | 4 ++++ lib/arm/asm/stack.h | 3 +++ lib/arm/processor.c | 1 + lib/arm/stack.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 lib/arm/stack.c
arm/Makefile.arm +4 -0
@@ -8,12 +8,16 @@ ldarch = elf32-littlearm kernel_offset = 0x10000 machine = -marm +# stack.o relies on frame pointers. +KEEP_FRAME_POINTER := y + CFLAGS += $(machine) CFLAGS += -mcpu=$(PROCESSOR) cstart.o = $(TEST_DIR)/cstart.o cflatobjs += lib/arm/spinlock.o cflatobjs += lib/arm/processor.o +cflatobjs += lib/arm/stack.o # arm specific tests tests =
lib/arm/asm/stack.h +3 -0
@@ -5,4 +5,7 @@#error Do not directly include <asm/stack.h>. Just use <stack.h>.#endif +#define HAVE_ARCH_BACKTRACE_FRAME +#define HAVE_ARCH_BACKTRACE +#endif
lib/arm/processor.c +1 -0
@@ -108,6 +108,7 @@ void do_handle_exception(enum vector v, struct pt_regs *regs) asmvolatile ("mrc p15, 0, %0, c5, c0, 1" :"=r" (fsr));printf ("IFAR: %08lx IFSR: %08lx\n" , far, fsr); } +dump_frame_stack ((void *)regs->ARM_pc, (void *)regs->ARM_fp);abort (); }
lib/arm/stack.c new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.4.11
Re: [kvm-unit-tests PATCH v2 8/8] arm: stack: add dump_stack support
Quoted 5 lines · Andrew Jones
This actually fixes the arm build too, as arm's
__builtin_return_addressdoesn't allow any input other than zero, and thus the commonbacktrace()wasn't compiling.Signed-off-by Andrew Jones <[email protected]>
Radim Krčmář
Applied2016-04-19 18:19+0200, Andrew Jones:
Quoted 1 line
The main motivator of this series is to get the arm build fixed.
Applied, thanks.