Core part of this change is cleaning up Mold from UBSan alignment errors.
Following approach inspired by LLVM's ELFTypes is done here:
1. Introduce generic Packed class acting as proxy for unaligned aggregated value.
Every access to such value through proxy is secured by memcpy call.
2. Replace plain struct members with Packed members wherever it matters.
3. Use explicit castings through Packed type for misaligned loads.
For more background please check: https://github.com/rui314/mold/discussions/477
Signed-off-by: Dawid Jurczak <dawid_jurek@vp.pl>
I didn't want to write a Python one-liner in the Makefile, but it
looks like it is in practice one of the most portable way to compute a
relative path.
https://github.com/rui314/mold/pull/425
I think we don't need to create a tar file for binary distribution
for each Linux distro. Instead, we can create mold executable that
works on most Linux machines.
The new script, build-dynamic.sh, creates a mold executable with
libmimalloc, libtbb, libstdc++ and libcrypto begin linked statically.
I don't have a concern as to the availability of other libraries
(libc, libm, libz and librt) because they essentially exists on any
system.
It looks like setting __TBB_DYNAMIC_LOAD_ENABLED to 0 is not enough
to make TBB not to call dlopen(). We need to unset __TBB_WEAK_SYMBOLS_PRESENT
as well.
Fixes https://github.com/rui314/mold/issues/348
When building with SYSTEM_MIMALLOC=1, linking with (assuming
shared) '-lmimalloc' is not enough to override C++ new/delete
with mimalloc versions, and 'mimalloc-new-delete.h' should be
included from one (and the only) translation unit as well.
Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
The LTO plugin API support is still in progress, but with this change,
mold can link itself with `-flto` with both GCC and Clang.
Since mold now supports LTO natively, I removed the fallback mechanism
to ld.bfd or ld.lld that I implemented in
a5029d19a8.
Fixes https://github.com/rui314/mold/issues/181
Ensure that all xxhash functions are inlined. Since it eliminates
external dependencies, we no longer have to link against libxxhash.a
or libxxhash.so at all.
`SYSTEM_XXHASH` Makefile variable has been removed because it is
no longer relevant.
We use only `XXH3_64bits` from libxxhash, and it looks like the function
is an inline function, so there's actually no runtime dependency against
libxxhash.so.
Before the change calls to $(shell git rev-parse) and $(shell pkg-config)
happened on every mold's .o file (as make's "A = $(B)" performs late
expansion).
After the change $(shell) calls are evaluated once with "A := $(B)"
assignment.
Noticed by chance when 'make' was complaining about missing pkg-config
tool on each build step.
Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
It is up to packager's choice to create mold as a position-independent
executable or not. If you want, pass `LDFLAGS=-fpie` and `CXXFLAGS=-fPIE`
to `make`.
Our Makefile didn't allow overriding CFLAGS, CXXFLAGS or LDFLAGS
because we add mandatory options to these variables. It is contrary
to conventions Makefile conventions explained here.
https://www.gnu.org/prep/standards/html_node/Command-Variables.html#Command-Variables
In this patch, I separated mandatory options to MOLD_CXXFLAGS and
MOLD_LDFLAGS so that users can freely override CFLAGS, CXXFLAGS and
LDFLAGS.
I also removed `DEBUG`, `ASAN` and `TSAN` variables from the Makefile
because we can now simply pass `CXXFLAGS="-g -O0"` or
`CXXFLAGS=-fsanitize=...` instead.
libtbb.so contains undefined symbols on Gentoo with musl libc.
Because we are not using such symbols at runtime, and symbols are
resolved lazily, mold would work fine as long as we can build it.
By passing `-allow-shlib-undefined`, we can build mold.
Fixes https://github.com/rui314/mold/issues/281
Some operating systems, like NetBSD, don't have a separate library for
dlopen(3). They have dl* functions in their libc.
Signed-off-by: Masatake Daimon <pho@NetBSD.org>
mold does not have to be built with clang/clang++, so don't use
these compiler frontends.
mold also doesn't have be built with g++ (GNU C++ compiler).
We use `c++` command instead.
Fixes https://github.com/rui314/mold/issues/261