1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-04 16:48:04 +03:00
Commit Graph

385 Commits

Author SHA1 Message Date
Rui Ueyama
58f6502a1c [Mach-O] Add static archive file support 2021-10-28 14:37:18 +09:00
Rui Ueyama
7236d14650 [Mach-O] Report errors for remaining undefined symbols 2021-10-27 21:46:57 +09:00
Rui Ueyama
6cdfd45134 [Mach-O] Create GOT entries for internal references 2021-10-27 15:57:31 +09:00
Rui Ueyama
5549a005f1 [Mach-O] Create GOT entries for external references 2021-10-26 17:44:57 +09:00
Rui Ueyama
5837fe75eb [Mach-O] wip 2021-10-26 16:38:44 +09:00
Rui Ueyama
d7fb95fa63 [Mach-O] wip 2021-10-26 15:26:08 +09:00
Rui Ueyama
8471f47abb [Mach-O] wip 2021-10-26 15:24:23 +09:00
Rui Ueyama
48e7616263 [Mach-O] Add the -platform_version option 2021-10-26 15:14:14 +09:00
Rui Ueyama
d6657a3cb0 [Mach-O] Add the -headerpad option 2021-10-25 20:14:52 +09:00
Rui Ueyama
5817265e91 [Mach-O] Fix ASAN issue 2021-10-25 20:14:32 +09:00
Rui Ueyama
a86ad2771a [Mach-O] Use clang as a linker frontend
Now that we can link a "hello world" program on macOS, we can
use clang as a linker frontend.
2021-10-25 19:09:18 +09:00
Rui Ueyama
4b6407dfc0 [Mach-O] wip 2021-10-23 17:45:45 +09:00
Rui Ueyama
e6c614d69c [ELF] Remove extra path separators 2021-10-12 18:32:20 +09:00
Rui Ueyama
ffb8e03c97 [ELF] Make .rela.dyn and .rela.plt contiguous in an output file
glibc 2.22 or prior have a bug that the dynamic linker (ld-linux.so.2)
crashes on `dlopen` if .rela.dyn and .rela.plt are not contiguous in
the `dlopen`-ed file and RTLD_NOW is specified. That bug was fixed in
fa19d5c48a.

glibc 2.23 which includes the fix for the bug was released on 2016-02-18.
So, unless you are using glibc that is more than 5 years old, mold-
generated shared object files work fine with `dlopen`. But it is easy
to make the sections contiguous in file, so I'll commit this change as a
workaround for the bug.

Fixes https://github.com/rui314/mold/issues/120
2021-10-12 17:10:32 +09:00
Rui Ueyama
a8b2f521f7 [ELF] Create .rodata.cst and .rodata.str sections
Previously, mold created two or more ".rodata" sections if input files
contain regular .rodata sections as well as .rodata.str* or .rodata.cst*
sections. This is because .rodata.str* and .rodata.cst* contains mergeable
section contents (i.e. string constants and constant pools, respectively),
and they are handled in a special way.

In ELF, section names are not significant, so nothing is wrong with
creating multiple .rodata. However, valgrind unfortunately doesn't like
such executable.

With this change, mold keeps ".rodata.str" and ".rodata.cst" prefixes
to avoid creating multiple ".rodata" sections.

Fixes https://github.com/rui314/mold/issues/118
2021-10-07 13:55:46 +09:00
Rui Ueyama
301d45b2fa Fix a test 2021-10-06 22:04:25 +09:00
Rui Ueyama
3c513a31cc [Mach-O] Apply relocations 2021-10-06 14:33:01 +09:00
Rui Ueyama
4932daadba [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama
8965de697b [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama
840d19bb5e [Mach-O] Add -o option 2021-10-05 11:40:32 +09:00
Rui Ueyama
ffd34678e0 [ELF] Fix "mold-wrapper.so is not found" error 2021-09-30 15:01:55 +09:00
Rui Ueyama
d123009460 [Mach-O] Add a test 2021-09-28 21:55:37 +09:00
Rui Ueyama
9d805f5d26 [Mach-O] Make make test to work on macOS 2021-09-28 18:47:24 +09:00
Rui Ueyama
774fc0f340 [ELF] Remove an extra space in an error message 2021-09-26 12:43:39 +09:00
Rui Ueyama
e4861bb3e1 [ELF] Fix "recompile with -fPIC" error
mold used to emit a spurious "recompile with -fPIC" error when creating
a position-dependent executable. This is because we alwyas create
dynamic relocations for importe symbols. If the relocated place is
read-only, we can't apply a dynamic relocation, and we printed out the
error message.

This patch fixes the issue by creating copy relocations and PLTs for
such symbols.

Fixes https://github.com/rui314/mold/issues/116
2021-09-25 18:13:26 +09:00
Rui Ueyama
5ea876ff2f [Mach-O] wip 2021-09-15 21:00:34 +09:00
Rui Ueyama
08b61f29d2 [ELF] Add --require-defined 2021-09-12 18:34:42 +09:00
Rui Ueyama
1cb750a649 [ELF] Add -Bno-symbolic 2021-09-11 21:41:17 +09:00
Rui Ueyama
8f10ac5047 [Mach-O] Add a test for mach-o stub 2021-09-08 19:19:07 +09:00
Rui Ueyama
5dab8612c8 Move ELF tests to test/elf directory 2021-09-08 19:13:18 +09:00
Rui Ueyama
bfa24a3205 Create temporary files for tests under out/ 2021-09-08 19:08:52 +09:00
Rui Ueyama
b39a47a759 Promote weak undefs to dynamic symbols if building DSO
475a250ad4 changed mold's behavior on
weak undefined symbols, so that if they are not resolved within the
current ELF module, they are resolved to address zero. Previously,
they would be promoted to dynamic symbols to give then another chance
to be resolved at runtime.

That change caused a regression in Firefox. Firefox uses weak undef
symbols as a mean to export symbols from libxul.so. Quote from
Firefox's mfbt/Types.h:

> On linux mozglue is linked in the program and we link libxul.so with
> -z,defs. Normally that causes the linker to reject undefined references in
> libxul.so, but as a loophole it allows undefined references to weak
> symbols. We add the weak attribute to the import version of the MFBT API
> macros to exploit this.

So, they use this as a "loophole".

This change partially revert 475a250ad4.
Now, remaining weak undefs are resolved to address zero only when we
are creating an executable.

Fixes https://github.com/rui314/mold/issues/114
2021-09-06 20:47:16 +09:00
Rui Ueyama
b3d0ee093b Report the "recompile with -fPIC' error correctly 2021-08-30 21:07:27 +09:00
Rui Ueyama
d3577550d2 Fix filename typo 2021-08-30 20:52:28 +09:00
Rui Ueyama
c50dd18881 Fix an issue that local symbols are exported
We sometimes put local symbols into .dynsym, but if they are
global symbols hidden by a version script, they were exported
from .dynsym. This patch correctly makes them local symbols.
2021-08-29 13:04:23 +09:00
Rui Ueyama
d06e2f71f3 Attempt to fix CI 2021-08-28 20:47:45 +09:00
Rui Ueyama
d43e43adbb Add a test 2021-08-28 14:50:19 +09:00
Rui Ueyama
475a250ad4 Do not promote unresolved weak undefs to dynamic symbols
Previously, we try to promote unresolved weak undefined symbols to
dynamic symbols so that they will get another chance to be resolved at
runtime. This is not always doable. Consider the following two cases:

 - There's a relocation that directly refers a weak undefined symbol

 - There's a relocation that is in a read-only section

In the former case, we need to create a copy relocation, but we can't
do that against a weak undef becasue a weak undef doesn't have the notion
of the symbol size.

In the latter case, we need to create a dynamic relocation, but such
dynamic relocation would fail at load-time when the runtime linker tries
to mutate the contents of a read-only section.

So, we had a logic to detect the above cases and promote weak undefs
only when they can be promoted. But the logic is not as robust as I
hoped. So, in this patch, I removed the logic and stop promoting weak
undefs.
2021-08-27 12:50:23 +09:00
Rui Ueyama
684962b84c Support TLSGD relocations for AArch64 2021-08-24 06:29:04 +00:00
Rui Ueyama
5912a0022f Fix CI 2021-08-23 18:40:05 +09:00
Rui Ueyama
f0f40d073b Fix tests for AArch64 2021-08-23 09:21:31 +00:00
Rui Ueyama
bb1ec6177f Fix TLSDESC relocations against imported symbols
Such relocations shouldn't be relaxed to local-exec, as they are
not local.
2021-08-23 13:38:53 +09:00
Rui Ueyama
7f943d1445 Implement TLSDESC relaxation for AArch64 2021-08-23 03:24:18 +00:00
Rui Ueyama
4c710df347 Fix TLSDESC relocations for statically-linked executables
We shouldn't create TLSDESC dynamic relocations for statically-
linked executables because such executables don't contain the
tranpoline function needed for TLSDESC. Instead, we should
always relax these relocations.
2021-08-22 22:01:38 +09:00
Rui Ueyama
3c79d672dc Implement TLSDESC for AArch64 2021-08-22 11:34:22 +00:00
Rui Ueyama
a82bc71088 Fix test/nocopyreloc.sh for AARCH64 2021-08-22 10:33:38 +00:00
Rui Ueyama
96589d4acf Allow to put local symbols to .dynsym
We used to write only global symbols to .dynsym because, in most
use cases, .dynsym are used for resolving inter-module dependencies.
However, we need to put local symbols to .dynsym if they are thread-
local symbols.
2021-08-22 19:28:37 +09:00
Rui Ueyama
f570c4e9e8 Fix tests for AARCH64 2021-08-20 09:48:10 +00:00
Rui Ueyama
2a3639a7d8 Fix tests for AARCH63 2021-08-19 12:31:23 +00:00
Rui Ueyama
34558f410d Do not generate dynrels against RO sections for weak undef symbols
Previously, we created dynamic relocations against read-only sections
if the sections contain relocations against weak undefined symbols.
Since such dynamic relocations cannot be applied at load-time, the
generated executables failed with SEGV.

Now, such relocations are resolved to address 0.

Reported at https://github.com/rui314/mold/pull/110
2021-08-17 17:23:22 +09:00