summaryrefslogtreecommitdiff
path: root/Userland/DynamicLoader/main.cpp
AgeCommit message (Collapse)Author
2021-10-17Everywhere: Make some symbols `__attribute__((used))` for LTODaniel Bertalan
With these changes, the userland builds correctly with Clang's ThinLTO enabled.
2021-07-27DynamicLoader+LibELF: Move self-relocation code into a separate fileGunnar Beutner
2021-07-22DynamicLoader: Don't truncate dynamic section address on x86_64Andreas Kling
2021-07-14LibC: Use our implementation of `crti.o` and `crtn.o`Daniel Bertalan
We have had these for quite a while, but we didn't compile them, and used GCC's version instead. Clang does not come with these, so we have to provide our own implementation. Our implementation follows what `musl` and `FreeBSD` do, so this should work fine, even if documentation can hardly be found for them.
2021-07-13DynamicLoader: Add RELA support for self-relocationsGunnar Beutner
GCC doesn't seem to rely on those to work, but Clang does.
2021-07-11DynamicLoader+LibC: Make _start a naked functionHendiadyoin1
2021-07-10Kernel+Userland: Make the stack alignment comply with the System V ABIGunnar Beutner
The System V ABI for both x86 and x86_64 requires that the stack pointer is 16-byte aligned on entry. Previously we did not align the stack pointer properly. As far as "main" was concerned the stack alignment was correct even without this patch due to how the C++ _start function and the kernel interacted, i.e. the kernel misaligned the stack as far as the ABI was concerned but that misalignment (read: it was properly aligned for a regular function call - but misaligned in terms of what the ABI dictates) was actually expected by our _start function.
2021-07-07DynamicLoader: Don't use LibELF to do the initial relocationsGunnar Beutner
Using LibELF to do the initial relocations doesn't work when building SerenityOS with Clang. We seem to be accessing a global symbol that hasn't been relocated yet somewhere along the path to ELF::DynamicObject::create().
2021-07-02DynamicLoader: Use string view literal to remove a allocation on startupBrian Gianforcaro
The ""sv operator switches a const char* to String conversion into just a StringView literal.
2021-06-29DynamicLoader: Implement self relocations for x86_64Gunnar Beutner
2021-06-28Kernel+LibELF: Add support for validating and loading ELF64 executablesGunnar Beutner
2021-05-07DynamicLoader: Remove math functionality in favor of -lgccGunnar Beutner
This links the dynamic linker against libgcc.a instead of having our own copy of the math functions. For now we need to specify -fbuilding-libgcc as a hack to work around a bug with the -nodefaultlibs flag. Once everyone is on the latest toolchain version this can be removed.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-18LibC+LibELF: Implement support for the dl_iterate_phdr helperGunnar Beutner
This helper is used by libgcc_s to figure out where the .eh_frame sections are located for all loaded shared objects.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...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-21LibELF+DynamicLoader: Rename DynamicObject::construct() => create()Andreas Kling
2021-01-25DynamicLoader: Remove some unnecessary #includesAndreas Kling
2021-01-25DynamicLoader: Remove unused debugging macrosAndreas Kling
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
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-09Loader.so+LibELF: Do not read environment variables if AT_SECURE is setItamar
AT_SECURE is set in the auxiliary vector when we execute setuid/setgid programs. In those cases, we do not want to read environment variables that influence the logic of the dynamic loader, as they can be controlled by the user.
2021-01-03Kernel+Loader.so: Allow dynamic executables without an interpreterWilliam Marlow
Commit a3a9016701e487a5ca92d83b8cff179a190cdeb2 removed the PT_INTERP header from Loader.so which cleaned up some kernel code in execve. Unfortunately it prevents Loader.so from being run as an executable
2021-01-03Loader.so+LibELF: Move most of Loader.so's logic into ELF::DynamicLinkerWilliam Marlow
Loader.so now just performs the initial self relocations and static LibC initialisation before handing over to ELF::DynamicLinker::linker_main to handle the rest of the process. As a trade-off, ELF::DynamicLinker needs to be explicitly excluded from Lagom unless we really want to try writing a cross platform dynamic loader
2020-12-31DynamicLoader: Handle Loader.so being invoked directly as an executableWilliam Marlow
Loader.so is an actual executable, as well as the interpreter for dynamic libraries. Currently launching Loader.so as a standalone executable results in an obsucre crash as it tries to load itself over itself. Now we at least print a helpful message saying that you're doing the wrong thing and exit gracefully. In future we may wish to allow users to specify additional options to learn more about what's going on during dynamic linking, such as ld-linux.so.2 on Linux.
2020-12-26LibC: Fix some incorrect printf usagesSahan Fernando
2020-12-25LibELF: Move AuxiliaryValue into the ELF namespaceAndreas Kling
2020-12-25LibELF: Remove ELF::Loader and move everyone to ELF::ImageAndreas Kling
This commit gets rid of ELF::Loader entirely since its very ambiguous purpose was actually to load executables for the kernel, and that is now handled by the kernel itself. This patch includes some drive-by cleanup in LibDebug and CrashDaemon enabled by the fact that we no longer need to keep the ref-counted ELF::Loader around.
2020-12-24Loader: Support loading non-position independent executablesItamar
2020-12-24DynamicLoader: Call libc's exit when exitting, to flush standard streamsSahan Fernando
2020-12-21Everywhere: Switch from (void) to [[maybe_unused]] (#4473)Lenny Maiorani
Problem: - `(void)` simply casts the expression to void. This is understood to indicate that it is ignored, but this is really a compiler trick to get the compiler to not generate a warning. Solution: - Use the `[[maybe_unused]]` attribute to indicate the value is unused. Note: - Functions taking a `(void)` argument list have also been changed to `()` because this is not needed and shows up in the same grep command.
2020-12-14Loader: Don't re-load self-dependant librariesItamar
2020-12-14UserspaceEmulator: Support dynamically loaded programsItamar
When loading dynamic objects, the emulator loads the interpreter, generates an auxiliary vector and starts executing the loader. Additionally, this commits also makes the MallocTracer and backtrace symbolication work for dynamically loaded programs.
2020-12-14Loader: Take main program name from auxiliary vectorItamar
2020-12-14Loader: Stabilize loader & Use shared libraries everywhere :^)Itamar
The dynamic loader is now stable enough to be used everywhere in the system - so this commit does just that. No More .a Files, Long Live .so's!
2020-12-14Loader: Add dynamic loader programItamar
The dynamic loader exists as /usr/lib/Loader.so and is loaded by the kernel when ET_DYN programs are executed. The dynamic loader is responsible for loading the dependencies of the main program, allocating TLS storage, preparing all loaded objects for execution and finally jumping to the entry of the main program.