Kernel+LibELF: Don't demangle symbols in the kernel

Instead we should just generate kernel.map in such a way that it already
contains demangled symbols.
This commit is contained in:
Gunnar Beutner 2021-07-06 12:35:26 +02:00 committed by Gunnar Beutner
parent 8e8a5680d5
commit 67f0c0d5f0
Notes: sideshowbarker 2024-07-18 10:16:55 +09:00
7 changed files with 12 additions and 10 deletions

View file

@ -413,7 +413,7 @@ if (ENABLE_KERNEL_LTO)
check_ipo_supported()
set_property(TARGET ${KERNEL_TARGET} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
target_link_libraries(${KERNEL_TARGET} kernel_heap gcc supc++)
target_link_libraries(${KERNEL_TARGET} kernel_heap gcc)
add_dependencies(${KERNEL_TARGET} kernel_heap)
add_custom_command(

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Demangle.h>
#include <AK/TemporaryChange.h>
#include <Kernel/Arch/x86/SmapDisabler.h>
#include <Kernel/FileSystem/FileDescription.h>
@ -148,7 +147,7 @@ NEVER_INLINE static void dump_backtrace_impl(FlatPtr base_pointer, bool use_ksym
if (symbol.symbol->address == g_highest_kernel_symbol_address && offset > 4096)
dbgln("{:p}", symbol.address);
else
dbgln("{:p} {} +0x{:x}", symbol.address, demangle(symbol.symbol->name), offset);
dbgln("{:p} {} +0x{:x}", symbol.address, symbol.symbol->name, offset);
}
}

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Demangle.h>
#include <AK/StdLibExtras.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
@ -362,7 +361,7 @@ void Process::crash(int signal, FlatPtr ip, bool out_of_memory)
} else {
if (ip >= KERNEL_BASE && g_kernel_symbols_available) {
auto* symbol = symbolicate_kernel_address(ip);
dbgln("\033[31;1m{:p} {} +{}\033[0m\n", ip, (symbol ? demangle(symbol->name) : "(k?)"), (symbol ? ip - symbol->address : 0));
dbgln("\033[31;1m{:p} {} +{}\033[0m\n", ip, (symbol ? symbol->name : "(k?)"), (symbol ? ip - symbol->address : 0));
} else {
dbgln("\033[31;1m{:p} (?)\033[0m\n", ip);
}

View file

@ -4,7 +4,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Demangle.h>
#include <AK/ScopeGuard.h>
#include <AK/StringBuilder.h>
#include <AK/Time.h>
@ -1051,7 +1050,7 @@ static bool symbolicate(RecognizedSymbol const& symbol, Process& process, String
if (symbol.symbol->address == g_highest_kernel_symbol_address && offset > 4096) {
builder.appendff("{:p}\n", (void*)(mask_kernel_addresses ? 0xdeadc0de : symbol.address));
} else {
builder.appendff("{:p} {} + 0x{:x}\n", (void*)(mask_kernel_addresses ? 0xdeadc0de : symbol.address), demangle(symbol.symbol->name), offset);
builder.appendff("{:p} {} + 0x{:x}\n", (void*)(mask_kernel_addresses ? 0xdeadc0de : symbol.address), symbol.symbol->name, offset);
}
return true;
}

View file

@ -7,5 +7,5 @@ else
fi
nm -n $kernel_binary | awk '{ if ($2 != "a") print; }' | uniq > "$tmp"
printf "%08x\n" "$(wc -l "$tmp" | cut -f1 -d' ')" > kernel.map
cat "$tmp" >> kernel.map
c++filt < "$tmp" >> kernel.map
rm -f "$tmp"

View file

@ -289,6 +289,7 @@ StringView Image::Symbol::raw_data() const
return { section.raw_data() + (value() - section.address()), size() };
}
#ifndef KERNEL
Optional<Image::Symbol> Image::find_demangled_function(const StringView& name) const
{
Optional<Image::Symbol> found;
@ -309,6 +310,7 @@ Optional<Image::Symbol> Image::find_demangled_function(const StringView& name) c
});
return found;
}
#endif
Image::SortedSymbol* Image::find_sorted_symbol(FlatPtr address) const
{
@ -355,6 +357,7 @@ NEVER_INLINE void Image::sort_symbols() const
});
}
#ifndef KERNEL
String Image::symbolicate(u32 address, u32* out_offset) const
{
auto symbol_count = this->symbol_count();
@ -381,5 +384,6 @@ String Image::symbolicate(u32 address, u32* out_offset) const
}
return String::formatted("{} +{:#x}", demangled_name, address - symbol->address);
}
#endif
} // end namespace ELF

View file

@ -227,10 +227,11 @@ public:
FlatPtr base_address() const { return (FlatPtr)m_buffer; }
size_t size() const { return m_size; }
Optional<Symbol> find_demangled_function(const StringView& name) const;
bool has_symbols() const { return symbol_count(); }
#ifndef KERNEL
Optional<Symbol> find_demangled_function(const StringView& name) const;
String symbolicate(u32 address, u32* offset = nullptr) const;
#endif
Optional<Image::Symbol> find_symbol(u32 address, u32* offset = nullptr) const;
private: