Commit graph

72 commits

Author SHA1 Message Date
Tim Schumacher 77f124c87a Toolchain: Remove references to -lm 2022-09-16 16:09:19 +00:00
Tim Schumacher f45238db0f Toolchain: Update to LLVM 15.0.0 2022-09-16 05:39:28 +00:00
Tim Schumacher 39477e923f Toolchain: Remove references to -ldl 2022-09-05 10:12:02 +01:00
Tim Schumacher a857b6297a Toolchain: Don't pass -lpthread when pthreads are requested
This is essentially a no-op since we have our replacement linker script,
but if we can skip over that entirely, why not?
2022-07-19 11:00:35 +01:00
Andrew Kaster 010190beb8 Toolchain: Remove workarounds for initializer_list and _aligned_alloc
These are no longer required to use libc++ on Serenity
2022-06-30 12:34:16 +01:00
Andrew Kaster efc1805b8f Toolchain: Create separate serenity xlocale support file 2022-06-30 12:34:16 +01:00
Andrew Kaster d889294036 Toolchain: Format llvm patches per new patch format
This removes the patch series 1/N comments, git version at the bottom of
the patch, and zeros out the original commit hash.
2022-06-30 12:34:16 +01:00
Tim Schumacher 242bbf1be4 Toolchain: Set '/' as default division character for binutils
While we are at it, regenerate the patch and remove some outdated parts
of the description.
2022-06-30 12:27:17 +01:00
Tim Schumacher 2df56f840f Revert "Toolchain: Load x64 executables at a higher address"
Now that the lower pages can be unmapped and more of the virtual
address range is available to us, we can actually use the default
mapping address of x86_64 again.

This reverts commit 292398b585.
2022-06-21 22:38:15 +01:00
Daniel Bertalan d0edf2627c Toolchain+Ports: Split the GCC patches
This shouldn't cause any breaking changes, so a toolchain rebuild is not
required.

As per Hendiadyoin's request, math errno is disabled by default, which
should enable some extra compiler optimizations in LibGL and LibSoftGPU
code that uses math functions heavily.

Co-Authored-By: Ali Mohammad Pur <mpfard@serenityos.org>
2022-05-19 20:17:10 +04:30
Daniel Bertalan 6cf260c7af Toolchain: Upgrade to GCC 12.1.0
This release brings support for various C++23 constructs like `if
consteval` and multidimensional subscript operators. Vectorization is
now enabled for O2 too, and `-ftrivial-auto-var-init` has been added
which can help us find and prevent security issues coming from
uninitialized variables.

Toolchain/Patches/gcc.patch is now significanly smaller as some unused,
autoconf-generated code has been removed.
2022-05-12 13:12:37 +02:00
Andrew Kaster 4334bd06b8 Toolchain: Enable LLVM Profile instrumentation
Add a patch to let llvm's InstrProfiling modules know serenity supports
all the Unix-y features required to make -fprofile-instr-generate and
-fcoverage-mapping work properly on target.
2022-05-02 01:46:18 +02:00
Daniel Bertalan 01b31d9858 Toolchain+Ports: Update LLVM to 14.0.1
Besides a version bump, the following changes have been made to our
toolchain infrastructure:
- LLVM/Clang is now built with -march=native if the host compiler
  supports it. An exception to this is CI, as the toolchain cache is
  shared among many different machines there.
- The LLVM tarball is not re-extracted if the hash of the applied
  patches doesn't differ.
- The patches have been split up into atomic chunks.
- Port-specific patches have been integrated into the main patches,
  which will aid in the work towards self-hosting.
- <sysroot>/usr/local/lib is now appended to the linker's search path by
  default.
- --pack-dyn-relocs=relr is appended to the linker command line by
  default, meaning ports take advantage of RELR relocations without any
  patches or additional compiler flags.

The formatting of LLVM port's package.sh has been bothering me, so I
also indented the arguments to the CMake invocation.
2022-04-23 10:43:32 -07:00
James Mintram 11bcde0bbd Toolchain: Add a gcc patch to fix linker error on M1 host 2022-03-31 19:22:53 -07:00
Daniel Bertalan 5550905c00 Toolchain: Update gdb to 11.2 2022-03-24 20:08:08 -07:00
Tim Schumacher 2788d46ae0 Toolchain: Make wint_t unsigned for Clang 2022-03-19 00:11:45 +00:00
Tim Schumacher 5d0869d5ca Toolchain: Enable IFUNC support for GCC 2022-03-19 00:11:45 +00:00
Tim Schumacher b55a3a504e Toolchain: Enforce correct sizes for size_t and ptrdiff_t 2022-03-19 00:11:45 +00:00
Brian Gianforcaro d386d3946a Toolchain: Fix QEMU build with latest gcc by disabling -fcf-protection
I noticed after upgrading my machine that the QEMU is no longer building
due to GCC enabling `-fcf-protection` by default, even for targets that
don't support it.

The included patch came from the QEMU development list, but hasn't be
included in any patch releases at the time of writing.
https://lore.kernel.org/all/20220208211937.79580-1-vineetg@rivosinc.com/

Until QEMU patches, lets fix it on our end by patching before we build.
2022-02-13 17:11:53 +00:00
Daniel Bertalan 85780fafcd Toolchain: Update binutils to version 2.38
This version comes with general fixes and, more importantly, introduces
support for the packed RELR relocation format.
2022-02-11 18:07:53 +01:00
Daniel Bertalan ad649c48da Toolchain: Backport support for the mold linker
The `-fuse-ld=mold` flag was only added in the not-yet-released GCC 12.

Cherry-picked from the following upstream commit:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=ad964f7eaef9c03ce68a01cfdd7fde9d56524868
2022-01-24 10:41:47 +00:00
Daniel Bertalan 9e8c4bb072 Toolchain: Enable the -rdynamic flag in the gcc driver
Although we handle it in the linker spec file, gcc will actually reject
this argument unless it's also enabled in the option file.

CMake adds this flag if the minimum required version is 3.3 or less (see
CMP0065), so old projects would fail to compile because of this
unrecognized option.
2022-01-12 14:54:12 +01:00
Daniel Bertalan b19cc3cdcb Toolchain: Backport --update-section support to llvm-objcopy
This commit backports the LLVM commit that adds support for the
`--update-section` flag to llvm-objcopy. We use this feature of GNU
objcopy to embed the symbol map in the kernel.

The corresponding LLVM Phabricator Differential Revision can be found
here: https://reviews.llvm.org/D112116

This patch is identical to the upstream commit, except for two hunks
that had to be changed as they didn't apply cleanly.
2022-01-10 09:55:45 +03:30
Daniel Bertalan 20e29c403e Toolchain: Fix macOS build failure due to a malformed patch
Discord user aesophor pointed out that the GCC toolchain fails to build
on macOS, and traced the issue back to 41ea37f2, which is the latest
change to `gcc.patch`. Similarly, when I tried to run BuildIt.sh in the
`--dev` mode, `git apply` complained about the patch being malformed.

I regenerated the patch by manually applying the changes of 41ea37f2 on
top of a known good GCC source tree, and I sent the new file to them.
They reported that this fixed the build issue they were having.
2022-01-09 14:15:24 +01:00
Martin Bříza 41ea37f25a Toolchain/GCC: Declare we don't have memalign
I'm not even sure if this is a hack. However, we don't implement
memalign so it's necessary to tell GCC so it doesn't go looking for it
in their implementation of `new`
2022-01-07 18:38:32 +01:00
Daniel Bertalan 84c6d6649e Toolchain: Fix building the aarch64 toolchain
The `aarch64/t-aarch64` makefile fragment needs to be included for the
aarch64-specific parts of GCC to be built. Before 738e52da5, this was
done implicitly, but now it is not. This caused the following error when
building the toolchain: "aarch64-builtins.o: No such file or directory".
2022-01-04 17:40:09 +00:00
Andrew Kaster c5898806d2 Toolchain: Use Platform/SerenityOS.cmake in LLVM toolchain build
By setting CMAKE_MODULE_PATH in the LLVM initial cache scripts, we can
make the "SerenityOS" CMAKE_SYSTEM_NAME usable in the builds of
compiler-rt, libunwind, libcxxabi and libcxx.

This simplifies some toolchain patches and brings the cross-compiler
patches closer to the Port's patches, and closer to something
upstreamable.
2022-01-03 11:08:45 +00:00
Daniel Bertalan 738e52da56 Toolchain: Link libgcc_s on an as-needed basis
If we pass `-lgcc_s` explicitly to the linker, it will be added as a
dependency even if no functions are used from it. This behavior is not
consistent with other systems. GCC can already handle passing the
correct flags, so let's rely on that instead.

As an added benefit, we now get support for the `-static-libgcc` flag;
and `-static-pie` will no longer mistakenly link us against the dynamic
version of libgcc.

No toolchain rebuild is required.
2021-12-16 21:27:03 +02:00
Daniel Bertalan b1f6bfca7f Toolchain/Clang: Support using libstdc++ as the C++ standard library
This will come in handy if we want to use the LLVM port with a GNU host
compiler.

As of version 13, libc++ uses `__attribute__((using_if_exists))` to
import global LibC functions into the `std` namespace, which allows some
symbols to be absent. GCC does not support this attribute, so it fails
to build libc++ due to some obscure `wchar.h` functions. This means that
cross-compiling libc++ is not possible; and on-target builds would be
tedious, so we'll be better off using the toolchain's `libstdc++`.
2021-11-28 09:38:57 -08:00
Daniel Bertalan ce3b219021 Toolchain/Clang: Allow setting a default unwind library
This will let us use `libgcc` for unwinding when we build the LLVM port
with the GNU toolchain.
2021-11-28 09:38:57 -08:00
Daniel Bertalan ea8335cda1 Toolchain/Clang: Pick up includes when running inside Serenity
The toolchain should work without setting `--sysroot` when we build
inside SerenityOS.
2021-11-28 09:38:57 -08:00
Daniel Bertalan 91546f42f3 Toolchain/Clang: Add support for -static-libstdc++
This option is already used by our GNU toolchain to avoid creating a
circular dependency between LibC and `lib(std)c++`.
2021-11-28 09:38:57 -08:00
Tim Schumacher 292398b585 Toolchain: Load x64 executables at a higher address
Serenity defines a protected range of memory that must not be mmapped,
and is apparently reserved for kernel tasks. In this case, the protected
range is anything below 0x800000.

However, in its default setting, binutils chooses the memory address
0x400000 as the mapping address for executables that do not have PIE
enabled, resulting in mmap being unable to map the file unless the load
address has been overwritten at link time or if it's a PIE.

To mitigate this, move the default base address somewhere outside of
that range (and preferably not anywhere close near the beginning of the
useable virtual memory space, to avoid running into it during sequential
allocations).
2021-11-14 22:25:15 +01:00
Daniel Bertalan 061fa8a1ca Toolchain: Add aligned allocation support to libc++
Now that we have `_aligned_malloc` and `_aligned_free`, we can finally
enable C++17 aligned allocation support.
2021-11-14 16:46:21 +00:00
Daniel Bertalan 06fc64be13 Toolchain+Meta: Update LLVM version to 13.0.0
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-17 17:09:58 +01:00
Tim Schumacher dea43d88e7 Toolchain: Remove breaking mbstate_t define from clang 2021-09-17 00:14:57 +00:00
Nico Weber 1ed1a57707 Meta: Make serenity.sh rebuild-toolchain aarch64 clang work 2021-09-07 20:29:22 +01:00
Idan Horowitz 783a58dbc7 Toolchain: Build aarch64-gdb for cross-debugging on x86 2021-09-07 12:58:46 +02:00
Nico Weber 7052f403c8 Toolchain: Enough to make rebuild-toolchain aarch64 work
The gcc patch might not be completely correct, but at least the
toolchain completes building.
2021-08-28 14:43:07 +01:00
Nico Weber 61b6f69947 Toolchain: Regenerate binutils.patch and gcc.patch
I locally modified Meta/serenity.sh to pass `--dev` to BuildIt.sh
in build_toolchain(). Then I ran `Meta/serenity.sh rebuild-toolchain`,
cd'd into Toolchain/Tarballs/binutils-2.37, `git add`ed unadded files in
`git status`, and then ran `git diff > ../../Patches/binutils.patch`.
Then I did the same for Toolchain/Tarballs/gcc-11.2.0 (and was careful
not to `git add` serenity-kernel.h, since that's created by
Toolchain/BuildIt.sh).

No behavior change. This just rewrites the patch like git writes it.
2021-08-28 14:43:07 +01:00
Gunnar Beutner a29c18f969 Toolchain+Ports: Let -nostdlib make us not link against libgcc_s
For now this is not a mandatory toolchain rebuild.
2021-08-08 16:41:51 +02:00
Daniel Bertalan 15e217ea68 Toolchain: Add LLVM patch and script for building it
This contains all the bits and pieces necessary to build a Clang binary
that will correctly compile SerenityOS.

I had some trouble with getting LLVM building with a single command, so
for now, I decided to build each LLVM component in a separate command
invocation. In the future, we can also make the main llvm build step
architecture-independent, but that would come with extra work to make
library and include paths work.

The binutils build invocation and related boilerplate is duplicated
because we only use `objdump` from GNU binutils in the Clang toolchain,
so most features can be disabled.
2021-08-08 10:55:36 +02:00
Gunnar Beutner 5df8c274bb Toolchain+Ports: Fix building ports on x86_64
Fixes #8377.
2021-07-28 21:28:31 +02:00
Gunnar Beutner 9c431ae7ef Toolchain: Update GCC to version 11.2.0 2021-07-28 21:28:31 +02:00
Gunnar Beutner cfeffbe524 Toolchain: Update binutils to version 2.37 2021-07-28 21:28:31 +02:00
Gunnar Beutner 12bfc7b3fc Toolchain+Ports: Ignore -arch on macOS M1 hosts
CMake specifies -arch arm64 for our toolchain. Unfortunately that's an
option GCC only understands when built for macOS. This causes the build
to fail.

I haven't been able to get CMake to not specify that option so this adds
a dummy option to GCC.
2021-07-24 14:04:13 +02:00
modmuss50 036f2a14ed Toolchain: Fix building toolchain on arm64 macs
This patch is based off:
https://github.com/osx-cross/homebrew-avr/pull/248 and
https://github.com/riscv/riscv-gnu-toolchain/issues/800
2021-07-08 16:07:14 +02:00
Gunnar Beutner d86275d271 Kernel+Toolchain: Remove the kernel-specific toolchain
This is no longer necessary now that the kernel doesn't use libsupc++
anymore.
2021-07-06 19:08:22 +02:00
Gunnar Beutner 988dfa7f33 Toolchain+Ports: Fix building binutils on FreeBSD
This imports the upstream patch from
https://sourceware.org/bugzilla/show_bug.cgi?id=27382

Fixes #7407.
2021-06-07 09:51:12 +02:00
Gunnar Beutner b223233b15 Toolchain+Ports: Skip link tests for libstdc++v3
This makes stdlib.h and stdio.h functions available in the std
namespace for C++.

libstdc++v3's link tests can fail if you don't have an up-to-date
build directory, for example:

1. Have libc with missing _Exit symbol because you haven't done
   a build since that was added.

2. Run toolchain rebuild. libstdc++v3's configure script will
   realize that it can do link tests in general but will fail
   later on when it tries to link a program that tests for _Exit.

Even though this is a toolchain patch this does not necessarily
require rebuilding the toolchain right away. This is only required
once we start using any of these new members in the std namespace,
e.g. for ports.
2021-05-09 15:35:01 +02:00