1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
Commit Graph

514 Commits

Author SHA1 Message Date
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
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
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
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
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
Rui Ueyama
9453488424 [ELF] Fix test for ARM64 2022-01-18 13:28:57 +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
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
a9cca00933 [ELF] Fix symbol visibility
This commit fixes a regression introduced in
ce5749ce2f.
2022-01-13 22:59:04 +09:00
Rui Ueyama
011a7d35d6 [ELF] Add a test
https://github.com/rui314/mold/issues/244
2022-01-13 13:06:37 +09:00
Rui Ueyama
9d27ee0839 [ELF] Skip incompatible files specified by linker script GROUP command
Fixes https://github.com/rui314/mold/issues/260
2022-01-13 10:42:13 +09:00
Rui Ueyama
74e0e4f6d0 [ELF] Resurrect a file that was deleted by accident 2022-01-12 22:40:04 +09:00
Rui Ueyama
60c134893c [ELF] Create DT_DEBUG dynamic entry only for executables
gdb uses this field only if it is an executable. Having an extra
dynamic entry is usually harmless, but unfortunately, RPM's `rpmdeps`
tool uses the presence of this entry to distinguish executables from
shared object files. So, it is better not to create a DT_DEBUG entry
for shared object files.

Fixes https://github.com/rui314/mold/issues/254
2022-01-12 22:13:13 +09:00
Rui Ueyama
d2c57e99ca Refactor 2022-01-12 20:35:41 +09:00
Rui Ueyama
bb18b29e13 [ELF] Fix --trace-symbol for DSO
Previously, --trace-symbol didn't work for shared object files.
2022-01-12 17:30:51 +09:00
Rui Ueyama
cea6a569af [ELF] Remove "GNU gold" from the --version string
That substring was introduced in de7ba9014f
to appease Gentoo's dev-libs/jansson-2.13.1-r1 package. But I think I
shouldn't done that from the beginning to avoid the sitaution of the
"User-Agent" string of the web browser, which everybody claims they
are Mozilla, AppleWebKit, Chrome and Safari simultaneously.
2022-01-12 16:38:04 +09:00
Rui Ueyama
9ca6a9dc5e [ELF] Add -z ibt
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:38:38 +09:00
Rui Ueyama
31a43a7ba6 [ELF] Add -z cet-report
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:34:32 +09:00
Rui Ueyama
e29bd8f42b [ELF] Add -z shstk
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:34:24 +09:00
Rui Ueyama
013e6ea06e [ELF] Fix .got.plt for IBTPLT
Previously, the `bnd jmp` instruction in a IBTPLT entry jumps to the
middle of an instruction due to an incorrect GOTPLT value. That happened
to work because a value that was there after the jump can be interpreted
as an `add` instruction and the control falled through the next `pushq`.
2022-01-09 10:14:35 +09:00
Rui Ueyama
27d836180f [ELF] Make an undefined symbol to be resolved to a common symbol in an archive
Previously, mold ignored common symbols in an archive when resolving
symbols. As a result, even if an undefined symbol could be resolved
using a common symbol in an archive, mold would end up with an undefined
symbol error.

This commit changes the behavior. Now, an undefined symbol is resolved
to a common symbol in an archive if exists.

Fixes https://github.com/rui314/mold/issues/256
2022-01-08 20:44:22 +09:00
Rui Ueyama
0370e7f1b3 [ELF] Emit a compact PLT section if -z now is passed
Each entry in the regular PLT section takes 16 bytes.
This new PLT section reduces it to 8 bytes.
2022-01-08 14:57:50 +09:00
Rui Ueyama
fbfa01dcd1 [ELF] Implement -z ibtplt
https://github.com/rui314/mold/issues/229
2022-01-08 14:09:12 +09:00
Rui Ueyama
badc733488 [ELF] Report an error if an incompatible object file is given
Previously, mold would crash if an incompatible object file was given.
https://github.com/rui314/mold/issues/260
2022-01-07 23:04:08 +09:00
Rui Ueyama
3dd76cd953 Attempt to fix buildbots 2022-01-07 18:18:00 +09:00
Rui Ueyama
d86a774ebf Fix Mach-O tests 2022-01-07 18:12:40 +09:00
Rui Ueyama
e7decd2c77 Use relative paths in tests 2022-01-07 18:08:06 +09:00
Rui Ueyama
4324cb2998 Use cc and c++ instead of clang, gcc, clang++ or g++ in tests 2022-01-07 18:02:35 +09:00
Rui Ueyama
4348417dd8 [ELF] Do not convert .ctors/.dtors to .init_array/.fini_array
The .ctors section contains a list of pointers that have to be run
before `main`. It usually contains pointers to global constructors.
The .dtors are for global destructors.

The .init_array and .fini_array serve the same purpose as .ctors and
.dtors. The former sections are newer than the latter sections, and
most programs have already migrated to .{init,fini}_array.

.ctors/.dtors are very similar to .{init,fini}_array, but the order
in which pointers are executed is different. .ctors/.dtors are executed
from the end to the beginning, while .{init,fini}_array are executed
from the beginning to the end.

Previously, we converted .ctors/.dtors sections into .{init,fini}_array
sections. In order to do that, we not only merge .ctors/.dtors to
.{init,fini}_array but also reverse their section contents, so that
the initialization order remains the same.

However, there was a bug in that logic. We forgot to reverse the
locations of dynamic relocations for the converted sections.
So, .ctors/.dtors sections converted to .{init,fini}_array were executed
in a wrong order.

We have two choices to "fix" the issue: (1) reverse not only section
contents but also dynamic relocations, or (2) stop converting .ctors/.dtors.
In this patch, I chose (2).

Since LLVM lld doesn't convert .ctors/.dtors, it shouldn't cause an
issue for most programs.
2022-01-07 17:47:14 +09:00
Rui Ueyama
0e17dbeda8 [ELF] Make --defsym'ed symbols absolute
If a symbol is defined in the form of --defsym=foo=0x<hexvalue>,
it should be defined as an absolute symbol with the given value.
2022-01-07 16:28:14 +09:00
Rui Ueyama
3b33420fe5 [ELF] Support R_X86_64_PLTOFF64 2022-01-07 14:44:17 +09:00
Rui Ueyama
e075e622ba Fix buildbots 2022-01-07 13:24:42 +09:00
Rui Ueyama
092286fc1d [ELF] Fix tests so that they work if CC is clang 2022-01-07 12:45:20 +09:00
Rui Ueyama
2f86fef3a0 [ELF] Fix assertion failure
This patch fixes a regression introduced in
43fa021d48.

Fixes https://github.com/rui314/mold/issues/259
2022-01-06 22:01:56 +09:00
Rui Ueyama
daa88f2f06 [ELF] Handle '[]' in glob patterns
Previously, mold crashes due to an invalid regex pattern exception
when `[...]` is given as a version script pattern.

Fixes https://github.com/rui314/mold/issues/258
2022-01-06 20:45:46 +09:00
Rui Ueyama
404fa1288b [ELF] Add a test
https://github.com/rui314/mold/issues/258
2022-01-06 18:27:31 +09:00
Rui Ueyama
43fa021d48 [ELF] Do not place non-exported symbols into .gnu.hash
Previously, mold put all global symbols into .gnu.hash. Although I
believe it was not an error, it bloated the size of .gnu.hash because
.gnu.hash needs only exported symbols.

https://github.com/rui314/mold/issues/255
2022-01-06 17:47:19 +09:00
Christoph Erhardt
df865725ed Fix test failures on aarch64
Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-01-05 12:26:56 +01:00
Rui Ueyama
be49d673a5 [ELF] Deduce emulation from input files if -m is not given 2022-01-05 19:55:32 +09:00
Rui Ueyama
285c9e2c32 [ELF] Attempt to fix buildbots 2022-01-04 20:59:33 +09:00
Rui Ueyama
a5029d19a8 [ELF] Automatically fall back to ld.bfd or ld.lld if LTO is in use
This is very hacky but highly practical, so I couldn't resist to not
implement this. We should support LTO natively in the future. In the
meantime, this feature should work as a poor-man's replacement.

Fixes https://github.com/rui314/mold/issues/242
2022-01-04 20:50:16 +09:00
Rui Ueyama
9894b3173b [ELF] Add --default-symver
Fixes https://github.com/rui314/mold/issues/228
2022-01-03 20:29:33 +09:00
Rui Ueyama
4b2f10d009 [ELF] Improve test 2022-01-03 20:15:04 +09:00
Rui Ueyama
5618038463 [ELF] Show a better error message for the empty input file
Fixes https://github.com/rui314/mold/issues/227
2022-01-02 19:33:07 +09:00
Rui Ueyama
0a8231b59d [ELF] Support R_X86_64_GOTOFF64
Fixes https://github.com/rui314/mold/issues/224
2022-01-02 11:14:33 +09:00
Rui Ueyama
1f7727975c [ELF] Improve test 2022-01-02 11:13:12 +09:00
Rui Ueyama
b5172caeb5 Improve test
I think `-m32` means ARM32 if this test runs on ARM64.
2021-12-31 00:13:07 +09:00
Tobias Klauser
66c9659f5a
Fix skip check in i386-mergable-strings.sh
Check for the ability to build 32-bit binaries like in the other i386
test cases.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2021-12-30 15:58:11 +01:00
Rui Ueyama
d49c50ddaf [ELF] Add --defsym
Fixes https://github.com/rui314/mold/issues/208
2021-12-30 14:48:39 +09:00
Rui Ueyama
44ae92c4ed Remove redundant "../../" from test script paths
So that it's easier to see the output of the test script running
with `bash -x` . This change was made using sed.
2021-12-30 11:11:27 +09:00