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

1201 Commits

Author SHA1 Message Date
Rui Ueyama
fe118f6347 Fix CI 2023-12-24 14:42:01 +09:00
Rui Ueyama
9554b92c86 Allow escaped meta-characters in version script patterns 2023-12-24 14:04:51 +09:00
Rui Ueyama
e1e16bf85a Fix version script priority
Previously, if two or more VERSION clauses match to the same symbol,
the first one took precedence. This was incompatible with GNU ld, which
gives the last one the highesth priority.

This change inverted the priority so that the last one will take
precedence other the others.

Fixes https://github.com/rui314/mold/issues/1158
2023-12-23 18:20:22 +09:00
Rui Ueyama
35516a6fc2 Do not include '@' in symbol name
Fixes https://github.com/rui314/mold/issues/1168
2023-12-23 15:37:39 +09:00
Rui Ueyama
e921486008 Fix CI
It seems some versions of objdump cannot disassemble c.li instruction.
2023-12-13 13:26:56 +09:00
Rui Ueyama
70d59ca1cd Improve test 2023-12-12 22:11:35 +09:00
Rui Ueyama
2ccaa81aab Relax a GOT load into a direct address materialization
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/397
2023-12-12 16:41:18 +09:00
Rui Ueyama
0c8a872c37 Avoid using the HOST environment variable
It seems HOST is a fairly common environment variable. Let's use
MACHINE instead.

Fixes https://github.com/rui314/mold/issues/1163
2023-12-07 09:45:29 +09:00
Rui Ueyama
3bc2e9bdb1 Revert "Set DF_SYMBOLIC if -Bsymbolic is given"
This reverts commit 9d35710419 to unbreak CI.
2023-12-04 16:07:56 +09:00
Rui Ueyama
9d35710419 Set DF_SYMBOLIC if -Bsymbolic is given
I don't think this would make any difference, but the ELF spec says
that the flag is set if symbols are bound locally.
2023-12-04 15:10:01 +09:00
Rui Ueyama
bdcf448605 Emit TLS common symbols in .tls_common
Section names are not significant in executables or DSOs, so this is
a purely aesthetic change.
2023-12-04 13:13:33 +09:00
Rui Ueyama
ea9864bbd5 Do not try to demangle C++ symbols as Rust ones
Previously, we always tried to demangle a symbol name as a Rust
symbol first and then attempted to demangle it as a C++ symbol.
This resulted in an incorrect demangled result, as the Rust legacy
mangling scheme is not distinguishable from C++.

This patch fix the issue by adding the "is_rust_obj" flag to the
ObjectFile. We try to demangle a symbol as a Rust one before as a C++
only if the flag is true.

Fixes https://github.com/rui314/mold/issues/1159
2023-11-30 13:53:23 +09:00
Rui Ueyama
6540294a81 Fix CI 2023-11-29 17:15:39 +09:00
Rui Ueyama
f4c5a8a42e Allow multiple .eh_frame sections in a single object file
A `.eh_frame` section contains data for exception handling. Usually,
an object file contains only one `.eh_frame` section, which explains
how to handle exceptions for all text sections in the same object file.

However, it appears that, in rare cases, we need to handle object
files containing multiple `.eh_frame` sections. An example of this is
the `/usr/lib/clang/17/lib/x86_64-redhat-linux-gnu/clang_rt.crtbegin.o`
file, which is provided by the `compiler-rt` package of Fedora 39.
Specifically, I'm using the `quay.io/fedora/fedora:39` Docker image.
The file contains two `.eh_frame` sections.

One `.eh_frame` in the file is of type `STT_X86_64_UNWIND` and the
other is of `STT_PROGBITS`. It's possible that the file was created
with `ld -r`, and the linker failed to merge the two incoming
`.eh_frame` sections into one output section due to the difference in
section types.

We did not expect such inputs and consequently produced corrupted
output files.

This commit improves our linker so that mold can handle multiple
`.eh_frame` sections in a single object file.

Fixes https://github.com/rui314/mold/issues/1157
2023-11-29 16:10:36 +09:00
Rui Ueyama
0fdbace9b2 Improve compatibility of precedences in version script patterns
Previously, symbol names or wildcard patterns in version script files
were processed strictly from top to bottom. When a single symbol
matches two or more patterns, the first one was given precedence.

However, GNU ld appears to treat exact matches differently, assigning
them higher precedence over wildcard patterns. This discrepancy led to
programs linked with Qt 6.6.1 using mold failing to launch.

Fixes https://github.com/rui314/mold/issues/1158
2023-11-28 15:43:48 +09:00
Rui Ueyama
000ce0ee52 Handle LLVM-generated TLSDESC code sequence
It had been assumed that the TLSDESC code seqeunce looks like this:

  lea    0(%rip), %rax
      R_X86_64_GOTPC32_TLSDESC    foo
  call   *(%rax)
      R_X86_64_TLSDESC_CALL       foo

However, LLVM seems to also emit something like this:

  lea    0(%rip), %reg
      R_X86_64_GOTPC32_TLSDESC    foo
  ...
  mov    %reg, %rax
  ...
  call   *(%rax)
      R_X86_64_TLSDESC_CALL       foo

That means when we rewrite the LEA instruction to relax the code
sequence, we need to handle destination registers other than %rax.

The wrong assumption caused a program crash as reported as
https://bugs.gentoo.org/914849.
2023-11-26 18:49:20 +09:00
Rui Ueyama
de7d37e1fc Do not count .tbss into account when creating PT_GNU_RELRO
Fixes https://github.com/rui314/mold/issues/1151
2023-11-21 11:44:52 +09:00
Rui Ueyama
3cb8a528a5 Make -z rewrite-endbr to work without -ffunction-sections
Now we can rewrite an endbr64 instruction even if it is not at the
beginning of a section.
2023-11-20 17:36:23 +09:00
Rui Ueyama
8bb01e1a0e Fix CI 2023-11-20 14:25:03 +09:00
Rui Ueyama
0416d7ed80 Add --nmagic
Fixes https://github.com/rui314/mold/issues/1144
2023-11-20 13:35:04 +09:00
Rui Ueyama
eb6c213f2a Add --spare-program-headers
This is a new experimental flag to make room at the end of PHDR
so that post-processing tools can add more entries as needed.

Fixes https://github.com/rui314/mold/issues/1148
2023-11-16 12:07:13 +09:00
Rui Ueyama
6e97393740 Fix tests 2023-11-14 12:44:02 +09:00
Rui Ueyama
ff3d54d26f Fix a crash bug in --defsym
Fixes https://github.com/rui314/mold/issues/1108
2023-11-13 20:09:25 +09:00
Rui Ueyama
60bc56848f Fix tests for Debian 9 2023-11-13 13:37:35 +09:00
Rui Ueyama
da3f5dd4ec Fix --dynamic-list for DSOs
--dynamic-list, --export-dynamic-symbol and --export-dynamic-symbol-list
have different semantics for executables and DSOs. If the output is an
executable, they specify a list of symbols that are to be exported.
If the output is a shared object, they specify the list of symbols that
are to be interposable.

mold havne't implemented the latter semantics. This commit fixes that
issue.

Fixes https://github.com/rui314/mold/issues/1071
2023-11-12 13:00:24 +09:00
Rui Ueyama
8131528305 Rename long .rodata section names 2023-11-10 15:07:19 +09:00
Rui Ueyama
3f88964527 Map .ctors/.dtors into .init_array/.fini_array
.init_array/.fini_array haven't completely replace .ctors/.dtors, so
we need to convert .ctors/.dtors to .init_array/.fini_array.

Fixes https://github.com/rui314/mold/issues/1113
2023-11-09 12:43:58 +09:00
Rui Ueyama
0c6daad215 Add more tests 2023-11-07 15:20:31 +09:00
Rui Ueyama
8c35c80bb7 Enable qemu tests by default 2023-11-07 13:55:56 +09:00
Rui Ueyama
d42ba3bae4 Fix CI 2023-11-07 13:48:48 +09:00
Rui Ueyama
8c337b25df Run power10 tests on qemu only if qemu and cross GCC suports power10 2023-11-07 12:04:22 +09:00
Rui Ueyama
8d1c08bd03 Simplify 2023-11-07 11:25:03 +09:00
Rui Ueyama
5599a6f24f Skip test only on qemu 2023-11-07 11:06:13 +09:00
Rui Ueyama
ef9a610dd1 Run tests as long as qemu and cross compiler are available
So that we can catch bugs like e11d64b5c7
earlier.
2023-11-07 11:00:26 +09:00
Rui Ueyama
e11d64b5c7 Do not run tests under qemu-i386 on i686 native host
Fixes https://github.com/rui314/mold/issues/1140
2023-11-06 12:44:28 +09:00
Rui Ueyama
9d91a2bc23 Revert "Do not crash if defsym'ed symbol didn't exist"
This reverts commit 5c7a75b3e4 and
8c41f21d3c because they broke CI.
2023-11-06 12:43:20 +09:00
Rui Ueyama
8c41f21d3c Fix CI 2023-11-05 22:30:43 +09:00
Rui Ueyama
5c7a75b3e4 Do not crash if defsym'ed symbol didn't exist
Fixes https://github.com/rui314/mold/issues/1108
2023-11-05 16:37:09 +09:00
Rui Ueyama
0f78fa9c43 Attempt to fix tests on 32-bit x86
Fixes https://github.com/rui314/mold/issues/1140
2023-11-05 11:01:31 +09:00
Rui Ueyama
348e44a9c4 Reorganize tests 2023-11-04 14:43:47 +09:00
Rui Ueyama
42f663cac0 Silence TSAN errors that I believe false 2023-11-04 09:07:28 +09:00
Rui Ueyama
4dd5d2f8cb Propagate mergeable sections' sh_entsize and sh_addralign attributes
For --relocatable output, we need to pass through these attributes
for correctness. With this change, we'll have more .rodata sections
such as .rodata.str1.1, rodata.str1.4, etc. in the final executable,
but that should be fine because the runtime doesn't care about
section tables at all. The table isn't even loaded to memory at runtime.
2023-11-03 21:34:17 +09:00
Rui Ueyama
4cdfc7e72c Do not emit text relocations for IFUNC symbols in PDEs
IFUNC symbols are resolved at process startup by executing the function
that the symbol points to. This is used to select the "best" function at
runtime; for instance, the runtime may choose a faster version of memcpy
that uses SIMD instructions if they are available on the current system.

Thus, an IFUNC symbol has two addresses: the initial address (or the
resolver's address) and the resolved address, which is the return value of
the resolver.

In position-independent executables (PIEs), function pointers are loaded
from the GOT indirectly, and symbols are not directly referenced. In such
executables, the initial value of the GOT slot for an IFUNC symbol
contains the resolver address, and this is overwritten at runtime to the
resolved address upon process startup. When user code takes a pointer to
an IFUNC, it always reads the resolved address from GOT.

In contrast, position-dependent executables (PDEs) may have instructions
that directly refer to an IFUNC symbol, such as movabs on x86-64. The GOT
entry for an IFUNC holds the resolved address, so any direct reference
must also produce the resolved address to maintain pointer equality.
(C/C++ standards require that two pointers must be equal if and only if
they are taken for the same symbol.)

Previously, we emitted text relocations to modify instruction operands.
However, text relocations are undesirable and not always reliable. For
example, on ARM64, multiple instructions are used to materialize a
symbol's address, and it's not feasible to issue a dynamic relocation to
alter those instructions since the dynamic loader generally can only
modify 32-bit or 64-bit words.

In this commit, I have adopted a different strategy. An IFUNC symbol now
occupies two consecutive GOT slots in a PDE. The first slot holds the
symbol's PLT address, and the second slot holds the resolved address. The
PLT address is consistently used as the symbol's address throughout the
process, while the second slot is used only by the PLT entry to jump to
the resolved address.

This method ensures pointer equality without the need to emit text
relocations for IFUNC symbols in PDEs.
2023-11-02 12:27:55 +09:00
Rui Ueyama
f3de82b2a2 Do not add the same set of tests twice 2023-10-31 19:32:46 +09:00
Rui Ueyama
0c62a91ded Enable loongarch64 tests on loongarch64 hosts 2023-10-31 16:15:14 +09:00
Rui Ueyama
3229b5b7e3 Fix test 2023-10-31 12:22:39 +09:00
Rui Ueyama
4b4219fc33 Fix tests for ARM32-on-ARM64 systems 2023-10-30 13:02:36 +09:00
Rui Ueyama
782ff4f582 Fix test 2023-10-27 13:40:09 +09:00
Christoph Erhardt
a31679cf04 Fix aarch64_variant-pcs.sh test on Linux
The test expects the output format given by `llvm-readelf`:
```
5: 0000000000010698     0 FUNC    GLOBAL DEFAULT [VARIANT_PCS]   13 foo
```

However, in GNU's `readelf` implementation the symbol name comes first:
```
5: 0000000000010698     0 FUNC    GLOBAL DEFAULT   13 foo  [VARIANT_PCS]
```

Replace the regular expression with two `grep` calls piped together to
support both output formats.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2023-10-26 23:59:24 +02:00
Rui Ueyama
2d4ba3ac74 Skip a test if musl
musl's tlsdesc implementation for arm32 is buggy.

Fixes https://github.com/rui314/mold/issues/1135
2023-10-23 23:47:13 +09:00