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

3669 Commits

Author SHA1 Message Date
Rui Ueyama
d4bbf31db2 [ELF] Add the --noinhibit-exec option
Fixes https://github.com/rui314/mold/issues/370
2022-02-28 13:03:35 +09:00
Rui Ueyama
9b5d404d1e Simplify 2022-02-27 20:59:59 +09:00
Rui Ueyama
4caadefac6 Refactor 2022-02-27 15:21:06 +09:00
Rui Ueyama
8f21cc386e [ELF] Merge --shuffle-sections-seed into --shuffle-sections 2022-02-27 14:25:10 +09:00
Rui Ueyama
f7de9571f8 Refactor 2022-02-27 14:24:14 +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
41986279de [ELF] Do not create multiple .init_array output sections
Usually, init_array is readable and writable, but it looks like rustc
with `-C lto=fat` create a read-only .init_array. mold used to create
two output .init_array sections for read/write and read-only
init_array input sections. That caused one of them are not executed
on startup.

Now, mold create read/write .init_array output section even if an
input .init_array section is read-only.

Fixes https://github.com/rui314/mold/issues/363
2022-02-25 22:54:55 +09:00
Rui Ueyama
480efdedf0 [ELF] Fix IBT-enabled PLT
We used to emit the following sequence for each PLT entry.

    0xf3, 0x0f, 0x1e, 0xfa, // endbr64
    0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOTPLT
    0xe8, 0, 0, 0, 0,       // call PLT[0]

In the above instruction sequence, `jmp` was expected to jump to the
following `call` instruction if the PLT entry is executed for the
first time. However, it wouldn't work because we needed another
`endbr64` before `call`.

This problem should be fixed in this commit. Now, the PLT header is
32 bytes long and each entry is 16 bytes.
2022-02-25 12:43:43 +09:00
Rui Ueyama
99e3f959fc [ELF] Make IBTPLT header a bit shorter 2022-02-24 19:56:41 +09:00
Rui Ueyama
4ec0bbf048 [ELF] Shrink the size of IBTPLT entry from 32 bytes to 16 bytes
IBT-enabled PLT section is sparse as 2/3 of the section contents are
NOP instructions. In this patch, I implemented alternative instruction
sequences for IBTPLT, so that each IBTPLT entry occupies only 16 bytes
instead of 32 bytes.

In return, our new IBTPLT section needs a 64 bytes header instead of a
16 bytes one, but it's overall a good deal because we usually have many
PLT entries.
2022-02-24 17:55:17 +09:00
Rui Ueyama
f4c0e321db [ELF] Do not use BND JMP
BND JMP instruction is a part of of Intel MPX instructions.
Intel MPX instructions are deprecated by Intel now.
2022-02-24 14:26:40 +09:00
Rui Ueyama
31a5cdf86f [ELF] Verify a relocation after TLSGD or TLSLD 2022-02-24 12:32:02 +09:00
Rui Ueyama
a44de89991 Fix CI
`-m32` doesn't work on CI for some reason, so I'll remove the test
file for now.
2022-02-24 11:32:00 +09:00
Rui Ueyama
30683645c2 [ELF] Do not corrupt compressed debug sections on i386
Previously, if an input debug section is compressed, mold produced
corrupted output debug section on i386.

Fixes https://github.com/rui314/mold/issues/361
2022-02-24 11:05:54 +09:00
Rui Ueyama
ac3ae60184 Format 2022-02-24 11:05:54 +09:00
Rui Ueyama
9f34830882 [ELF] Relax TLSLD followed by GOTPCREL, GOTPCRELX or REX_GOTPCRELX 2022-02-23 23:53:57 +09:00
Rui Ueyama
4aa4bfa4a6 [ELF] Fix TLSGD/TLSLD relaxation
When we relax R_X86_64_TLSGD or R_X86_64_TLSGD, we rewrite two
instructions (the one referred by TLSGD/TLSLD and the following one
referred by the following relocation). The second instruction is
usually 5 bytes, but if it can be longer than that, and if that's the
case, we need to emit a nop to fill the gap at the end of the longer
instruction.

We didn't do that. As a result, the remaining garbage of the second
instruction is executed and caused an unpredictable result (illegal
instruction or segv).

This patch fixes the issue.

Fixes https://github.com/rui314/mold/issues/360
2022-02-23 16:16:53 +09:00
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