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
This commit is contained in:
Justin Hibbits 2018-05-10 03:59:48 +00:00
parent 8951f05525
commit b4a0a59871
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333447
4 changed files with 15 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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_ */

View File

@ -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);