summaryrefslogtreecommitdiff
path: root/Userland/DynamicLoader
AgeCommit message (Collapse)Author
2022-07-21LibPthread: Implement named semaphoresIdan Horowitz
Note that as part of this commit semaphore.cpp is excluded from the DynamicLoader, as the dynamic loader does not build with pthread.cpp which semaphore.cpp uses.
2022-07-19LibPthread: Move the pthread and semaphore implementation to LibCTim Schumacher
This additionally adds some compatibility code to redirect linking attempts for LibPthread to LibC instead.
2022-05-12LibC+Kernel: Prevent string functions from calling themselvesDaniel Bertalan
Most of the string.h and wchar.h functions are implemented quite naively at the moment, and GCC's pattern recognition pass might realize what we are trying to do, and transform them into libcalls. This is usually a useful optimization, but not when we're implementing the functions themselves :^) Relevant discussion from the GCC Bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102725 This prevents the infamous recursive `strlen`. A more proper fix would be writing these functions in assembly. That would likely give a small performance boost as well ;)
2022-05-02Meta+Userland: Add ENABLE_USERSPACE_COVERAGE_COLLECTION CMake optionAndrew Kaster
This option sets -fprofile-instr-generate -fcoverage-mapping for Clang builds only on almost all of Userland. Loader and LibTimeZone are exempt. This can be used for generating code coverage reports, or even PGO in the future.
2022-05-02DynamicLoader: Remove stale FIXME for removing -nodefaultlibsAndrew Kaster
The FIXME says "Remove after next toolchain update" and I'm very certain we've had some :tool: :chain: in the last 7 months.
2022-05-01LibC: Implement a faster memset routine for x86-64 in assemblyDaniel Bertalan
This commit addresses the following shortcomings of our current, simple and elegant memset function: - REP STOSB/STOSQ has considerable startup overhead, it's impractical to use for smaller sizes. - Up until very recently, AMD CPUs didn't have support for "Enhanced REP MOVSB/STOSB", so it performed pretty poorly on them. With this commit applied, I could measure a ~5% decrease in `test-js`'s runtime when I used qemu's TCG backend. The implementation is based on the following article from Microsoft: https://msrc-blog.microsoft.com/2021/01/11/building-faster-amd64-memset-routines Two versions of the routine are implemented: one that uses the ERMS extension mentioned above, and one that performs plain SSE stores. The version appropriate for the CPU is selected at load time using an IFUNC.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-01-23DynamicLoader+LibC+LibTimeZone: Include LibTimeZone sources in LibCTimothy Flynn
LibTimeZone will be needed directly within LibC for functions such as localtime(). This change adds LibTimeZone directly within LibC, so that LibTimeZone isn't its own .so library anymore. LibTimeZone itself is compiled as an object library to make it easier to give it generator-specific compilation flags.
2021-10-17Toolchain+Meta: Update LLVM version to 13.0.0Daniel Bertalan
This commit updates the Clang toolchain's version to 13.0.0, which comes with better C++20 support and improved handling of new features by clang-format. Due to the newly enabled `-Bsymbolic-functions` flag, our Clang binaries will only be 2-4% slower than if we dynamically linked them, but we save hundreds of megabytes of disk space. The `BuildClang.sh` script has been reworked to build the entire toolchain in just three steps: one for the compiler, one for GNU binutils, and one for the runtime libraries. This reduces the complexity of the build script, and will allow us to modify the CI configuration to only rebuild the libraries when our libc headers change. Most of the compile flags have been moved out to a separate CMake cache file, similarly to how the Android and Fuchsia toolchains are implemented within the LLVM repo. This provides a nicer interface than the heaps of command-line arguments. We no longer build separate toolchains for each architecture, as the same Clang binary can compile code for multiple targets. The horrible mess that `SERENITY_CLANG_ARCH` was, has been removed in this commit. Clang happily accepts an `i686-pc-serenity` target triple, which matches what our GCC toolchain accepts.
2021-10-17Everywhere: Make some symbols `__attribute__((used))` for LTODaniel Bertalan
With these changes, the userland builds correctly with Clang's ThinLTO enabled.
2021-09-15Meta: Switch to a SuperBuild that splits host and target buildsAndrew Kaster
Replace the old logic where we would start with a host build, and swap all the CMake compiler and target variables underneath it to trick CMake into building for Serenity after we configured and built the Lagom code generators. The SuperBuild creates two ExternalProjects, one for Lagom and one for Serenity. The Serenity project depends on the install stage for the Lagom build. The SuperBuild also generates a CMakeToolchain file for the Serenity build to use that replaces the old toolchain file that was only used for Ports. To ensure that code generators are rebuilt when core libraries such as AK and LibCore are modified, developers will need to direct their manual `ninja` invocations to the SuperBuild's binary directory instead of the Serenity binary directory. This commit includes warning coalescing and option style cleanup for the affected CMakeLists in the Kernel, top level, and runtime support libraries. A large part of the cleanup is replacing USE_CLANG_TOOLCHAIN with the proper CMAKE_CXX_COMPILER_ID variable, which will no longer be confused by a host clang compiler.
2021-08-28CMake: Let `Meta/serenity.sh run aarch64` make it past cmakeNico Weber
This adds just enough scaffolding to make cmake succeed. The build falls over immediately.
2021-08-12LibC+DynamicLoader: Prevent GCC from removing null checksDaniel Bertalan
GCC implements `fputc`, `fputs` and `fwrite` as builtin functions, whose `FILE*` argument is implicitly marked `__attribute__((nonnull))`. This causes our `VERIFY(stream)` statements to be removed. This does not happen with Clang, as they do not use the `nonnull` attribute in this way.
2021-08-08DynamicLoader: Make sure we don't link against libgcc_sGunnar Beutner
This bug was reintroduced by the removal of -fbuilding-gcc.
2021-08-08Meta: Add Clang support to the CMake build scriptsDaniel Bertalan
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-04DynamicLoader: Remove -fbuilding-libgcc hackGunnar Beutner
This won't be necessary anymore after a toolchain rebuild.
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-07-01DynamicLoader: Remove obsolete commentGunnar Beutner
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-27Userland: Port UBSAN implementation to userspaceAndrew Kaster
Take Kernel/UBSanitizer.cpp and make a copy in LibSanitizer. We can use LibSanitizer to hold other sanitizers as people implement them :^). To enable UBSAN for LibC, DynamicLoader, and other low level system libraries, LibUBSanitizer is built as a serenity_libc, and has a static version for LibCStatic to use. The approach is the same as that taken in Note that this means now UBSAN is enabled for code generators, Lagom, Kernel, and Userspace with -DENABLE_UNDEFINED_SANTIZER=ON. In userspace however, UBSAN is not deadly (yet). Co-authored-by: ForLoveOfCats <ForLoveOfCats@vivaldi.net>
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-05-03DynamicLoader: Fix compiler warningGunnar Beutner
math.cpp: In function 'int64_t __moddi3(int64_t, int64_t)': math.cpp:168:13: error: 'r' may be used uninitialized [-Werror=maybe-uninitialized] 168 | return ((int64_t)r ^ s) - s; // negate if s == -1 | ^~~~~~~~~~
2021-04-29Tests: Unify LibC tests to single location.Brian Gianforcaro
In a1720eed2a8e744f2cd6d99adae4dff1fbab309e I added this new test, but missed that there were already some "unit tests" for LibC over in Userland/Tests/LibC. So lets unify these two locations.
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-21LibC: Setup a unit test harness for LibC, add ctime_r / asctime_r tests.Brian Gianforcaro
LibC is no different than any other code, it should be unit tested where appropriate / possible.
2021-04-20LibC+LibPthread: Implement function forwarding for libpthreadGunnar Beutner
GCC will insert various calls to pthread functions when compiling C++ code with static initializers, even when the user doesn't link their program against libpthread explicitly. This is used to make static initializers thread-safe, e.g. when building a library that does not itself use thread functionality and thus does not link against libpthread - but is intended to be used with other code that does use libpthread explicitly. This makes these symbols available in libc.
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-21LibC: Add x86_64 RegistersHendiadyoin1
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-02-25LibC: Add x86_64 implementation of setjmp() and longjmp()Andreas Kling
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-02-08Revert "DynamicLoader: Remove unnecessary math functions"Andreas Kling
This reverts commit b1f1f5afcf8f3b8a3ca10bcb6aefa05fbb2b35be. Unfortunately this broke dbgln() in the dynamic loader. We need to figure out how to link libgcc into it properly.
2021-02-07DynamicLoader: Remove unnecessary math functionsAndreas Kling
These are provided by libgcc.
2021-02-05Userland: Add LibSystem and funnel all syscalls through itAndreas Kling
This achieves two things: - Programs can now intentionally perform arbitrary syscalls by calling syscall(). This allows us to work on things like syscall fuzzing. - It restricts the ability of userspace to make syscalls to a single 4KB page of code. In order to call the kernel directly, an attacker must now locate this page and call through it.
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-12Libraries: Move to Userland/Libraries/Andreas Kling
2021-01-09Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything: The modifications in this commit were automatically made using the following command: find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\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