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

42 Commits

Author SHA1 Message Date
Rui Ueyama
b93ad52a73 Enable separate compilation for each source file and target pair
Almost all functions and data types are template in mold, which are
parameterized to target type (e.g. X86_64 or ARM32). I'm generally
happy with that design, but there's one drawback; as we add more
targets, compilation gets slower.

Now we support more than 10 targets, so the compiler has to do 10x
more work than it originall did. As a result, compiling output-chunks.cc
(one of our largest file) took more than 30 seconds to compile on a
Threadripper machine. I hasitated to add a support for a new target
because of this problem. We needed to fix it.

This commit tweaks the build system configs so that the build system
generates bunch of intermediate .cc files. Each generated .cc file
instantiates an original .cc file for one target.

The total amount of required computation doesn't change by this hack,
but now we can parallelize the compilation step. That works well on a
modern multi-core machine.

I generally don't like to tweak build system to workaround a tool's
issue (that's why I'm creating mold in the first place), but it looks
like there's no way to speed up compilation other than this. Or,
maybe we can write a faster C++ compiler someday, but that's another
topic.
2022-09-23 22:28:40 +08:00
Rui Ueyama
3b796819e5 Split LTO source files for Windows 2022-08-12 21:47:02 -07:00
Rui Ueyama
9daf9f942c Fix MSVC compile errors 2022-08-12 20:49:16 +08:00
Rui Ueyama
688ded77ac Simplify 2022-08-12 17:40:35 +08:00
Clemens Wasser
fde9e852f3 Port dynamic loading to Windows
Signed-off-by: Clemens Wasser <clemens.wasser@gmail.com>
2022-08-11 17:32:07 +02:00
Clemens Wasser
08a83c7aaa Disable includes unavailable on Windows
Signed-off-by: Clemens Wasser <clemens.wasser@gmail.com>
2022-08-11 17:28:11 +02:00
Rui Ueyama
b8a4df51ca [ELF][LTO] Support GCC's LDPT_GET_API_VERSION 2022-07-13 15:29:15 +08:00
Christoph Erhardt
4df062c72e Remove unused variable
Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-07-03 21:58:10 +02:00
Rui Ueyama
2b86786419 Move a file 2022-05-15 16:43:22 +08:00
Rui Ueyama
f0bb588e32 Revert "[ELF][LTO] Restart the linker when get_symbols_v2 is called for the first time"
This reverts commit 38f2b965db.

I'd like to wait for GCC to provide some way to identify whether
or not a given LTO plugin supports the v3 API.
2022-05-14 17:47:19 +08:00
Rui Ueyama
38f2b965db [ELF][LTO] Restart the linker when get_symbols_v2 is called for the first time
Previously, we detected if a given linker plugin supports get_symbols_v3
or not and restart the process if only get_symbols_v2 is supported.

Now, mold restart itself wehn get_symbols_v2 is called for the first time,
eliminating the need for the feature detection.

https://github.com/rui314/mold/issues/454
2022-05-04 10:38:02 +08:00
Rui Ueyama
cde4b0fb45 Move a function 2022-05-04 10:01:41 +08:00
Rui Ueyama
a15b73a6ee [ELF] Parallelize a loop 2022-04-28 13:40:11 +08:00
Rui Ueyama
bcac1a3c53 [ELF][LTO] Do not internalize weak/common symbols
Previously, if a symbol in a non-IR object is weak or common and
is resolved to an IR symbol, mold internalized that symbol. That
resulted in having two separate definitions for the same symbol
and caused a mysterious error.

Fixed https://github.com/rui314/mold/issues/479
2022-04-28 13:37:16 +08:00
Rui Ueyama
1fa6b3cd17 [ELF] Allow to build only for x86-64 or ARM64
mold is usually built for all supported tagets, namely, x86-64, i386,
ARM32, ARM64 and RISCV64. This is a good thing because it makes cross
compilation easy. That is, as long as you have a copy of the mold linker,
it is guaranteed to work as a cross linker.

However, during a quick debug session in which you build mold many
times, you may want to build mold only for your native target. That
greatly reduces build time because it reduces the amount of code
after template instantiation.

Therefore, in this commit, I introduced new macros,
MOLD_DEBUG_X86_64_ONLY and MOLD_DEBUG_ARM64_ONLY, to build mold for
x86-64 and ARM64 only, respectively.

These flags should never be used for production. They are solely for
debugging purpose.
2022-04-17 13:02:19 +08:00
Rui Ueyama
66a057cce7 [ELF][ARM64] Add a stub for ARM32 2022-03-10 16:27:31 +09:00
Rui Ueyama
e7c071ea36 [ELF] Improve an error message 2022-03-10 13:54:16 +09:00
Rui Ueyama
9b5d404d1e Simplify 2022-02-27 20:59:59 +09:00
Rui Ueyama
e413433752 [ELF][LTO] Add lld-compatible LTO-related command line options
Fixes https://github.com/rui314/mold/issues/367
2022-02-27 09:28:51 +09:00
Rui Ueyama
e67f460bfd [ELF][LTO] Fix "too many open files" issue for GCC
Fixes https://github.com/rui314/mold/issues/362
2022-02-26 16:34:51 +09:00
Rui Ueyama
e281ed88bb Fix minor memory leak 2022-02-26 16:24:25 +09:00
Rui Ueyama
c173f9c0ab Simplify 2022-02-21 18:26:51 +09:00
Rui Ueyama
3a15c54f10 [ELF][LTO] Check for the return value of all_symbols_read_hook 2022-02-19 21:57:36 +09:00
Rui Ueyama
ec9ac181f8 [ELF] Improve comments 2022-02-19 18:24:21 +09:00
Rui Ueyama
7dc6ce72dd Refactor 2022-02-19 12:13:23 +09:00
Rui Ueyama
15fa05eff6 [ELF][LTO] Clear symbols after LTO
This commit ensure that all symbol resolution results are cleared
after LTO, so that the following second symbol resolution will not
be affected by the previous results.
2022-02-18 22:05:14 +09:00
Rui Ueyama
b57da5413c [ELF][LTO] Restart mold if a LTO plugin does not support get_symbols v3 API 2022-02-17 19:14:05 +09:00
Rui Ueyama
8f0acbf413 [ELF][LTO] Move LTO to the symbol resolution pass
ELF object files returned by do_lto() may contain unforeseen undefined
symbols, so we can't call that function after the symbol resolution pass
because it can cause undefined symbol errors.
2022-02-17 16:14:11 +09:00
Rui Ueyama
b94dd6dbeb Revert "[ELF] add method to check whether an input file is shared object"
This reverts commit ddcb7b4197. `is_dso`
is used by hot functions such as `Symbol::get_addr()`, so we want to
eliminate the cost of virtual function dispatch.
2022-02-16 09:51:07 +09:00
Rui Ueyama
28236b1b34 [ELF][LTO] Report an error if an IR file wasn't claimed
And remove an unused variable. Found by Dmitry Antipov.
2022-02-14 20:59:32 +09:00
Rui Ueyama
68a35bfa03 Fix CI 2022-02-13 16:52:54 +09:00
Rui Ueyama
70ec56f8bb [ELF][LTO] Export symbols from DSOs correctly
With this change, mold can now build Clang with LTO and all Clang tests pass.
2022-02-13 15:34:37 +09:00
Rui Ueyama
5f17da80d0 [ELF][LTO] Mark IR objects as alive 2022-02-13 12:57:28 +09:00
Rui Ueyama
16a3c9491f [ELF][LTO] Fix "too many open files" issue
read_lto_object is called on each archive member, so if an archive file
contains lots of members, it can exhaust the pool of file descriptors.
This patch fixes the issue by opening an archive only once.
2022-02-13 12:22:18 +09:00
Rui Ueyama
ce744aeca4 Refactor 2022-02-12 20:34:49 +09:00
Rui Ueyama
46f954d23d [ELF][LTO] Returns a more precise value from get_symbols callback 2022-02-12 20:06:44 +09:00
Rui Ueyama
42b3038463 [ELF][LTO] Factor out LTO type definitions to lto.h 2022-02-12 17:50:36 +09:00
Rui Ueyama
c9612d3120 Refactor 2022-02-12 17:36:38 +09:00
Rui Ueyama
60d0900496 [ELF][LTO] Fix "concurrent hash table full" error
Since compiled IR objects may contain mergeable string sections, we
don't know the estimated number of items in output mergeable sections.
Previously, we created the concurrent hash tables for output mergeable
sections before compiling IR objects, so there was a chance to see
the "concurrent hash table full" error.

This commit moves the code to add section pieces to output mergeable
sections after `do_lto`.
2022-02-12 16:53:36 +09:00
Rui Ueyama
c1963ce2ac [ELF][LTO] Recognize IR files generated by GCC 11 2022-02-12 16:28:38 +09:00
Rui Ueyama
61eb265cf4 [ELF][LTO] Report an error if -plugin was not given 2022-02-12 10:17:21 +09:00
Rui Ueyama
46995bcfc3 [ELF] Support LTO plugin API
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
2022-02-11 21:09:28 +09:00