From b4a0a5987135379c4e7f208fa3690d9d02e93552 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Thu, 10 May 2018 03:59:48 +0000 Subject: [PATCH] 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 Differential Revision: https://reviews.freebsd.org/D15372 --- sys/ddb/db_main.c | 10 ++++++---- sys/ddb/ddb.h | 4 ++++ sys/powerpc/include/db_machdep.h | 4 ++++ sys/powerpc/pseries/platform_chrp.c | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/ddb/db_main.c b/sys/ddb/db_main.c index 174f930fc7c4..11b2113d7111 100644 --- a/sys/ddb/db_main.c +++ b/sys/ddb/db_main.c @@ -100,6 +100,7 @@ X_db_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strat, c_linker_sym_t lsym; Elf_Sym *sym, *match; unsigned long diff; + db_addr_t stoffs; if (symtab->private == NULL) { if (!linker_ddb_search_symbol((caddr_t)off, &lsym, &diff)) { @@ -111,19 +112,20 @@ X_db_search_symbol(db_symtab_t *symtab, db_addr_t off, db_strategy_t strat, diff = ~0UL; match = NULL; + stoffs = DB_STOFFS(off); for (sym = (Elf_Sym*)symtab->start; (char*)sym < symtab->end; sym++) { if (sym->st_name == 0 || sym->st_shndx == SHN_UNDEF) continue; - if (off < sym->st_value) + if (stoffs < sym->st_value) continue; if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT && ELF_ST_TYPE(sym->st_info) != STT_FUNC && ELF_ST_TYPE(sym->st_info) != STT_NOTYPE) continue; - if ((off - sym->st_value) > diff) + if ((stoffs - sym->st_value) > diff) continue; - if ((off - sym->st_value) < diff) { - diff = off - sym->st_value; + if ((stoffs - sym->st_value) < diff) { + diff = stoffs - sym->st_value; match = sym; } else { if (match == NULL) diff --git a/sys/ddb/ddb.h b/sys/ddb/ddb.h index d54fe3326520..d9452d4b5692 100644 --- a/sys/ddb/ddb.h +++ b/sys/ddb/ddb.h @@ -72,6 +72,10 @@ SYSCTL_DECL(_debug_ddb); #define DB_MAXSCRIPTRECURSION 3 #endif +#ifndef DB_STOFFS +#define DB_STOFFS(offs) (offs) +#endif + #ifndef DB_CALL #define DB_CALL db_fncall_generic #else diff --git a/sys/powerpc/include/db_machdep.h b/sys/powerpc/include/db_machdep.h index c0dd7415bcbf..ff516c9b9942 100644 --- a/sys/powerpc/include/db_machdep.h +++ b/sys/powerpc/include/db_machdep.h @@ -85,4 +85,8 @@ typedef intptr_t db_expr_t; /* expression - signed */ #define inst_load(ins) 0 #define inst_store(ins) 0 +#ifdef __powerpc64__ +#define DB_STOFFS(offs) ((offs) & ~DMAP_BASE_ADDRESS) +#endif + #endif /* _POWERPC_DB_MACHDEP_H_ */ diff --git a/sys/powerpc/pseries/platform_chrp.c b/sys/powerpc/pseries/platform_chrp.c index b85b19d05cb3..c254c0f5c425 100644 --- a/sys/powerpc/pseries/platform_chrp.c +++ b/sys/powerpc/pseries/platform_chrp.c @@ -146,7 +146,7 @@ chrp_attach(platform_t plat) /* Set up important VPA fields */ for (i = 0; i < MAXCPU; i++) { - bzero(splpar_vpa[i], sizeof(splpar_vpa)); + bzero(splpar_vpa[i], sizeof(splpar_vpa[i])); /* First two: VPA size */ splpar_vpa[i][4] = (uint8_t)((sizeof(splpar_vpa[i]) >> 8) & 0xff);