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

3426 Commits

Author SHA1 Message Date
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
Tobias Klauser
c34c77b9a5
[ELF] Ignore --fix-cortex-a53-835769 flag
GCC passes this on my linux/arm64 machine (Pine64 Pinebook Pro).

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2022-01-19 21:15:55 +01:00
Rui Ueyama
a4d81fb723 [ELF] Ignore trailing garbage after a terminator in .eh_frame
Follow-up patch for https://github.com/rui314/mold/pull/278
2022-01-19 19:45:31 +09:00
Rui Ueyama
948248b732
Merge pull request #278 from depressed-pho/netbsd-compatibility
Improve compatibility with NetBSD
2022-01-19 19:35:18 +09:00
Masatake Daimon
807679cb0a Skip empty records in .eh_frame
It should be perfectly legal to have an empty CIE along with an end-of-records
marker of FDE. /usr/lib/crtend.o from NetBSD/amd64 has the following .eh_frame
but mold emits an error for the zero-length FDE:

    .section	.eh_frame, "a", @progbits
    .align 8
    .quad 0

Signed-off-by: Masatake Daimon <pho@NetBSD.org>
2022-01-19 11:16:55 +09:00
Masatake Daimon
67179950d0 Ignore -dc and -dp
GCC 7.5.0 passes these flags to ld(1). Maybe mold should handle them properly,
but since common symbols are considered to be obsolete it's probably not worth
it. At least it's better to ignore them rather than to abort.

Signed-off-by: Masatake Daimon <pho@NetBSD.org>
2022-01-19 11:16:55 +09:00
Masatake Daimon
af05107964 Do not try to link with -ldl unconditionally
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>
2022-01-19 11:16:55 +09:00
Rui Ueyama
fe209f3f4c [ELF] If we can't open an existing output file, create a new one
We try to overwrite to an existing output file if exists because
writing to a file that is already in buffer cache is much faster than
creating a new fresh file and write to it.

Previously, mold failed with the "fchmod failed" error if an existing
file is writable (so open for read-write succeeds) but owned by
someone else (so fchown fails). Now, mold ignore such existing file
and create a fresh output file.

Fixes https://github.com/rui314/mold/issues/275
2022-01-18 16:04:52 +09:00
Rui Ueyama
e6d1d011ef
Merge pull request #274 from akawashiro/show-errno
Show errno for ftruncate and fchmod
2022-01-18 15:07:15 +09:00
Akira Kawata
fe7bc2a846 [ELF] [Mach-O] Show errno for ftruncate and fchmod
Signed-off-by: Akira Kawata <akirakawata1@gmail.com>
2022-01-18 14:42:56 +09:00
Rui Ueyama
9453488424 [ELF] Fix test for ARM64 2022-01-18 13:28:57 +09:00
Rui Ueyama
267125e5b1 Update README 2022-01-18 13:07:34 +09:00
Rui Ueyama
43b2a1e423 [ELF] Do not scan .text for .relr.dyn 2022-01-17 20:40:22 +09:00
Rui Ueyama
04ba8f4cbd [ELF] Rename a function 2022-01-17 10:26:23 +09:00
Rui Ueyama
c747162717 Simplify 2022-01-16 17:20:26 +09:00
Rui Ueyama
3ad29b230c Simplify 2022-01-16 15:23:47 +09:00
Rui Ueyama
7a8c14a634 [ELF] Do not use parallel scan to compute section offsets
A function passed to tbb::parallel_scan must be associative, but I don't
think our function satisfied that constraint. So I rewrote code without
tbb::parallel_scan.
2022-01-16 13:32:20 +09:00
Rui Ueyama
021463c628 Refactor 2022-01-16 12:55:23 +09:00
Rui Ueyama
1152b6eb38 [ELF] Remove redundant assignment 2022-01-16 08:41:26 +09:00
Rui Ueyama
27be74e800 Simplify 2022-01-15 20:18:25 +09:00
Rui Ueyama
709ed92ac0 [ELF] Rename a function 2022-01-15 16:08:10 +09:00
Rui Ueyama
faa75ee9e7 [ELF] Add a comment to explain the encoding of .relr.dyn 2022-01-15 16:02:43 +09:00
Rui Ueyama
3411511a8b [ELF] Ignore i386-specific linkonce symbols
This is a follow-up to the previously commit patch
0c19046721. We needed to ignore symbols
whose address is in a discarded .gnu.linkonce sections.

Fixes https://github.com/rui314/mold/issues/270
2022-01-15 14:28:34 +09:00
Rui Ueyama
12fcc76ff0 Install missing tools to a docker environment
We need `git` and `pkg-config` because we are using them in our
Makefile.
2022-01-15 14:02:40 +09:00
Rui Ueyama
0c19046721 [ELF] Ignore .gnu.linkonce sections in old glibc i386 CRT files
Fixes https://github.com/rui314/mold/issues/270
2022-01-15 00:06:15 +09:00
Rui Ueyama
bd6afa1b23 [ELF] Add -pack-dyn-relocs=relr
.relr.dyn is a new section that has been implemented in other linkers
recently. That section contains only the RELATIVE-type dynamic
relocations (i.e. base relocations). Compared to the regular
.rela.dyn, a .relr.dyn's size is typically less than 1/10 because the
section is compressed.

Since PIEs (position-independent executables) tend to contain lots of
RELATIVE-type relocations and PIEs are now the default on many Linux
distributions for security reasons, .relr.dyn is more effective than
it was. It can reduce binary size by a few percent or more.

Note that the runtime support is catching up, so binaries built with
`-pack-dyn-relocs=relr` may not work on your system unless you are
running a very recent version of Linux.
2022-01-14 20:54:37 +09:00
Rui Ueyama
5fc0e503e1 Do not use CPPFLAGS for C++ compiler flags
The correct variable name is `CXXFLAGS`. `CPPFLAGS` is for C preprocessor
flags in the Makefile.
2022-01-14 15:34:55 +09:00
Rui Ueyama
8e709d2b62 Refactor 2022-01-14 11:34:38 +09:00
Rui Ueyama
7fa15fd17e Ignore /SYM64/ pseudo members in thin archives 2022-01-14 11:06:39 +09:00
Rui Ueyama
a80524b478 Refactor 2022-01-14 10:57:01 +09:00
Rui Ueyama
2ee2243c63 Refactor 2022-01-13 23:53:53 +09:00
Rui Ueyama
bba506d6b4 Ignore /SYM64/ pseudo member inar
I believe this pseudo member is relatively new to support archive
files larger than 4 GiB. I'm not sure if mold can handle such large
archives, but first of all, mold crashes when an archive with this
pseudo member is given.

This commit fixes the crash bug.

I don't know how to create an archive with this pseudo member, so
this commit does not have a testcase.

Reported by sina-ht at https://github.com/rui314/mold/pull/269.
2022-01-13 23:35:11 +09:00