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

1027 Commits

Author SHA1 Message Date
Rui Ueyama
d8ad600b6a Improve MergedSection<E>::assign_offsets()
This patch parallelize MergedSection<E>::assign_offsets().
clang-13 link time is reduced from ~2.5s to ~2.35 with this patch.
2021-07-14 17:11:25 +09:00
Rui Ueyama
41b2fa7375 Optimize string merging
Linking clang-13 with debug info takes ~3.6 seconds on a simulated
10-core/20-threads machine. mold spends most of its time (~2.3 seconds)
merging string literals in .debug_str. Input .debug_str sections contain
70 million string literals in total, which is reduced to 2 million after
de-duplication. The input object files contain a lot of duplicates.
clang-13 with debug info is enormous -- it is ~3.1 GiB after linking.

It looks like TBB's concurrent hashmap doesn't scale well with the
input.

In this patch, I implemented our own concurrent hashmap. The hashmap
is extremely lightweight and support only the key-value insertion
operation. It doesn't even support rehashing. It aborts once the hash
table becomes full.

In order to know the correct size for the hashmap before inserting
strings into it, I also implemented HyperLogLog algorithm in this patch.
HyperLogLog is an algorithm that gives a fairly accurate estimate on
the number of unique elements.

With this patch, mold can link clang-13 in ~2.5 seconds, which is ~30%
faster than before.

https://github.com/rui314/mold/issues/73
2021-07-13 16:54:09 +09:00
Rui Ueyama
6bb091595e Refactor 2021-07-13 13:13:34 +09:00
Rui Ueyama
e0d44b6678 Use concurrent_unorderd_map for string merging
With high contention rate, it looks like concurrent_unordered_map
outperforms concurrent_hash_map.
2021-07-12 00:02:01 +09:00
Rui Ueyama
e855b90344 Show stacktrace on SEGV and assertion failure 2021-07-09 23:34:39 +09:00
Rui Ueyama
63b6d30876 Compress .repro section contents
Previously, .repro contains an uncompressed tar file containing all
input files. This patch compresses the contents in the gzip format.
2021-07-09 00:47:15 +09:00
Rui Ueyama
50b7497e19 Align section header to a E::wordsize boundary
Fixes https://github.com/rui314/mold/issues/80
2021-07-08 15:58:55 +09:00
Rui Ueyama
fc4aafa974 Fix assertion failures
mold failed with `make EXTRA_CPPFLAGS="-Wp,-D_GLIBCXX_ASSERTIONS" test`,
which enables extra assertions.

Thanks for @nehaljwani to find out the flag.
2021-07-06 14:43:06 +09:00
Rui Ueyama
d0265554a7 Refactor 2021-07-06 13:39:33 +09:00
Nehal J Wani
b596248a1e
Fix out of bound check in get_shndx()
Assert failure:
/usr/include/c++/11.1.0/span:276:
  std::span::reference
  std::span<ElfSym<X86_64>, 18446744073709551615>
     ::operator[](std::span::size_type)
         const [_Type = ElfSym<X86_64>, _Extent = 18446744073709551615]:
           Assertion '__idx < size()' failed.

GDB stacktrace:
Thread 2.4 "mold" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fabc3d3f640 (LWP 17804)]
0x00007fabc496fd22 in raise () from /usr/lib/libc.so.6
(gdb) bt
 #0  0x00007fabc496fd22 in raise () from /usr/lib/libc.so.6
 #1  0x00007fabc4959862 in abort () from /usr/lib/libc.so.6
 #2  0x000055a9685eb018 in std::__replacement_assert (...)
     at /usr/include/c++/11.1.0/x86_64-pc-linux-gnu/bits/c++config.h:504
 #3  0x000055a968614c47 in std::span<ElfSym<X86_64>, ...>::operator[] (...)
     at /usr/include/c++/11.1.0/span:276
 #4  ObjectFile<X86_64>::get_shndx (this=<...>, esym=...) at ./mold.h:2145
 #5  ObjectFile<X86_64>::get_section (this=<...>, esym=...) at ./mold.h:2154

Signed-off-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
2021-07-05 18:02:27 -04:00
Rui Ueyama
b721514f98 Rename a variable 2021-07-05 14:00:16 +09:00
Rui Ueyama
accf96877f Add a stub for AArch64
It can generate an executable, but generated executable won't run
correctly because we don't process relocations at all yet.
2021-07-03 21:39:44 +09:00
Rui Ueyama
546df46eaf Define AARCH64 type and other constants for ARM64 2021-07-03 19:58:46 +09:00
Rui Ueyama
fe3af50fb8 Fix comment 2021-07-03 18:32:43 +09:00
Nehal J Wani
a48eee9179
Fix compilation error with GCC 11
mold.h:128:19: error: explicit specialization of
  ‘template<class Key> class tbb::detail::d1::tbb_hash_compare’
  outside its namespace must use a nested-name-specifier [-fpermissive]
  128 | template<> struct tbb_hash_compare<std::string_view> {
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
2021-07-02 23:40:16 -04:00
Rui Ueyama
3e3d58b6f1 Static-link oneTBB by default
oneTBB API is changing rapidly, so even if a oneTBB is installed
into a system already, it is likely that that is not a compatible
version with mold. This makes program building unnecessarily hard.

This change intends to solve the problem once and for all by
including oneTBB as a subdirectory and static-link against it at
build-time.

oneTBB is released under the Apache License 2.0, which is compatible
with AGPL. Therefore, we can still distribute the binary of mold
under AGPL.

If you do not want to static-link oneTBB, pass `SYSTEM_TBB=1`
to `make`.

This change also ports mold from oneTBB v2020.3 to v2021.3.0.

Fixes https://github.com/rui314/mold/issues/66
2021-07-03 00:08:33 +09:00
Rui Ueyama
29a7d06dd4 Fix race condition 2021-07-01 23:10:00 +09:00
Rui Ueyama
6432114e2a Fix handling of --sysroot
Fixes https://github.com/rui314/mold/issues/59
2021-06-30 22:15:19 +09:00
Rui Ueyama
4436e4a57d Improve error message for an attempt of LTO 2021-06-26 15:05:05 +09:00
Rui Ueyama
0b0e066cc5 Refactor 2021-06-25 23:36:53 +09:00
Rui Ueyama
bd8059a366 Fix an issue that a .dynsym for PLT refers itself 2021-06-25 13:33:14 +09:00
Rui Ueyama
5046fae0cf Do not directly call imported functions
This is needed by Gentoo's sci-libs/lapack-3.9.0-r1 package.
2021-06-25 01:05:57 +09:00
Rui Ueyama
d9ecc2e3e6 Promote weak undefined symbols to weak dynamic symbols
Previously, if a weak undefined symbol cannot be resolved within
an output of the linker, mold turned it into an absolute symbol
with value 0. However, other linkers export such symbols as a
weak dynamic symbol, so that the symbol gets another chance to be
resolved at runtime.

This patch implements the behavior.

This is needed by Gentoo's dev-libs/nsync-1.20.1 package.
2021-06-25 00:44:35 +09:00
Rui Ueyama
de668b125a Refactor 2021-06-24 15:50:08 +09:00
Rui Ueyama
1bac9c7b8d Add -z nodump
This is needed by Gentoo's sci-libs/indilib-1.8.9 package.
2021-06-21 06:56:07 +09:00
Rui Ueyama
83b14328ec Keep .ctors/.dtors sections if they are read from crtbegin.o or crtend.o
This is needed by Gentoo's dev-lang/gnat-gpl-2018-r3 package,
which still uses GCC7's CRT files.
2021-06-20 17:59:38 +09:00
Rui Ueyama
9a219c0048 Rename a variable 2021-06-20 16:22:01 +09:00
Rui Ueyama
4f92d7f19b Add -z origin
This is needed by Gentoo's dev-ada/gnatcoll-bindings-2020-r1 package.
2021-06-20 14:42:43 +09:00
Rui Ueyama
9519e4ce20 Change how to handle --unresolved-symbols=ignore
Previously, we turned unresolved undefined symbols into dynamic
symbols. This patch changed the behavior so that such symbols
are turned into non-dynamic absolute symbols with value zero.

This change is needed by Gentoo's dev-libs/wayland-protocols-1.21
package.
2021-06-20 14:31:36 +09:00
Rui Ueyama
b21ade127c Simplify 2021-06-20 00:51:38 +09:00
Rui Ueyama
793136a8f0 Give common symbols in archive files higher priority
If an object file in an static archive contains a common symbol
that can be used to resolve an undefined symbol, mold now pulls
out that object file from the archive. Previously, we ignore such
common symbols.

Object files generated by a Fortran compiler often contain a lot of
common symbols, and this change makes a difference.

Fixes Gentoo's sci-astronomy/wcslib-7.3 package, which contains a
program written in Fortran.
2021-06-19 21:42:21 +09:00
Rui Ueyama
9febec6c69 Rename a function 2021-06-19 20:29:16 +09:00
Rui Ueyama
a0ecd0c8dc Add --unique=PATTERN
This is needed by Gentoo's sys-fabric/infinipath-psm-3.2 package.
2021-06-19 01:09:26 +09:00
Rui Ueyama
37b88e3f5a Do not set executable bit for --relocatable outputs 2021-06-18 01:45:38 +09:00
Rui Ueyama
2203644a3b Fix section addresses
This is needed for Gentoo's net-libs/nodejs-14.16.1 package.
2021-06-17 23:48:31 +09:00
Rui Ueyama
219e6c92c3 Always create a .dynsym and .dynstr
This is needed for Gentoo's app-benchmarks/cpuburn-1.4a-r3 package.
2021-06-17 14:18:44 +09:00
Rui Ueyama
e88dddb820 Add -z {text,notext,textoff] 2021-06-17 14:18:44 +09:00
Rui Ueyama
e7019ebf86 Add -z keep-text-section-prefix 2021-06-16 19:50:08 +09:00
Rui Ueyama
a715197be4 Export more symbols from executable if they could overwrite dso syms 2021-06-15 01:47:53 +09:00
Rui Ueyama
bc2ece0474 Fix --relocatable 2021-06-14 13:48:26 +09:00
Rui Ueyama
333843a33d Add --warn-unresolved-symbols and --error-unresolved-symbols 2021-06-14 00:04:07 +09:00
Rui Ueyama
a1e0aa88fe Fix issues found by ASAN 2021-06-11 22:54:37 +09:00
Rui Ueyama
9cc309af75 Implement --relocatable
Fixes https://github.com/rui314/mold/issues/46
2021-06-11 21:57:43 +09:00
Rui Ueyama
3102ab867c Refactor 2021-06-11 02:12:19 +09:00
Rui Ueyama
c53a71ada3 Simplify 2021-06-08 13:42:40 +09:00
Rui Ueyama
8c75327817 Simplify
AFAIK, GOT entry size is always the same as the machine word size,
so remove E::got_size and use E::wordsize instead.
2021-06-08 00:01:55 +09:00
Rui Ueyama
a0c3fcb1bb Do not put local symbols to .dynsym 2021-06-06 17:24:49 +09:00
Rui Ueyama
214bcb2f48 Make it compile with GCC-11
Fixes https://github.com/rui314/mold/issues/37
2021-06-05 19:54:30 +09:00
Rui Ueyama
6e7baef8d3 Set DT_RELACOUNT field 2021-06-04 20:04:30 +09:00
Rui Ueyama
3fb870c80b Add --compress-debug-info=zlib-gnu 2021-06-03 23:57:06 +09:00