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

3697 Commits

Author SHA1 Message Date
Rui Ueyama
9e11b40a99 [ELF] Do not allocate a byte for an empty class
In C++, the size of an empty class is 1 rather than 0 because every
object is guaranteed to have a unique address. But if we do not need
the unique address guarantee, we can add `[[no_unique_address]]` to
a class member to save 1 byte. This is a new C++20 feature.
2022-03-06 12:20:31 +09:00
Rui Ueyama
a4fd7e3819 [ELF] Remove redundant foo/.. from library paths 2022-03-05 21:28:43 +09:00
Rui Ueyama
aae3dc3c1e Refactor 2022-03-05 20:27:10 +09:00
Rui Ueyama
ba7967152d Refactor 2022-03-05 20:14:43 +09:00
Rui Ueyama
d6dae3be6d [ELF] Report errors more strictly for unrepresentable relocations 2022-03-05 14:59:31 +09:00
Rui Ueyama
83aaa63a49 [ELF][i386] Make GOT-relative relocs relative to .got instead of .got.plt
We used to compute offsets from .got.plt for GOT-relative relocations,
but according to the i386 psABI, they should be relative to .got.
2022-03-05 12:13:04 +09:00
Rui Ueyama
b0d91b9967 [ELF] Add -warn-shared-textrel
Fixes https://github.com/rui314/mold/issues/377
2022-03-05 10:59:04 +09:00
Rui Ueyama
4ea052591a
Merge pull request #378 from gruenich/main
input-files: Remove unused variable size
2022-03-05 09:49:57 +09:00
Christoph Grüninger
2f03e46bb3 input-files: Remove unused variable size
Removed code has no effect.
Left-over from code removal in 4dae896726.

Signed-off-by: Christoph Grüninger <foss@grueninger.de>
2022-03-05 00:30:30 +01:00
Rui Ueyama
6205a1edc3 Update the man page 2022-03-04 14:54:10 +09:00
Rui Ueyama
4dea134949 [ELF] Do not compute the contents of .eh_frame twice 2022-03-03 20:07:45 +09:00
Rui Ueyama
eb79859ea2 [ELF] Always set _GLOBAL_OFFSET_TABLE_ to the beginning of .got
Previously, we set the address of `_GLOBAL_OFFSET_TABLE_` to `.got.plt`
on i386 and x86-64 and to `.got` on other targets. But it looks like
this special treament of x86 isn't necessary. The x86-64 psABI said
that the symbol can even be in the middle of `.got` (*1). If `.got.plt`
is missing, GNU linker set it to `.got`.

This commit unconditionally set the symbol value to `.got`.

(*1) x86-64 psABI 1.0 p.77: "The symbol _GLOBAL_OFFSET_TABLE_ may
reside in the middle of the .got section, allowing both negative and
non-negative offsets into the array of addresses."
2022-03-03 12:10:26 +09:00
Rui Ueyama
8714b78d48 [ELF] Reduce memory usage a bit 2022-03-03 10:28:27 +09:00
Rui Ueyama
86b142e555 [ELF] Do not create DT_INIT/DT_FINI if _init/_fini are in a .so
Fixes https://github.com/rui314/mold/issues/372
2022-03-02 21:12:41 +09:00
Rui Ueyama
e5549c73f0 Remove an unused class 2022-03-02 17:37:38 +09:00
Rui Ueyama
4dae896726 [ELF] Reduce the size of InputSection from 88 bytes to 72 bytes 2022-03-02 17:27:31 +09:00
Rui Ueyama
83e05dae28 [ELF] Reduce the size of FdeRecord from 24 bytes to 16 bytes
It saves 8 bytes for each input function.
2022-03-02 16:25:17 +09:00
Rui Ueyama
99a0aaf133 [ELF] Add a test for -init 2022-03-02 10:35:32 +09:00
Rui Ueyama
7068c0cd0f [ELF] Reduce the size of InputSection from 120 bytes to 88 bytes 2022-03-01 17:49:17 +09:00
Rui Ueyama
f49e4024e9 Rename a variable 2022-03-01 17:08:14 +09:00
Rui Ueyama
567a78dbd5 [ELF] Do not directly read st_shndx
If st_shndx is 0xffff, the actual section index value is in a
SHT_SYMTAB_SHNDX section.
2022-03-01 14:47:51 +09:00
Rui Ueyama
f2d27d8d24 [ELF] Shrink the size of Symbol from 56 bytes to 48 bytes
This is a second attempt to reduce the size of the Symbol class.
2022-03-01 12:03:35 +09:00
Rui Ueyama
dc9573989c Refactor 2022-03-01 11:37:49 +09:00
Rui Ueyama
e469b04f0d Revert "[ELF] Shrink the size of Symbol from 56 bytes to 48 bytes"
This reverts commit 32e158d340
because it broke some tests when mold is built with itself.
2022-03-01 07:49:57 +09:00
Rui Ueyama
32e158d340 [ELF] Shrink the size of Symbol from 56 bytes to 48 bytes 2022-02-28 20:53:40 +09:00
Rui Ueyama
18b6f96756 Refactor 2022-02-28 19:42:01 +09:00
Rui Ueyama
2b7dbb01c4 Rename a file 2022-02-28 16:20:37 +09:00
Rui Ueyama
c1c9bdf363 Optimize BigEndian class
Despite its comment, gcc sometimes failed to optimize the loop into
single `bswap` instruction. So it looks like we should explicitly use
`__builtin_bswap` functions.
2022-02-28 16:17:11 +09:00
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