Debug Kit: Fix LoadedImage SymbolLookup for multiple TEXT segments.

Similar fixes to the previous commits: we need to take the size
of all the text segments into account. In userspace we already
have this value in the image_info, in the kernel we'd have to
compute it.

Also add TODOs to the kernel to adjust things in UserSymbolLookup.
At present we don't fetch any image infos other than [0], but
we should probably store this data differently in the runtime_loader
structure anyway.

Change-Id: Ife72a8fc18d3139bf2f1606782181ec0006aaf81
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8825
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
Augustin Cavalier 2025-01-11 00:21:06 -05:00 committed by waddlesplash
parent c3ff6461e5
commit e68498c7c9
2 changed files with 12 additions and 14 deletions

View File

@ -597,10 +597,7 @@ SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
bool exactMatch = false; bool exactMatch = false;
const char *symbolName = NULL; const char *symbolName = NULL;
int32 symbolCount = fSymbolLookup->Read(fImage->symhash[1]); for (int32 i = 0; i < fSymbolCount; i++) {
const elf_region_t *textRegion = fImage->regions; // local
for (int32 i = 0; i < symbolCount; i++) {
const elf_sym *symbol = &fSymbolLookup->Read(fImage->syms[i]); const elf_sym *symbol = &fSymbolLookup->Read(fImage->syms[i]);
// The symbol table contains not only symbols referring to functions // The symbol table contains not only symbols referring to functions
@ -612,13 +609,12 @@ SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
// though). // though).
if ((symbol->Type() != STT_FUNC && symbol->Type() != STT_OBJECT) if ((symbol->Type() != STT_FUNC && symbol->Type() != STT_OBJECT)
|| symbol->st_value == 0 || symbol->st_value == 0
|| symbol->st_value + symbol->st_size + textRegion->delta || (symbol->st_value + symbol->st_size) > (size_t)fInfo.text_size) {
> textRegion->vmstart + textRegion->size) {
continue; continue;
} }
// skip symbols starting after the given address // skip symbols starting after the given address
addr_t symbolAddress = symbol->st_value + textRegion->delta; addr_t symbolAddress = symbol->st_value + fLoadDelta;
if (symbolAddress > address) if (symbolAddress > address)
continue; continue;
@ -646,7 +642,7 @@ SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress,
if (symbolFound != NULL) { if (symbolFound != NULL) {
if (_baseAddress) if (_baseAddress)
*_baseAddress = symbolFound->st_value + textRegion->delta; *_baseAddress = symbolFound->st_value + fLoadDelta;
if (_symbolName) if (_symbolName)
*_symbolName = symbolName; *_symbolName = symbolName;
if (_exactMatch) if (_exactMatch)

View File

@ -1420,7 +1420,9 @@ public:
const uint32* hashBuckets = image.symhash + 2; const uint32* hashBuckets = image.symhash + 2;
const uint32* hashChains = image.symhash + 2 + hashTabSize; const uint32* hashChains = image.symhash + 2 + hashTabSize;
const elf_region_t& textRegion = image.regions[0]; const addr_t loadDelta = image.regions[0].delta;
// TODO: add a way to get other text regions' size!
size_t regionsSize = image.regions[0].size;
// search the image for the symbol // search the image for the symbol
elf_sym symbolFound; elf_sym symbolFound;
@ -1452,13 +1454,12 @@ public:
// -- couldn't verify that in the specs though). // -- couldn't verify that in the specs though).
if ((symbol.Type() != STT_FUNC && symbol.Type() != STT_OBJECT) if ((symbol.Type() != STT_FUNC && symbol.Type() != STT_OBJECT)
|| symbol.st_value == 0 || symbol.st_value == 0
|| symbol.st_value + symbol.st_size + textRegion.delta || (symbol.st_value + symbol.st_size) > regionsSize) {
> textRegion.vmstart + textRegion.size) {
continue; continue;
} }
// skip symbols starting after the given address // skip symbols starting after the given address
addr_t symbolAddress = symbol.st_value + textRegion.delta; addr_t symbolAddress = symbol.st_value + loadDelta;
if (symbolAddress > address) if (symbolAddress > address)
continue; continue;
addr_t symbolDelta = address - symbolAddress; addr_t symbolDelta = address - symbolAddress;
@ -1495,9 +1496,9 @@ public:
if (_baseAddress) { if (_baseAddress) {
if (deltaFound < INT_MAX) if (deltaFound < INT_MAX)
*_baseAddress = symbolFound.st_value + textRegion.delta; *_baseAddress = symbolFound.st_value + loadDelta;
else else
*_baseAddress = textRegion.vmstart; *_baseAddress = image.regions[0].vmstart;
} }
if (_exactMatch) if (_exactMatch)
@ -1517,6 +1518,7 @@ public:
if (!_Read(imageAddress, image)) if (!_Read(imageAddress, image))
return B_BAD_ADDRESS; return B_BAD_ADDRESS;
// TODO: text may be more than just the first region.
if (image.regions[0].vmstart <= address if (image.regions[0].vmstart <= address
&& address < image.regions[0].vmstart + image.regions[0].size) { && address < image.regions[0].vmstart + image.regions[0].size) {
return B_OK; return B_OK;