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:
parent
8951f05525
commit
b4a0a59871
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=333447
@ -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;
|
c_linker_sym_t lsym;
|
||||||
Elf_Sym *sym, *match;
|
Elf_Sym *sym, *match;
|
||||||
unsigned long diff;
|
unsigned long diff;
|
||||||
|
db_addr_t stoffs;
|
||||||
|
|
||||||
if (symtab->private == NULL) {
|
if (symtab->private == NULL) {
|
||||||
if (!linker_ddb_search_symbol((caddr_t)off, &lsym, &diff)) {
|
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;
|
diff = ~0UL;
|
||||||
match = NULL;
|
match = NULL;
|
||||||
|
stoffs = DB_STOFFS(off);
|
||||||
for (sym = (Elf_Sym*)symtab->start; (char*)sym < symtab->end; sym++) {
|
for (sym = (Elf_Sym*)symtab->start; (char*)sym < symtab->end; sym++) {
|
||||||
if (sym->st_name == 0 || sym->st_shndx == SHN_UNDEF)
|
if (sym->st_name == 0 || sym->st_shndx == SHN_UNDEF)
|
||||||
continue;
|
continue;
|
||||||
if (off < sym->st_value)
|
if (stoffs < sym->st_value)
|
||||||
continue;
|
continue;
|
||||||
if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT &&
|
if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT &&
|
||||||
ELF_ST_TYPE(sym->st_info) != STT_FUNC &&
|
ELF_ST_TYPE(sym->st_info) != STT_FUNC &&
|
||||||
ELF_ST_TYPE(sym->st_info) != STT_NOTYPE)
|
ELF_ST_TYPE(sym->st_info) != STT_NOTYPE)
|
||||||
continue;
|
continue;
|
||||||
if ((off - sym->st_value) > diff)
|
if ((stoffs - sym->st_value) > diff)
|
||||||
continue;
|
continue;
|
||||||
if ((off - sym->st_value) < diff) {
|
if ((stoffs - sym->st_value) < diff) {
|
||||||
diff = off - sym->st_value;
|
diff = stoffs - sym->st_value;
|
||||||
match = sym;
|
match = sym;
|
||||||
} else {
|
} else {
|
||||||
if (match == NULL)
|
if (match == NULL)
|
||||||
|
@ -72,6 +72,10 @@ SYSCTL_DECL(_debug_ddb);
|
|||||||
#define DB_MAXSCRIPTRECURSION 3
|
#define DB_MAXSCRIPTRECURSION 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DB_STOFFS
|
||||||
|
#define DB_STOFFS(offs) (offs)
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DB_CALL
|
#ifndef DB_CALL
|
||||||
#define DB_CALL db_fncall_generic
|
#define DB_CALL db_fncall_generic
|
||||||
#else
|
#else
|
||||||
|
@ -85,4 +85,8 @@ typedef intptr_t db_expr_t; /* expression - signed */
|
|||||||
#define inst_load(ins) 0
|
#define inst_load(ins) 0
|
||||||
#define inst_store(ins) 0
|
#define inst_store(ins) 0
|
||||||
|
|
||||||
|
#ifdef __powerpc64__
|
||||||
|
#define DB_STOFFS(offs) ((offs) & ~DMAP_BASE_ADDRESS)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _POWERPC_DB_MACHDEP_H_ */
|
#endif /* _POWERPC_DB_MACHDEP_H_ */
|
||||||
|
@ -146,7 +146,7 @@ chrp_attach(platform_t plat)
|
|||||||
|
|
||||||
/* Set up important VPA fields */
|
/* Set up important VPA fields */
|
||||||
for (i = 0; i < MAXCPU; i++) {
|
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 */
|
/* First two: VPA size */
|
||||||
splpar_vpa[i][4] =
|
splpar_vpa[i][4] =
|
||||||
(uint8_t)((sizeof(splpar_vpa[i]) >> 8) & 0xff);
|
(uint8_t)((sizeof(splpar_vpa[i]) >> 8) & 0xff);
|
||||||
|
Loading…
Reference in New Issue
Block a user