Gunnar Beutner
0cca23def5
LibELF: Improve error message for missing symbols
2021-04-19 12:00:40 +02:00
Gunnar Beutner
6cb28ecee8
LibC+LibELF: Implement support for the dl_iterate_phdr helper
...
This helper is used by libgcc_s to figure out where the .eh_frame sections
are located for all loaded shared objects.
2021-04-18 10:55:25 +02:00
Gunnar Beutner
cd7512a2ad
LibELF: Add support for loading objects with multiple data and text segments
...
This enables loading executables with multiple data and text segments. Also
it fixes loading executables where the text segment has a non-zero offset.
Example:
$ echo "main () {}" > test.c
$ gcc -Wl,-z,separate-code -o test test.c
$ objdump -p test
test: file format elf32-i386
Program Header:
PHDR off 0x00000034 vaddr 0x00000034 paddr 0x00000034 align 2**2
filesz 0x000000e0 memsz 0x000000e0 flags r--
INTERP off 0x00000114 vaddr 0x00000114 paddr 0x00000114 align 2**0
filesz 0x00000013 memsz 0x00000013 flags r--
LOAD off 0x00000000 vaddr 0x00000000 paddr 0x00000000 align 2**12
filesz 0x000003c4 memsz 0x000003c4 flags r--
LOAD off 0x00001000 vaddr 0x00001000 paddr 0x00001000 align 2**12
filesz 0x00000279 memsz 0x00000279 flags r-x
LOAD off 0x00002000 vaddr 0x00002000 paddr 0x00002000 align 2**12
filesz 0x00000004 memsz 0x00000004 flags r--
LOAD off 0x00002004 vaddr 0x00003004 paddr 0x00003004 align 2**12
filesz 0x00000100 memsz 0x00000124 flags rw-
DYNAMIC off 0x00002014 vaddr 0x00003014 paddr 0x00003014 align 2**2
filesz 0x000000c8 memsz 0x000000c8 flags rw-
2021-04-14 13:12:52 +02:00
Brendan Coles
8ad74684ea
LibELF: DynamicObject: Add rpath and runpath helpers
2021-03-22 17:46:05 +01:00
Brian Gianforcaro
069fd58381
LibELF: Convert more string literals to StringView literals.
...
Most of these won't have perf impact, but the optimization is
practically free, so no harm in fixing these up.
2021-02-24 14:45:34 +01:00
Andreas Kling
5d180d1f99
Everywhere: Rename ASSERT => VERIFY
...
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)
Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.
We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
b33a6a443e
LibELF: Inline DynamicObject::hash_section()
...
This was high up in profiles and gets almost entirely optimized out
when inlined, so let's do that.
2021-02-23 20:33:32 +01:00
Andreas Kling
22b8110554
LibELF: Avoid doing strlen() on everything while iterating GNU hash
...
It's a lot faster to iterate the GNU hash tables if we don't have to
compute the length of every symbol name before rejecting it anyway while
comparing the first character. :^)
2021-02-23 19:43:44 +01:00
Andreas Kling
46a94a9a9e
LibELF: Rename lookup_elf_symbol() => lookup_sysv_symbol()
...
We have two kinds of lookup, SYSV and GNU hash. Both are ELF lookups.
2021-02-23 19:43:44 +01:00
Andreas Kling
cc00df0f0f
LibELF: Avoid calling strlen() in DynamicObject::hash_section()
...
The long-term fix here is to make StringView recognize compile-time
string literals and do the right thing automatically.
2021-02-23 19:43:44 +01:00
Andreas Kling
d6af3302e8
LibELF: Don't recompute the same ELF hashes over and over
...
When performing a global symbol lookup, we were recomputing the symbol
hashes once for every dynamic object searched. The hash function was
at the very top of a profile (15%) of program startup.
With this change, the hash function is no longer visible among the top
stacks in the profile. :^)
2021-02-23 19:43:44 +01:00
Andreas Kling
37420f1baf
LibELF: Move ELF hash functions to their own file (and make constexpr)
2021-02-23 19:43:44 +01:00
Andreas Kling
f23b29f605
LibELF: Move DynamicObject::lookup_symbol() to DynamicLoader
...
Also simplify it by removing an unreachable code path.
2021-02-21 00:29:52 +01:00
Andreas Kling
a43910acc3
LibELF: Make SymbolLookupResult::address a VirtualAddress
...
Let's use a stronger type than void* for this since we're talking
specifically about a virtual address and not necessarily a pointer
to something actually in memory (yet).
2021-02-21 00:02:21 +01:00
Andreas Kling
1997d5de1a
LibELF: Make symbol lookup functions return Optional<Symbol>
...
It was very confusing how these functions used the "undefined" state
of Symbol to signal lookup failure. Let's use Optional<T> to make things
a bit more understandable.
2021-02-21 00:02:21 +01:00
Andreas Kling
ba1eea9898
LibELF+DynamicLoader: Rename DynamicObject::construct() => create()
2021-02-21 00:02:21 +01:00
Andreas Kling
01f1e480e5
LibELF: Fix various clang-tidy warnings
...
Remove a bunch of unused code, unnecessary const, and make some
non-object-specific member functions static.
2021-02-21 00:02:21 +01:00
Andreas Kling
0c0127dc3f
LibELF: Use StringView instead of "const char*" in dynamic linker code
...
There's no reason to use C strings more than absolutely necessary.
2021-02-20 22:29:12 +01:00
Andreas Kling
fa4c249425
LibELF+Userland: Enable RELRO for all userland executables :^)
...
The dynamic loader will now mark RELRO segments read-only after
performing relocations. This is pretty cool!
Note that this only applies to main executables so far,.
RELRO support for shared libraries will require some reorganizing
of the dynamic loader.
2021-02-18 18:55:19 +01:00
AnotherTest
09a43969ba
Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
...
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
Andreas Kling
41d8734288
LibELF: Use Optional<SymbolLookupResult> as a return type
...
Instead of storing a "found" state inside the result object.
2021-01-25 18:57:06 +01:00
Andreas Kling
a5de46684b
LibELF: Convert String::format() to String::formatted()
2021-01-25 18:57:06 +01:00
Andreas Kling
c5e52be5d4
LibELF: Convert dbgprintf() in DynamicObject class to dbgln()
2021-01-25 18:57:06 +01:00
asynts
acdcf59a33
Everywhere: Remove unnecessary debug comments.
...
It would be tempting to uncomment these statements, but that won't work
with the new changes.
This was done with the following commands:
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \;
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25 09:47:36 +01:00
Andreas Kling
13d7c09125
Libraries: Move to Userland/Libraries/
2021-01-12 12:17:46 +01:00