summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibELF/Image.cpp
diff options
context:
space:
mode:
authorValtteri Koskivuori <vkoskiv@gmail.com>2021-10-18 02:16:33 +0300
committerAndreas Kling <kling@serenityos.org>2021-10-21 01:14:09 +0200
commitd1adf5bc5e528d44e61c16a8ce379f1c25e7396b (patch)
treec5de551d090f9bb557df25bcaced911cbe4af87a /Userland/Libraries/LibELF/Image.cpp
parent097902bd065b96f8dd24f1feeaab51e9cc621ec8 (diff)
downloadserenity-d1adf5bc5e528d44e61c16a8ce379f1c25e7396b.zip
LibELF+Userland: Move a few functions to Elf::Image
These were originally in `readelf`, but they became useful in `file` as well, so they are now available in Elf::Image with a slightly revised API.
Diffstat (limited to 'Userland/Libraries/LibELF/Image.cpp')
-rw-r--r--Userland/Libraries/LibELF/Image.cpp106
1 files changed, 85 insertions, 21 deletions
diff --git a/Userland/Libraries/LibELF/Image.cpp b/Userland/Libraries/LibELF/Image.cpp
index e8f30776da..7bea64a696 100644
--- a/Userland/Libraries/LibELF/Image.cpp
+++ b/Userland/Libraries/LibELF/Image.cpp
@@ -34,26 +34,6 @@ Image::~Image()
{
}
-#if ELF_IMAGE_DEBUG
-static const char* object_file_type_to_string(ElfW(Half) type)
-{
- switch (type) {
- case ET_NONE:
- return "None";
- case ET_REL:
- return "Relocatable";
- case ET_EXEC:
- return "Executable";
- case ET_DYN:
- return "Shared object";
- case ET_CORE:
- return "Core";
- default:
- return "(?)";
- }
-}
-#endif
-
StringView Image::section_index_to_string(unsigned index) const
{
VERIFY(m_valid);
@@ -83,7 +63,7 @@ void Image::dump() const
return;
}
- dbgln(" type: {}", object_file_type_to_string(header().e_type));
+ dbgln(" type: {}", ELF::Image::object_file_type_to_string(header().e_type).value_or("(?)"));
dbgln(" machine: {}", header().e_machine);
dbgln(" entry: {:x}", header().e_entry);
dbgln(" shoff: {}", header().e_shoff);
@@ -283,6 +263,90 @@ Optional<Image::Section> Image::lookup_section(const StringView& name) const
return {};
}
+Optional<StringView> Image::object_file_type_to_string(ElfW(Half) type)
+{
+ switch (type) {
+ case ET_NONE:
+ return "None"sv;
+ case ET_REL:
+ return "Relocatable"sv;
+ case ET_EXEC:
+ return "Executable"sv;
+ case ET_DYN:
+ return "Shared object"sv;
+ case ET_CORE:
+ return "Core"sv;
+ default:
+ return {};
+ }
+}
+
+Optional<StringView> Image::object_machine_type_to_string(ElfW(Half) type)
+{
+ switch (type) {
+ case ET_NONE:
+ return "None"sv;
+ case EM_M32:
+ return "AT&T WE 32100"sv;
+ case EM_SPARC:
+ return "SPARC"sv;
+ case EM_386:
+ return "Intel 80386"sv;
+ case EM_68K:
+ return "Motorola 68000"sv;
+ case EM_88K:
+ return "Motorola 88000"sv;
+ case EM_486:
+ return "Intel 80486"sv;
+ case EM_860:
+ return "Intel 80860"sv;
+ case EM_MIPS:
+ return "MIPS R3000 Big-Endian only"sv;
+ case EM_X86_64:
+ return "Advanced Micro Devices X86-64"sv;
+ default:
+ return {};
+ }
+}
+
+Optional<StringView> Image::object_abi_type_to_string(Elf_Byte type)
+{
+ switch (type) {
+ case ELFOSABI_SYSV:
+ return "SYSV"sv;
+ case ELFOSABI_HPUX:
+ return "HP-UX"sv;
+ case ELFOSABI_NETBSD:
+ return "NetBSD"sv;
+ case ELFOSABI_LINUX:
+ return "Linux"sv;
+ case ELFOSABI_HURD:
+ return "GNU Hurd"sv;
+ case ELFOSABI_86OPEN:
+ return "86Open"sv;
+ case ELFOSABI_SOLARIS:
+ return "Solaris"sv;
+ case ELFOSABI_MONTEREY:
+ return "AIX"sv;
+ case ELFOSABI_IRIX:
+ return "IRIX"sv;
+ case ELFOSABI_FREEBSD:
+ return "FreeBSD"sv;
+ case ELFOSABI_TRU64:
+ return "Tru64"sv;
+ case ELFOSABI_MODESTO:
+ return "Novell Modesto"sv;
+ case ELFOSABI_OPENBSD:
+ return "OpenBSD"sv;
+ case ELFOSABI_ARM:
+ return "ARM"sv;
+ case ELFOSABI_STANDALONE:
+ return "Standalone"sv;
+ default:
+ return {};
+ }
+}
+
StringView Image::Symbol::raw_data() const
{
auto section = this->section();