Bug 227093 - powerpc64/pseries: Symbol table not relocated
Summary: powerpc64/pseries: Symbol table not relocated
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: powerpc Any
: --- Affects Only Me
Assignee: Justin Hibbits
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-29 20:52 UTC by Breno Leitao
Modified: 2018-05-11 02:18 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Breno Leitao 2018-03-29 20:52:38 UTC
After the powerpc64 memory relocation code, the stack dumps on pseries does not show the function names properly because the symbol table is not relocated.

I created a patch that fixes it on the wrong way, i.e, masking the symbol address other than relocating the whole symbol table.

This is the workaround I am using at this moment, but I will work to relocated the symbol table and send it for review.

diff --git a/sys/kern/subr_stack.c b/sys/kern/subr_stack.c
index 0254c7f3fd0..dd767858f8e 100644
--- a/sys/kern/subr_stack.c
+++ b/sys/kern/subr_stack.c
@@ -264,7 +264,9 @@ stack_symbol_ddb(vm_offset_t pc, const char **name, long *offset)
        linker_symval_t symval;
        c_linker_sym_t sym;
 
-       if (linker_ddb_search_symbol((caddr_t)pc, &sym, offset) != 0)
+       caddr_t newpc =  (caddr_t) (pc & 0x0fffffffffffffff);
+
+       if (linker_ddb_search_symbol(newpc, &sym, offset) != 0)
                goto out;
        if (linker_ddb_symbol_values(sym, &symval) != 0)
                goto out;
diff --git a/sys/powerpc/powerpc/db_trace.c b/sys/powerpc/powerpc/db_trace.c
index a3ee988d438..68b886a68bc 100644
--- a/sys/powerpc/powerpc/db_trace.c
+++ b/sys/powerpc/powerpc/db_trace.c
@@ -284,7 +284,7 @@ db_backtrace(struct thread *td, db_addr_t fp, int count)
                }
 
                db_printf("at ");
-               db_printsym(lr, DB_STGY_PROC);
+               db_printsym(lr & 0x0fffffffffffffff, DB_STGY_PROC);
                if (full)
                        /* Print all the args stored in that stackframe. */
                        db_printf("(%zx, %zx, %zx, %zx, %zx, %zx, %zx, %zx)",
Comment 1 Nathan Whitehorn freebsd_committer freebsd_triage 2018-03-30 04:13:30 UTC
I'm a bit surprised at this, since we really should be doing the right thing.

One thing to check as an alternative patch:

In kern/link_elf.c, at line 427, there is a line:
        linker_kernel_file->address += KERNBASE;
Could you replace this with:
        linker_kernel_file->address += __startkernel;

It's possible you will have to prevent the following if statement from running as well.
Comment 2 Breno Leitao 2018-04-03 00:03:54 UTC
Hi Nathan,

This patch shouldn't be considered to be applied. This is just a first demonstration on how to solve this issue in a hackish way. We definitely need to fix the debug symbol table.

Regarding your proposal, it didn't help either, since I still see the following stack when I run [1]

0xe000000000318da0: at 0xc00000000067bd4c
0xe000000000318ed0: at .dump+0x2c
0xe000000000318f50: at .handler+0x3c
0xe000000000318fd0: at 0xc0000000006001e8
0xe000000000319070: at 0xc0000000005f1d60
0xe000000000319450: at 0xc0000000005f2588
0xe000000000319510: at 0xc0000000005f26f4
0xe0000000003195b0: at 0xc0000000009ca550
0xe000000000319770: at 0xc0000000009bf418
0xe000000000319810: user SC trap by 0x8100daef8: srr1=0x800000000000f032
            r1=0x3fffffffffffbd90 cr=0x44224044 xer=0x20000000 ctr=0x8100daef0 r2=0x810258e50

Looking further at the code, it seems that the linker_kernel_file->address is not affecting the debug symbols st_value field at all, that explains why they are not being relocated.

For now, I am trying to relocate the whole debug symbol table manually to see if that fixes the problem.


[1] https://github.com/leitao/freebsd_modules/tree/master/dump_stack
Comment 3 Breno Leitao 2018-05-09 21:40:13 UTC
A new revision was made to get this fixed:

https://reviews.freebsd.org/D15372
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-05-10 04:00:51 UTC
A commit references this bug:

Author: jhibbits
Date: Thu May 10 03:59:49 UTC 2018
New revision: 333447
URL: https://svnweb.freebsd.org/changeset/base/333447

Log:
  Fix PPC symbol resolution

  Summary:
  There were 2 issues that were preventing correct symbol resolution
  on PowerPC/pseries:

  1- memory corruption at chrp_attach() - this caused the inital
     part of the symbol table to become zeroed, which would cause
     the kernel linker to fail to parse it.
     (this was probably zeroing out other memory parts as well)

  2- DDB symbol resolution wasn't working because symtab contained
     not relocated addresses but it was given relocated offsets.
     Although relocating the symbol table fixed this, it broke the
     linker, that already handled this case.
     Thus, the fix for this consists in adding a new DDB macro:
     DB_STOFFS(offs) that converts a (potentially) relocated offset
     into one that can be compared with symbol table values.

  PR:		227093
  Submitted by:	Leandro Lupori <leandro.lupori_gmail.com>
  Differential Revision: https://reviews.freebsd.org/D15372

Changes:
  head/sys/ddb/db_main.c
  head/sys/ddb/ddb.h
  head/sys/powerpc/include/db_machdep.h
  head/sys/powerpc/pseries/platform_chrp.c
Comment 5 Justin Hibbits freebsd_committer freebsd_triage 2018-05-11 02:18:49 UTC
Fixed in r333447