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

60 Commits

Author SHA1 Message Date
Rui Ueyama
e98aab7ea9 [ELF] Reimplement --repro
`--repro` is a hidden command flag for debugging.

Previously, if the flag was given, mold would create a `.repro`
section in an output file with all input files as its contents.
The flaw of the design is that when mold fails to create an output
file, no .repro section would be created.

So I changed the behavior in this commit. Now, the tar file is
created as an independent file.
2022-02-01 13:47:44 +09:00
Rui Ueyama
7aa35d12c3 [ELF] Do not use std::has_single_bit
It looks like some stdlib implementations do not provide that function.

Fixes https://github.com/rui314/mold/issues/308
2022-01-31 17:52:05 +09:00
Rui Ueyama
e76f7c0d47 Add an initial support of RISC-V
With this patch, mold can now produce a statically-link "Hello wrold"
program for RISC-V.
2022-01-28 18:08:42 +09:00
Rui Ueyama
229ee85890 [ELF][RISC-V] Add a stub for RISCV64
As we add more targets to mold/ELF, it takes more time to compile
source files because compiler has to instantiate more templates.
I think we need to do something to fix it, but for now, I'll just
add a stub for RISC-V 64-bit ISA so that we can start working on
RV64.
2022-01-26 15:16:36 +09:00
Rui Ueyama
6c9bb0d7ff Use C++20 bit-twiddling functions more 2022-01-26 09:24:52 +09:00
Christoph Erhardt
cb94a4ab1b Use C++20 bit-twiddling functions
This replaces the GCC builtins with their portable C++20 counterparts.

Note that the C++ functions are only defined for unsigned types, so we
need to explicitly specify the appropriate template type argument in
some instances.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-01-25 21:44:00 +01: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
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
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
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
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
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
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
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
778f8629eb Refactor 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
9b710cf832 Refactor 2022-01-08 15:11:25 +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
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
276b9d005d [ELF] Add ARM64 to --help message
Fixes https://github.com/rui314/mold/issues/251
2022-01-05 21:41:53 +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
df24372775
Merge pull request #220 from rmcgibbo/main
[ELF] Fix parsing of --no-dynamic-linker on command line
2022-01-02 11:54:27 +09:00
Robert T. McGibbon
68fa44d399 [ELF] Fix parsing of --no-dynamic-linker on command line
Signed-off-by: Robert T. McGibbon <rmcgibbo@gmail.com>
2022-01-01 12:22:48 -05:00
Christoph Erhardt
ebe982c443 Remove duplicate code
The exact same four lines of code exist a few lines below this hunk.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-01-01 09:44:37 +01:00
Rui Ueyama
58e43633fc Revert "Revert "Use C++17 filesystem API""
This reverts commit f29a85f20a with a fix
for a build failure.
2021-12-31 16:39:54 +09:00
Rui Ueyama
f29a85f20a Revert "Use C++17 filesystem API"
This reverts commit f6e91df440 because
it causes build breakages for a lot of Gentoo packages.
2021-12-30 22:15:52 +09:00
Rui Ueyama
f6e91df440 Use C++17 filesystem API 2021-12-30 21:32:01 +09: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
f3766cda81 [ELF] Add -z {max,common}-page-size
Fixes https://github.com/rui314/mold/issues/203
2021-12-29 17:14:08 +09:00
Rui Ueyama
aa972e5351 [ELF] Remove redundnat "mold: " from error messages 2021-12-28 12:42:25 +09:00
Rui Ueyama
888474b59c [ELF] Ignore --warn-execstack
mold never sets executable bit to the stack area, so we can
simply ignore the flag.

Fixes https://github.com/rui314/mold/issues/196
2021-12-26 10:29:16 +09:00
Rui Ueyama
6e290aab3e [ELF] Implement --color-diagnostics 2021-12-25 16:55:51 +09:00
Rui Ueyama
d1a47ee57b [ELF] Ignore --apply-dynamic-relocs
We always write dynamic relocation addends for bug-compatibiltiy
with the Go toolchain. Therefore, this flag is no-op.

See 919e8cbc62 for the details of
the Go's bug.
2021-12-25 16:22:35 +09:00
Rui Ueyama
7aa5c393e4 [ELF] Support extern "C++" in dynamic lists
Fixes https://github.com/rui314/mold/issues/149
2021-12-25 15:10:24 +09:00
Rui Ueyama
7b3c640472 Fix --dynamic-list
Previously, symbols were not exported from an executable even if
they are specified so by a dynamic list.
2021-12-25 13:38:24 +09:00
Rui Ueyama
5601cf4236 [ELF] Add -z separate-code, -z noseparate-code and -z separate-lodable-segments
Fixes https://github.com/rui314/mold/issues/172
2021-12-24 20:28:45 +09:00
Rui Ueyama
135f17c5aa [ELF] Handle --sysroot
Attempt to fix https://github.com/rui314/mold/issues/150
2021-12-23 21:23:00 +09:00
Rui Ueyama
8c86c28496 Add -z nodefaultlib
Fixes https://github.com/rui314/mold/issues/184
2021-12-23 15:01:57 +09:00
Rui Ueyama
feb63f7b5b [ELF] Ignore -z nodefaultlib
Fixes https://github.com/rui314/mold/issues/184
2021-12-22 21:04:21 +09:00
Rui Ueyama
8bc57363c8 [ELF] Issue a warning instead of error for an unknown -z option
Fixes https://github.com/rui314/mold/issues/180
2021-12-22 20:08:14 +09:00
Rui Ueyama
f9ff04866e [ELF] Add --threads=N option
Fixes https://github.com/rui314/mold/issues/168
2021-12-20 16:29:22 +09:00
Rui Ueyama
c824e7831a [ELF] Show a hint if -b binary is given
Fixes https://github.com/rui314/mold/issues/164
2021-12-20 12:26:02 +09:00
Rui Ueyama
100ed91a78 [ELF] Ignore -no-call-graph-profile-sort 2021-12-12 14:27:49 +09:00
Rui Ueyama
733bb6354f Rename variables 2021-12-11 21:40:57 +09:00
Rui Ueyama
10a318d5ba [ELF] Fix -exclude_libs option 2021-12-10 20:45:57 +09:00
Rui Ueyama
22116629f1 [ELF] Add --start-lib and --end-lib
Fixes https://github.com/rui314/mold/issues/133
2021-12-06 20:09:46 +09:00
Rui Ueyama
06c237838c [ELF] Fix --help message
Fixes https://github.com/rui314/mold/issues/119
2021-10-08 23:43:03 +09:00
Rui Ueyama
928c39937a Refactor 2021-10-03 16:26:31 +09:00