From 0e45e3eb1d8a2c29e1163878bfcf29b81a6eb791 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Sun, 4 May 2014 12:52:05 +0200 Subject: [PATCH] runtime_loader: keep symbol DSO in SymbolLookupCache While resolving TLS related relocations it is necessary to know the DSO that defines the symbol. Without proper support in caching that information is available only when the symbol is resolved first time. That works well for TLS since TLS_DTPMOD is guaranteed to be before TLS_DTPOFF relocation. This patch makes the newly introduced parts of the interface work in a general case. --- .../runtime_loader/elf_symbol_lookup.cpp | 4 ++-- src/system/runtime_loader/elf_symbol_lookup.h | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/system/runtime_loader/elf_symbol_lookup.cpp b/src/system/runtime_loader/elf_symbol_lookup.cpp index d6e87c655e..593336e1ce 100644 --- a/src/system/runtime_loader/elf_symbol_lookup.cpp +++ b/src/system/runtime_loader/elf_symbol_lookup.cpp @@ -480,7 +480,7 @@ resolve_symbol(image_t* rootImage, image_t* image, elf_sym* sym, // check the cache first if (cache->IsSymbolValueCached(index)) { - *symAddress = cache->SymbolValueAt(index); + *symAddress = cache->SymbolValueAt(index, symbolImage); return B_OK; } @@ -579,7 +579,7 @@ resolve_symbol(image_t* rootImage, image_t* image, elf_sym* sym, return B_MISSING_SYMBOL; } - cache->SetSymbolValueAt(index, (addr_t)location); + cache->SetSymbolValueAt(index, (addr_t)location, sharedImage); if (symbolImage) *symbolImage = sharedImage; diff --git a/src/system/runtime_loader/elf_symbol_lookup.h b/src/system/runtime_loader/elf_symbol_lookup.h index 5be9e542c7..497fa12410 100644 --- a/src/system/runtime_loader/elf_symbol_lookup.h +++ b/src/system/runtime_loader/elf_symbol_lookup.h @@ -64,6 +64,7 @@ struct SymbolLookupCache { { if (fTableSize > 0) { fValues = (addr_t*)malloc(sizeof(addr_t) * fTableSize); + fDSOs = (image_t**)malloc(sizeof(image_t*) * fTableSize); size_t elementCount = (fTableSize + 31) / 32; fValuesResolved = (uint32*)malloc(4 * elementCount); @@ -81,6 +82,7 @@ struct SymbolLookupCache { { free(fValuesResolved); free(fValues); + free(fDSOs); } bool IsSymbolValueCached(size_t index) const @@ -94,18 +96,27 @@ struct SymbolLookupCache { return fValues[index]; } - void SetSymbolValueAt(size_t index, addr_t value) + addr_t SymbolValueAt(size_t index, image_t** image) const + { + if (image) + *image = fDSOs[index]; + return fValues[index]; + } + + void SetSymbolValueAt(size_t index, addr_t value, image_t* image) { if (index < fTableSize) { fValues[index] = value; + fDSOs[index] = image; fValuesResolved[index / 32] |= 1 << (index % 32); } } private: - size_t fTableSize; - addr_t* fValues; - uint32* fValuesResolved; + size_t fTableSize; + addr_t* fValues; + image_t** fDSOs; + uint32* fValuesResolved; };