1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 21:17:28 +03:00
Commit Graph

3650 Commits

Author SHA1 Message Date
Rui Ueyama
fb6967c0cf Update a document 2022-02-22 19:26:28 +09:00
Rui Ueyama
385c1c494d Update a document 2022-02-22 18:57:15 +09:00
Rui Ueyama
4667be6134 [ELF] Change the size of ibtplt from 24 bytes to 32 bytes 2022-02-22 16:14:27 +09:00
Rui Ueyama
3f9868238b [ELF] Add the --shuffle-sections-seed=NUMBER option 2022-02-22 15:41:51 +09:00
Rui Ueyama
3e8c519d4e [ELF] Add the --reverse-sections option
This option reverse input sections before assigning offsets to them.
This is useful to detect an unintended dependency between static
initializers in different translation units. C++ only guarantees that
static initializers are invoked from top to bottom in a single
translation unit, and it doesn't guaratee anything about the order of
initialization between translation units.

By (partially) reversing the contents of .init_array using
--reverse-sections, you can run your program with a completely
reversed initialization order.
2022-02-22 15:41:51 +09:00
Rui Ueyama
aa27d674c1
Merge pull request #356 from sicherha/aarch64-skip-reloc-rodata-test
Skip reloc-rodata test on aarch64
2022-02-22 15:00:23 +09:00
Christoph Erhardt
3cbc57f9af Skip reloc-rodata test on aarch64
The test expects an error when an object compiled with `-fno-PIC` is
linked with `-pie`, but that doesn't happen on aarch64.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-02-22 06:41:01 +01:00
Rui Ueyama
a1e6d8e8df Add comments 2022-02-22 13:18:09 +09:00
Rui Ueyama
a054bcd4ff [ELF] Add the --dependency-file=FILE option 2022-02-22 13:18:04 +09:00
Rui Ueyama
e47c67727c Update README 2022-02-22 11:50:54 +09:00
Rui Ueyama
16bdf4009a Pass -O2 to the compiler 2022-02-22 11:49:17 +09:00
Rui Ueyama
c173f9c0ab Simplify 2022-02-21 18:26:51 +09:00
Rui Ueyama
89612b7096 Bump mold version to 1.1 2022-02-20 16:40:17 +09:00
Rui Ueyama
d258140d54 Inline a default constructor 2022-02-20 16:04:00 +09:00
Rui Ueyama
6ce142d73a Remove redundant default destructors 2022-02-20 16:02:05 +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
4a6e71096c Fix Gentoo build script as build-static.sh is gone 2022-02-19 21:57:36 +09:00
Rui Ueyama
ec9ac181f8 [ELF] Improve comments 2022-02-19 18:24:21 +09:00
Rui Ueyama
ccd475e41d [Mach-O] Show a notice on startup 2022-02-19 16:49:20 +09:00
Rui Ueyama
7dc6ce72dd Refactor 2022-02-19 12:13:23 +09:00
Rui Ueyama
064be343f5 Remove build-static.sh as the statically-linked mold can't do LTO
This commit removes build-static.sh because statically-linked mold
executable can't generally dlopen a shared library and therefore can't
load the linker LTO plugin.

Now, build-dynamic.sh is renamed dist.sh and recommended for general
use.
2022-02-19 12:00:51 +09:00
Rui Ueyama
c8853223a3 Add a script to create a tar file for binary distribution
I think we don't need to create a tar file for binary distribution
for each Linux distro. Instead, we can create mold executable that
works on most Linux machines.

The new script, build-dynamic.sh, creates a mold executable with
libmimalloc, libtbb, libstdc++ and libcrypto begin linked statically.
I don't have a concern as to the availability of other libraries
(libc, libm, libz and librt) because they essentially exists on any
system.
2022-02-19 11:26:18 +09:00
Rui Ueyama
0b7d210f99 Improve build scripts 2022-02-18 22:35:59 +09:00
Rui Ueyama
b22e6f80fc Add scripts to create binary packages
https://github.com/rui314/mold/issues/351
2022-02-18 22:11:34 +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
61e0311889 Refactor 2022-02-18 20:18:07 +09:00
Rui Ueyama
825b918146 Do not use dlopen only when built with ./build-static.sh
This commit fixes a regression in f4a9b05114
that mold crashed when it tried to dlopen a linker plugin shared library.
2022-02-18 15:18:56 +09:00
Rui Ueyama
19587d43ee Rename a variable 2022-02-18 12:53:34 +09:00
Rui Ueyama
f4a9b05114 Do not call dloepn() if built with ./build-static.sh
It looks like setting __TBB_DYNAMIC_LOAD_ENABLED to 0 is not enough
to make TBB not to call dlopen(). We need to unset __TBB_WEAK_SYMBOLS_PRESENT
as well.

Fixes https://github.com/rui314/mold/issues/348
2022-02-18 12:17:24 +09:00
Rui Ueyama
7735cf5b95 Style change 2022-02-17 20:29:28 +09:00
Rui Ueyama
fcb28161b1
Merge pull request #349 from dmantipov/use-explicit-mimalloc-new-delete-overrides-if-system-mimalloc
Use explicit mimalloc new/delete overrides if SYSTEM_MIMALLOC
2022-02-17 20:26:27 +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
Dmitry Antipov
630b262d2b Use explicit mimalloc new/delete overrides if SYSTEM_MIMALLOC
When building with SYSTEM_MIMALLOC=1, linking with (assuming
shared) '-lmimalloc' is not enough to override C++ new/delete
with mimalloc versions, and 'mimalloc-new-delete.h' should be
included from one (and the only) translation unit as well.

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2022-02-17 10:44:58 +03: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
a3f2a5c7ec Format 2022-02-17 13:54:15 +09:00
Rui Ueyama
b5db63f4bb [ELF] Allow relative relocs against absolute symbols
In the previous commit (c325cc039a),
I argued that PC-relative relocations are not representable if they
refer absolute symbols, and I made a change so that such relocations
are handled as errors.

Even though what I did is technically correct, that results in a failure
of an important use case of the weak undefined symbol. Here is why.

If you have an weak undefined symbol `foo`, you would use it as follows:

  if (foo)
    foo();

If `foo` is defined (i.e. has an address other than 0), `foo` is called.

If `foo` is undefined (i.e. has the address 0), the subsequent CALL
instruction will have an offset from the CALL instruction to address 0.
That displacement is computed at link-time. If the output is position-
independent, the call instruction may not have a correct displacement
from address 0 to the instruction at runtime due to base relocation.

However, that's not a problem in practice, because the function call
is guarded by `if (foo)`, and that will always evaluated to false
if `foo` is undefined. Therefore, the faulty `CALL` instruction will
never be executed.

So, that means we need to relocate PC-relative relocations against
absolute symbols even if doing so results in an incorrect result.
This patch implement that.
2022-02-17 12:07:48 +09:00
Rui Ueyama
c325cc039a [ELF] Report an error for an unrepresentable reloc against abs symbol
PC-relative relocations against absolute symbols are not representable
in position-independent code. In order to support such relocations,
someone has to compute `S + A - P` or subtract `B` as a base relocation,
but such dynamic relocations don't exist.

This is contrary to non-PC-relative relocations against non-absolute
symbols. In this case, we can simply use the base relocation (e.g.
R_X86_64_RELATIVE).

https://github.com/rui314/mold/issues/348
2022-02-17 11:21:52 +09:00
Rui Ueyama
0b7edc07f4 Format 2022-02-17 10:30:20 +09:00
Rui Ueyama
da48efe63b Update the man page 2022-02-16 19:36:26 +09:00
Rui Ueyama
3f1b071ae5 [ELF] Remove --warn-shared-textrel
It looks like the option is supported only by gold, and it doesn't
make much sense to me to have this option along with more generic
--warn-textrel. So I want to remove this before the next release.
2022-02-16 19:36:26 +09:00
Rui Ueyama
444cb7a566 [ELF] Improve the man page 2022-02-16 18:54:08 +09:00
Rui Ueyama
889f9f3a36 Simplify 2022-02-16 16:53:23 +09:00
Rui Ueyama
e4c4ab053e [ELF] Remove --shuffle-sections=N
This patch removes the --shuffle-sections option that takes an
argument as I'm still thinking about a better name for the option.

You can still use `--shuffle-sections` that doesn't take an argument.
2022-02-16 15:55:47 +09:00
Rui Ueyama
10ff2d705c Fix CI 2022-02-16 15:26:39 +09:00
Rui Ueyama
31f7427859 Rename a test file 2022-02-16 15:04:09 +09:00
Rui Ueyama
c338540885 [ELF] Handle relocations with r_sym == 0 correctly
If a relocation's r_sym value is 0 (i.e. it refers the undefined symbol
at the beginning of the symbol table), it has to handled as if S were 0.
We used to handle as if S were -1.

In addition to that, even if a relocation needs a dynamic base relocation,
it doesn't mean its expression is always S+A. For example, calling an
absolute address needs a dynamic relocation but its expression is S+A-P.

Fixes https://github.com/rui314/mold/issues/348
2022-02-16 13:18:22 +09:00
Rui Ueyama
d908d4c61c [ELF] Handle global symbols in mergeable sections correctly
Prior to this patch, mold computeed a wrong address for a global
symbol in a mergeable section. believe it was a regression in
60d0900496.

Fixes https://github.com/rui314/mold/issues/347
2022-02-16 12:05:40 +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
a7333bdb4e
Merge pull request #343 from dmantipov/fix-annoying-unused-variable-warnings
[ELF] Fix -Wunused-variable warnings
2022-02-14 21:27:57 +09:00
Dmitry Antipov
881b55d691 [ELF] Fix -Wunused-variable warning
Fix the following -Wunused-variable warning as reported by gcc:

elf/input-sections.cc:116:8: warning: unused variable ‘is_code’
[-Wunused-variable]
  116 |   bool is_code = (shdr().sh_flags & SHF_EXECINSTR);

Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com>
2022-02-14 15:22:00 +03:00