1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-05 00:57:08 +03:00
Commit Graph

3457 Commits

Author SHA1 Message Date
Rui Ueyama
b2ef045c03 Style fix 2022-01-24 07:56:19 +09:00
Rui Ueyama
e83d1616c8 Update the man page 2022-01-24 07:49:41 +09:00
Rui Ueyama
d196ec43e6
Merge pull request #299 from sicherha/fix-glibcxx-assertion
Fix out-of-bounds assertion on aarch64 with `_GLIBCXX_ASSERTIONS` enabled
2022-01-24 07:13:12 +09:00
Christoph Erhardt
03ba8f9325 Fix out-of-bounds error on aarch64 with _GLIBCXX_ASSERTIONS enabled
While an iterator may point beyond the last element of a `std::span`, a
pointer may not.

Fixes #298.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-01-23 21:48:55 +01:00
Rui Ueyama
79f83561bd
Merge pull request #296 from sicherha/pass-cxxflags-to-tbb
Pass `CXXFLAGS` to bundled tbb
2022-01-24 00:36:04 +09:00
Christoph Erhardt
0653716408 Pass CXXFLAGS to bundled tbb
This makes work easier for distributions that specify custom hardened
compiler flags.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-01-23 16:03:53 +01:00
Rui Ueyama
6fb64656b9 Bump mold version to 1.0.2 2022-01-23 17:19:40 +09:00
Rui Ueyama
21dd8834d3 Do not create mold as a PIE by default
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`.
2022-01-23 16:22:15 +09:00
Rui Ueyama
c6dc8da704 Tidy up Makefile
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.
2022-01-23 15:45:48 +09:00
Rui Ueyama
f8e7b157c7 Fix a test 2022-01-23 11:41:19 +09:00
Rui Ueyama
9ddc188f97 [ELF] Improve an error message 2022-01-23 11:33:23 +09:00
Rui Ueyama
6671d5b03b Style fix 2022-01-23 11:33:23 +09:00
Rui Ueyama
10e666ce0f Update the man page 2022-01-23 11:33:22 +09:00
Rui Ueyama
27f5b12ee2
Merge pull request #292 from ADKaster/posix-headers
Explicitly include sys/select and sys/time
2022-01-23 11:25:03 +09:00
Rui Ueyama
f7b00b7adb
Merge pull request #291 from BertalanD/relr-fix
[ELF]: Fix issues with relr relocations
2022-01-23 11:24:10 +09:00
Andrew Kaster
ca3d5f49d2 Explicitly include sys/select and sys/time
The SerenityOS LibC doesn't leak the definitions of select(2) or struct
timeval into other POSIX headers. Manually include these headers in
elf/subprocess.cc where they are used for better compatibility.

Signed-off-by: Andrew Kaster <akaster@serenityos.org>
2022-01-22 15:04:57 -07:00
Daniel Bertalan
1d0a854957 [ELF] Fix encoding of .relr.dyn bitmap entries
Before this change, all bitmap entries ended up containing the value
0x3 (as `pos[i] - base` is guaranteed to be a multiple of the word
size). This expression needs to produce the offset in words from the
base address, so we need to *divide* by the word size.

Signed-off-by: Daniel Bertalan <dani@danielbertalan.dev>
2022-01-22 18:20:02 +01:00
Daniel Bertalan
d1151a9528 [ELF] Create dynamic entries for .relr.dyn
If the corresponding DT_RELR, DT_RELRSZ and DT_RELRENT dynamic entries
are not present, dynamic linkers won't pick up the relocations encoded
in .relr.dyn.

Signed-off-by: Daniel Bertalan <dani@danielbertalan.dev>
2022-01-22 18:19:55 +01:00
Rui Ueyama
1ae6c55c52 Update man page 2022-01-22 20:59:28 +09:00
Rui Ueyama
f7ce2f6748 Remove a useless assignment 2022-01-22 20:59:28 +09:00
Rui Ueyama
c6b89f9766 Remove unnecessary #include 2022-01-22 13:11:21 +09:00
Rui Ueyama
8eae808223 Revert "[ELF] Compile an Aho-Corasick tree into a DFA"
This reverts commit 31ca2cc2ae
because looks like it's slower than before.
2022-01-22 12:37:40 +09:00
Rui Ueyama
31ca2cc2ae [ELF] Compile an Aho-Corasick tree into a DFA 2022-01-22 12:35:49 +09:00
Rui Ueyama
5cf2328a8b [ELF] Support negation and range in glob pattern 2022-01-22 11:01:55 +09:00
Rui Ueyama
ac93f8dfd1 Add comments 2022-01-22 10:23:11 +09:00
Rui Ueyama
28c36e58b7 Revert "Fix a build issue on Gentoo with musl libc"
This reverts commit 2cc85cc21d because
it didn't fix the Gentoo's issue.

https://github.com/rui314/mold/issues/281
2022-01-22 00:52:17 +09:00
Rui Ueyama
ba6ccd109c [ELF] Do not use GlobMatcher if all version patterns are simple 2022-01-21 23:47:54 +09:00
Rui Ueyama
e9a5d1cee3 [ELF] Handle glob patterns directly instead of converting them to regex
Converting a glob pattern to a regex is fragile, and std::regex is slow.
So we should handle glob patterns ourselves.
2022-01-21 23:32:27 +09:00
Rui Ueyama
4ee3062054 [ELF] Fix version pattern matching 2022-01-21 21:27:49 +09:00
Rui Ueyama
3f4e570320 Simplify 2022-01-21 20:59:19 +09:00
Rui Ueyama
d0c1c4db19 [ELF] Use Aho-Corasick algo to handle version script patternsC
To process version scriots, we have to match glob patterns against
symbol strings. Sometimes, we have hundreds or thousands of glob
patterns and have to match them against millions of mangled long
C++ symbol names. This step can be very slow.

In this patch, I implemented the Aho-Corasick algorithm to match glob
patterns to symbol strings as quickly as possible. For the details
of the algorithm, see https://en.wikipedia.org/wiki/Glob_(programming).

This patch improves mold's performance for programs that uses large
version scripts. For example, linking libQt6Gui.so.6.3.0 reduced from
1.10s to 0.05s with this patch.

This patch also changes how symbol versions are applied if two or more
version patterns match to a single symbol string. Previously, the last
one in a script file took precedence. Now, the first one takes
precedence. I believe the new behavior is compatible with GNU ld.

Fixes https://github.com/rui314/mold/issues/156
Fixed https://github.com/rui314/mold/issues/287
2022-01-21 20:30:05 +09:00
Rui Ueyama
05e1054058 s/std::lock_guard/std::scoped_lock/g
It looks like you should use std::scoped_lock instead of std::lock_guard
by default since C++17 unless you have a strong opinion to prefer the
latter.
2022-01-21 15:02:47 +09:00
Rui Ueyama
036fdf0b29 Add a comment 2022-01-21 11:00:36 +09:00
Rui Ueyama
2b034335ec Use std::erase_if instead of our own
I didn't know that C++20 has this function.
2022-01-21 10:40:46 +09:00
Rui Ueyama
be6ae07ac1 [ELF] Ignore an ICC-generated GNU linkonce section
If you try to link ICC-generated objects file with GCC-generated objects,
you'll get an error message that `__gxx_personality_v0` is duplicated.
This is because ICC puts a section with this symbol into a GNU linkonce
section, while GCC puts it into a COMDAT section.

ICC should stop putting that symbol into GNU linkonce because it's
superceded by COMDAT long ago.

That being said, we need to do something to make it possible to mix
ICC and GCC object files. In this patch, we simply discard the ICC-
generated section. Since `__gxx_personality_v0` is always provided by
libc (that function handles C++ exceptions), we can simply ignore ICC's
output.

Fixes https://github.com/rui314/mold/issues/271
2022-01-20 22:59:58 +09:00
Rui Ueyama
e3359ea415 Fix macOS buildbot 2022-01-20 16:46:08 +09:00
Rui Ueyama
2cc85cc21d Fix a build issue on Gentoo with musl libc
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
2022-01-20 16:35:44 +09:00
Rui Ueyama
9c0a55a2eb [ELF] Fix off-by-one error 2022-01-20 13:45:20 +09:00
Rui Ueyama
8b1905453d [ELF] Do not use BND prefix
BND prefix is defined by Intel MPX extension which is now deprecated by Intel.
2022-01-20 13:39:31 +09:00
Rui Ueyama
fa0cb30d8f Refactor 2022-01-20 13:28:16 +09:00
Rui Ueyama
2a4d8b4f72 Rename variables 2022-01-20 12:32:05 +09:00
Rui Ueyama
92876820cb [ELF/ARM64] Support range extension thunks
ARM64 branch instructions have only a 25-bit displacement. Non-thumb
instructions are always aligned to 4 byte boundaries, but with that
implicit trailing two zeros considered, they can represent only a 27-bit
displacement. That means branch instructions can jump to a location only
if it is within a ±128 MiB range.

If a branch destination is farther than that, a linker has to emit machine
code sequence that constructs a full 32-bit address in a register to jump
to the final destination, and redirect the branch to that code sequence.
Such code sequence is called a "range extension thunk" or just "thunk".

Previously, mold didn't support range extension thunks, so it couldn't link
large programs. That would fail with an "relocation out of range" error.
Now, mold gained a feature to create thunks and can link large programs.

Thunk creation is an interesting algorithmic problem. We need to insert
a thunk for at least in every 128 MiB chunk, because otherwise branch
instructions wouldn't be able to jump to a thunk. Adding an entry to a thunk
could slightly enlarge the distance between a branch instruction location
and its destination if the thunk is in between them. That could make the
branch that was previously reachable unreachable.

Usually, this problem is solved by an iterative algorithm. With the
iterative algorithm, a linker check for reachability of all relocations,
create new thunks if necessary, and repeat it until no new thunks are
created.

I implemented a different algorithm than that in this patch. The algorithm
implemented in this patch is guaranteed to work in O(n) where n is the
number of relocations. This algorithm might be novel.

And the algorithm implemented in this patch is quite fast. It can create
thunks in 80 milliseconds on a 16-core Amazon Graviton 2 machine for
clang-14 that has an ~100MB .text section.
2022-01-20 03:16:50 +00:00
Rui Ueyama
02c9fa82d4 [ELF] Ensure mold-warpper.so is linked against libdl 2022-01-20 10:23:32 +09:00
Rui Ueyama
1b01448f01
Merge pull request #286 from tklauser/test-exception-aarch64
[ELF] Pass -fno-PIC along with -mcmodel=large on aarch64
2022-01-20 09:46:42 +09:00
Rui Ueyama
dfeb17a5c8
Merge pull request #285 from tklauser/ignore-fix-cortex-flag
[ELF] Ignore --fix-cortex-a53-835769 flag
2022-01-20 09:45:20 +09:00
Rui Ueyama
d8e3980b86 Do not link libdl
I don't think mold uses any functionality in libdl. mold-wrapper.so
needs it for dlopen()-family functions on non-NetBSD systems though.
2022-01-20 09:28:51 +09:00
Rui Ueyama
0540f2c10b Update README
Fixes https://github.com/rui314/mold/issues/282
2022-01-20 09:10:21 +09:00
Rui Ueyama
809652d740 [ELF] Handle glob patterns other than * for local: in version scripts
Previously, we didn't handle version scripts like this correctly:

  ver {
    global: *;
    local: foo*;
  }

We didn't handle `local:` part correctly except for `*`.

Fixes https://github.com/rui314/mold/issues/277
2022-01-20 08:51:04 +09:00
Rui Ueyama
be41fdbc21 [ELF] Rename variables
`ctx.arg` should contain only variables that can directly be mapped
to command line arguments.
2022-01-20 08:35:52 +09:00
Tobias Klauser
fbd4e559e6
[ELF] Pass -fno-PIC along with -mcmodel=large on aarch64
The -mcmodel=large option is incompatible with -fPIC on aarch64, see
https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-mcmodel_003dlarge

This makes test/elf/exception.sh pass on linux/arm64.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2022-01-19 21:36:53 +01:00