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

936 Commits

Author SHA1 Message Date
Rui Ueyama
bad0cbc72a Revert "Remove a test that doesn't work yet"
This reverts commit bd65e0908f
because --gdb-index should now work with DWARF5.
2022-04-21 19:23:51 +08:00
Martin Liska
b3e0955d88 Use -batch mode for gdb tests.
Use the mode, otherwise one can be asked things like:
Quit anyway? (y or n)

which make the test stuck.

Signed-off-by: Martin Liska <mliska@suse.cz>
2022-04-21 10:15:45 +02:00
Rui Ueyama
f12a9bb5ff Fix possible "recompile with -fPIC" errors
Fixes https://github.com/rui314/mold/issues/449
2022-04-21 15:38:12 +08:00
Rui Ueyama
cf850f8993 [ELF] Handle TLS common symbols
Fixes https://github.com/rui314/mold/issues/447
2022-04-21 13:58:43 +08:00
Rui Ueyama
ec062f7241 [ELF] Accept DWARF 2 and 3 for --gdb-index 2022-04-21 10:21:53 +08:00
Rui Ueyama
fc798bc4ea Refactor 2022-04-21 09:59:36 +08:00
Rui Ueyama
bd65e0908f Remove a test that doesn't work yet 2022-04-21 09:59:36 +08:00
Martin Liska
32e0863675 Fix assembler warnings for a testcase.
Fixes:

Testing execstack-if-needed ... {standard input}: Assembler messages:
{standard input}:4: Warning: setting incorrect section type for .note.GNU-stack
{standard input}:4: Warning: setting incorrect section attributes for .note.GNU-stack

Signed-off-by: Martin Liska <mliska@suse.cz>
2022-04-20 10:56:23 +02:00
Rui Ueyama
8398d592de [ELF] Add -z execstack-if-needed
Fixes https://github.com/rui314/mold/issues/427
2022-04-20 15:17:55 +08:00
Rui Ueyama
21e1a80cec Add a test 2022-04-19 13:51:38 +08:00
Rui Ueyama
a4398c7c32 [ELF] Factor out DWARF-related code to dwarf.cc 2022-04-19 12:43:51 +08:00
Rui Ueyama
70bd1adbab [ELF] Handle --print-dependencies early
So that the dependency info is printed out even if the link will
eventually fail.
2022-04-17 19:06:58 +08:00
Rui Ueyama
45df585268 Remove test for executable DSO
This test fails on some Linux systems, and it is essentially testing
not the mold's capabilities but the running platform's capabilities.
I don't think there's a portable, guaranteed way to create an
executable shared object on Linux, so even if it happens to work,
I don't think we can guarantee that.
2022-04-17 15:01:28 +08:00
Rui Ueyama
deb212bbfc Fix for a compiler that does not support -gz=zlib-gnu 2022-04-17 14:51:23 +08:00
Rui Ueyama
b0596ab8fb Run only for native target 2022-04-17 12:32:42 +08:00
Rui Ueyama
b5a75c4215 [ELF] Support DWARF5 for --gdb-index
mold used to support only DWARF4.

Fixes https://github.com/rui314/mold/issues/436
2022-04-17 10:19:58 +08:00
Rui Ueyama
c90801e629 [ELF] Make --gdb-index work for compressed input debug sections
Previously, --gdb-index tries to read bogus compressed data from
input sections if input debug sections are compressed.

Fixes https://github.com/rui314/mold/issues/431
2022-04-16 15:00:21 +08:00
Rui Ueyama
6a6ae217a3
Merge pull request #433 from sicherha/suppress-debuginfod-prompt
Fix hanging unit test `gdb-index`
2022-04-16 10:38:11 +08:00
Christoph Erhardt
133946af0c Skip test if dwarfdump is unavailable
Fixes #430.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-04-15 20:34:04 +02:00
Christoph Erhardt
c6ae4234b8 Fix hanging unit test gdb-index
This affects Fedora >= 35, where debuginfod is enabled by default. On
such systems, gdb shows the following interactive prompt and then waits
forever:
```
This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.fedoraproject.org/
Enable debuginfod for this session? (y or [n])
```

Unsetting the `DEBUGINFOD_URLS` environment variable disables the prompt
as documented here: https://fedoraproject.org/wiki/Debuginfod#Disabling

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-04-15 19:08:15 +02:00
Rui Ueyama
100922b650 [ELF] Fix section file offsets
Previously, if a section has a very large alignment requirement,
that section and the following sections may get wrong file offsets.

Fixes https://github.com/rui314/mold/issues/405
2022-04-15 14:59:09 +08:00
Rui Ueyama
0daf6233fb [ELF] Fix R_RISCV_ALIGN relocations
Fixes https://github.com/rui314/mold/issues/419
2022-04-15 14:37:55 +08:00
Rui Ueyama
d0e4eee204 [ELF] Print out a warning for .note.GNU-stack
https://github.com/rui314/mold/issues/427
2022-04-14 11:47:54 +08:00
Rui Ueyama
a7475dd5e3 [ELF] Support --gdb-index
This is a tough one because .gdb_index, .debug_gnu_pubnames,
.debug_gnu_pubtypes and DWARF are underdocumented, and DWARF is
complicated even if you have a right documentation. But, I believe I
managed to create a correct .gdb_index section.

Just like ld.lld, mold's --gdb-index needs all input object files to
have been compiled with -ggnu-pubnames. We read symbol names and type
names from the sections generated by -ggnu-pubnames.

Unlike ld.gold and ld.lld, we do not use an external library to read
DWARF debug info records.

As always, this feature is implemented with speed in mind. For Clang
15 which is built with -ggnu-pubnames, mold takes ~150 ms to create a
~300 MiB .gdb_index section on a simulated 16-core machine.

Fixes https://github.com/rui314/mold/issues/396
2022-04-13 19:01:17 +08:00
Rui Ueyama
d1b9549817 [ELF] Do not ignore --dynamic-linker even if --shared is given
It is very rare, but technically you can create a shared object that
can also be executed directly. You can do that by giving a dynamic
linker path to the linker.

https://github.com/rui314/mold/issues/422
2022-04-09 18:35:04 +08:00
Rui Ueyama
87a5f238dd Fix CI 2022-04-09 13:18:22 +08:00
Rui Ueyama
e448e0eb2b [ELF] Write tombstone values to dead debug info records
This is an attempt to fix https://github.com/rui314/mold/issues/357.
2022-04-09 10:40:25 +08:00
Rui Ueyama
5feab826de [ELF] Fix _TLS_MODULE_BASE_ relocations
Fixes https://github.com/rui314/mold/issues/421
2022-04-08 13:34:43 +08:00
Rui Ueyama
f0a030cbcd [ELF] Add --disable-new-dtags
Fixes https://github.com/rui314/mold/issues/420
2022-04-07 15:26:59 +08:00
Rui Ueyama
731dd0ed25 [ELF] Support --oformat=binary
With this change, you can link a simple bootloader using mold.
To do so, compile bootloader source files to object files with
the `-fno-PIC` flag and then invoke mold on the object files with
`-Ttext=<bootloader-start-address>` and `--oformat=binary`.

The .text segment is usually at the beginning of the output file if
the file is created that way. By passing the startup code as the first
file argument to the linker, you can place that startup code at the
beginning of the file.

Fixes https://github.com/rui314/mold/issues/418
2022-04-06 19:13:43 +08:00
Rui Ueyama
23045c6f95 [ELF] Do not create synthetic sections if not necessary 2022-04-06 18:04:42 +08:00
Rui Ueyama
2d29f234e2 [ELF] Change output section layout 2022-04-06 16:35:38 +08:00
Rui Ueyama
4edaf82691 Fix CI 2022-04-06 15:03:37 +08:00
Rui Ueyama
49aa10318c [ELF] Add --section-start 2022-04-06 14:45:31 +08:00
Rui Ueyama
e0bc74ad8a [ELF] Create canonical PLTs only when needed
Previously, we make all PLT entries canonical if we are creating
a position dependent executable, because I was thinking that promoting
usual PLT entries to canonical ones is harmless; symbol equality still
holds.

However, it looks like Qt depends on the usual linker's behavior not
to make PLT canonical if not necessary. I believe they are maintaining
some hidden symbol as aliases for exported symbols and compare their
addresses at runtime.

Of course this doesn't work if your program is not compiled with -fPIC,
but qt5/QtCore/qglobal.h has a macro to abort compilation if PIC is
disabled. (They check for __PIC__ and __PIE__ macros.) So, all object
files are guaranteed to be compiled with -fPIC if they are using QT
functions, and they assume that the linker doesn't create a canonical
PLT for Qt functions.

This commit makes mold to create canonical PLTs only when needed.
That is, if an address of a function is directly taken (i.e. not via
GOT), then mold makes its PLT canonical.

Fixes https://github.com/rui314/mold/issues/352
2022-04-05 21:02:42 +08:00
Rui Ueyama
3768ca612e [ELF] Deprecate --preload
It looks like no one is using --preload, so there's no point to
maintain this feature.

https://github.com/rui314/mold/issues/414
2022-04-05 12:41:50 +08:00
Rui Ueyama
91947405fe Attempt to silence CI 2022-04-04 17:06:47 +08:00
Rui Ueyama
b7123bded5 [ELF] Fix tests for non-x86-64 targets 2022-04-04 16:36:43 +08:00
Rui Ueyama
392781a0e2 [ELF][i386] Sort .ctors and .dtors sections 2022-04-03 10:43:22 +08:00
Rui Ueyama
4e10ee7e50 [ELF] Run tests for all targets on CI 2022-04-02 21:27:45 +08:00
Rui Ueyama
8d94fd6ca3 [ELF][ARM64] Fix a test 2022-04-02 18:05:05 +08:00
Rui Ueyama
358f244247 [ELF][RISCV64] Fix a test 2022-04-02 18:00:23 +08:00
Rui Ueyama
e6d4154688 [ELF] Generalize tests
With this change, you can now cross compile test cases and run
them on qemu-user. Here is an example to run our test suits in
an emulated ARM32 environment.

$ CC=arm-linux-gnueabihf-gcc \
  CXX=arm-linux-gnueabihf-g++ \
  GCC=arm-linux-gnueabihf-gcc \
  GXX=arm-linux-gnueabihf-g++ \
  OBJDUMP=arm-linux-gnueabihf-objdump \
  MACHINE=arm \
  QEMU='qemu-arm -L /usr/arm-linux-gnueabihf' \
  make -j16 test
2022-04-02 16:53:41 +08:00
Rui Ueyama
0ecd72900e Attempt to fix CI 2022-04-01 13:32:01 +08:00
Rui Ueyama
8196199cac Refactor 2022-04-01 12:52:21 +08:00
Rui Ueyama
fe617c3618 [ELF][ARM32] Support R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS 2022-04-01 02:47:29 +00:00
Rui Ueyama
e3a7c9e017 [ELF][RISCV] Disable a test that doesn't work with RISCV64 2022-03-31 13:24:34 +00:00
Rui Ueyama
d9ea875677 [ELF][ARM32] Implement many relocations
With this change, most tests in test/elf/ directory pass on ARM32.
2022-03-30 09:26:32 +00:00
Rui Ueyama
577361478a Fix CI
This reverts commit 408e2bfee8.
2022-03-29 11:23:30 +00:00
Rui Ueyama
408e2bfee8 Improve tests 2022-03-29 06:47:17 +00:00
Rui Ueyama
05f4a43c8f [ELF][ARM64] Allow TLSGD relocations in statically-linked executables 2022-03-27 07:48:42 +00:00
Rui Ueyama
8770bd775b [ELF][ARM] Fix test 2022-03-23 14:54:26 +00:00
Rui Ueyama
89d43f2673 Fix test
So that this test works on ARM32.
2022-03-23 14:41:40 +00:00
Rui Ueyama
d5cf590498 [ELF][ARM32] Support basic relocations
With this change, mold can link dynamically-linked "Hello world"
program for ARM32.
2022-03-22 12:52:07 +00:00
Rui Ueyama
18656091f6 Rename a test 2022-03-22 12:24:10 +00:00
Rui Ueyama
ead32811b3 Fix a test for AArch64
Currently, we do not support relaxations of TLS GD/LD relocations
for ARM64. This is in practice not a problem because TLSDESC is used
on ARM64 by default.

However, there's one situation in which not supporting TLS GD/LD
relaxation becomes an issue; static linking. If an executable is
statically-linked, relaxation is mandatory because we can't generate
dynamic relocations for GD/LD relocations.

In this patch, we simply report an error if an object file compiled
with TLS GD/LD is used for creating a statically-linked executable.

This commit fixes all tests on ARM64.
2022-03-21 02:49:50 +00:00
Dawid Jurczak
0c88d323c8 [ELF][RISC-V] Do not hardcode GCC version in tests
Signed-off-by: Dawid Jurczak <dawid_jurek@vp.pl>
2022-03-19 17:22:03 +01:00
Rui Ueyama
619ff869e4 [ELF][i386] Implement GD → LE and LD → LD relaxations
This commit implements TLS relocation relaxations.

Fixes https://github.com/rui314/mold/issues/388
2022-03-10 15:18:43 +09:00
Rui Ueyama
c98d276916 [ELF][ARM64] Fix a test
For some reason, readelf doesn't like a build-id if it's very short.
2022-03-09 17:00:53 +09:00
Rui Ueyama
98edd441ce [ELF] Do not print out an error of ldd --version
Some `ldd` impls don't support the --version option. We do not
want to show the error message but instead just skip the test
entirely.

https://github.com/rui314/mold/pull/385
2022-03-09 14:53:10 +09:00
Rui Ueyama
37f6ef2081 [ELF] Fix a crash bug for -noinhibit-exec
After a certain point, it is not expected that there's a remaining
undefined symbol. -noinhibit-exec did not respect that invariant,
which caused a crash bug on ARM64.

This change forces all symbols to be resolved if --noinhibit-exec
is given.

Fixes https://github.com/rui314/mold/issues/383
2022-03-09 11:38:46 +09:00
Rui Ueyama
41cf6d7814 [ELF][ARM64] Avoid -mcmodel=large and -no-PIC
Such combination is not supported by GCC.

Fixes https://github.com/rui314/mold/issues/384
2022-03-09 11:36:44 +09:00
Rui Ueyama
bb5a596bc5 Set LC_ALL=C to get consistent output from shell comands
We unset `LANG`, but it looks like `LC_ALL` takes precedence over `LANG`,
so we should set `LC_ALL` to `C`.

Reported at https://github.com/rui314/mold/pull/385
2022-03-09 09:03:22 +09:00
Christoph Erhardt
a20e3b8004 Increase required glibc version for -static-pie tests
mold 1.1.1 generates `-static-pie` code that works with glibc 2.35 but
segfaults with glibc 2.34 or older.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-03-08 10:13:49 +01:00
Rui Ueyama
3999aa8b18 [ELF] Fix -static-pie
Previously, mold did not work with the -static-pie compiler flag.
In order to support static PIE, we need the following:

1. Create a .dynamic section even if it is not a dynamic executable, and
2. do not define __rel_iplt_start/end symbols.

The second part is required to workaround a glibc issue.

Even with these changes, mold-generated executable doesn't work with
old glibc versions. But I think it's OK because -static-pie is relatively
new option and you need a newer toolchain anyway.
2022-03-06 17:14:13 +09:00
Rui Ueyama
b4d9db9db8 [ELF] Do not emit DT_RELCOUNT
It looks like the glibc loader does not use this field in the dynamic
section. GNU ld, gold and LLVM lld don't create this. So I think we
can just follow suit.
2022-03-06 14:43:24 +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
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
99a0aaf133 [ELF] Add a test for -init 2022-03-02 10:35:32 +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
8f21cc386e [ELF] Merge --shuffle-sections-seed into --shuffle-sections 2022-02-27 14:25:10 +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
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
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
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
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
a054bcd4ff [ELF] Add the --dependency-file=FILE option 2022-02-22 13:18:04 +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
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
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
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
68a35bfa03 Fix CI 2022-02-13 16:52:54 +09:00
Rui Ueyama
70ec56f8bb [ELF][LTO] Export symbols from DSOs correctly
With this change, mold can now build Clang with LTO and all Clang tests pass.
2022-02-13 15:34:37 +09:00
Rui Ueyama
1663bcf932 Rename test files 2022-02-13 12:22:18 +09:00
Rui Ueyama
1dcd20b401 Fix CI 2022-02-12 15:39:28 +09:00
Rui Ueyama
7e91897154 [ELF] Add the --shuffle-sections option
If the --shuffle-sections is given, mold now randomize the output by
shuffling input sections randomly. This feature is compatible with lld's
--shuffle-sections=SEED option introduced in
https://reviews.llvm.org/D74791.

This feature is useful when you want to equalize the conditions of
benchmarks. That is, some particular memory layout can produce a very
good benchmark number due to hardware-level cache hit rate or something
like that. Therefore, even if you get a good benchmark number after
changing code, there's a chance that that's caused by the layout change
and not by the new code itself. With --shuffle-sections, you can isolate
that.

The other use case I can think of is to enhance security. If you build
your program as a position-independent executable, the kernel
automatically enables ASLR (Address Space Layout Randomization), but ASLR
only shift the entire program image in memory by some random offset;
Relative offsets between sections remain the same. If you compile programs
from source, by using --shuffle-sections, you can make the offsets
unpredictable to attackers.
2022-02-12 15:32:37 +09:00
Rui Ueyama
46995bcfc3 [ELF] Support LTO plugin API
The LTO plugin API support is still in progress, but with this change,
mold can link itself with `-flto` with both GCC and Clang.

Since mold now supports LTO natively, I removed the fallback mechanism
to ld.bfd or ld.lld that I implemented in
a5029d19a8.

Fixes https://github.com/rui314/mold/issues/181
2022-02-11 21:09:28 +09:00
Rui Ueyama
ebc2bfafdd [ELF] Fix ICF crash bug
`-icf=all` couldn't handle very small programs that has no sections
to process in the main loop. This commit fixes that crash bug.

Fixes https://github.com/rui314/mold/issues/332
2022-02-08 16:34:25 +09:00
Rui Ueyama
73159e241d [ELF] Add .got.plt to PT_GNU_RELRO if -z now
If external symbols are resolved eagerly on process startup, .got.plt
can be read-only and therefore can be in the PT_GNU_RELRO segment.
2022-02-07 17:12:53 +09:00
Rui Ueyama
e65c5d2a1c [ELF] Handle ABI incompatibility between -fgnu-unique and -fno-gnu-unique
GCC creates symbols in comdat groups as STB_GNU_UNIQUE instead of STB_WEAK
if it was configured to do so at build time or the -fgnu-unique option was
given. If mold is given two object files with and without STB_GNU_UNIQUE,
it could end up selecting a sybmol that is in a de-duplicated comdat group.

This is arguably just an ABI incompatibility. Two comdat groups must
contain the same contents if their identifiers are the same. But we
can't handle it as an error because it is not uncommon to link object
files compiled using Clang (or GCC without -fgnu-unique) to static
libraries built with GCC that produces STB_GNU_UNIQUE symbols.

This patch gives the same priority to STB_GNU_UNIQUE as STB_WEAK so that
mold won't select symbols in discarded comdat groups.

Frankly, the situation around STB_GNU_UNIQUE is a mess. That GNU extension
shouldn't have been added to the GNU toolchain in the first place.
It looks like GCC shipped with Linux distros are nowadays do not produce
STB_GNU_UNIQUE symbols by default, but we still need to handle them.

Fixes https://github.com/rui314/mold/issues/324
2022-02-07 07:53:58 +09:00
Rui Ueyama
27c50e8158 [ELF] Report an error for an unresolved hidden undef correctly
Previously, if a protected/hidden undef symbol is resolved to a DSO
symbol,  mold didn't report a symbol undefined error.

Fixes https://github.com/rui314/mold/issues/329
2022-02-06 13:49:17 +09:00
Rui Ueyama
6ffcae4286 [ELF] Add --warn-textrel 2022-02-05 13:26:38 +09:00
Rui Ueyama
03e0cef726 [ELF] Add --warn-shared-textrel 2022-02-05 12:15:30 +09:00
Rui Ueyama
a4d9bc7550 Fix CI 2022-02-05 12:15:17 +09:00
Rui Ueyama
f24b997501 [ELF} Add --warn-once 2022-02-05 11:39:59 +09:00
Rui Ueyama
26fe71d64c [ELF] Support --emit-relocs
This commit adds the `--emit-relocs` option to mold. If the flag is
given, mold copies relocation sections from input files to an output
file. This option is used by some binary post-processing tools such
as Facebook's Bolt.

It looks like the relocations emitted by `--emit-relocs` are correct,
but I didn't do extensive testing. If you find any problem, please
let me know.

Fixes https://github.com/rui314/mold/issues/177
2022-02-04 18:42:08 +09:00
Rui Ueyama
354d1b7d2f [ELF] Fix CI 2022-02-04 18:34:57 +09:00
Rui Ueyama
1550b5afff [ELF] Copy symbols from DSOs to an output file
Previously, mold didn't copy symbols from .so input files to the
output .symtab.
2022-02-04 18:03:17 +09:00
Rui Ueyama
e4c03c238e [ELF] Write section symbols to .symtab 2022-02-04 17:05:06 +09:00
Rui Ueyama
d0ab7d9e17 Refactor 2022-02-04 16:14:00 +09:00
Rui Ueyama
e98aab7ea9 [ELF] Reimplement --repro
`--repro` is a hidden command flag for debugging.

Previously, if the flag was given, mold would create a `.repro`
section in an output file with all input files as its contents.
The flaw of the design is that when mold fails to create an output
file, no .repro section would be created.

So I changed the behavior in this commit. Now, the tar file is
created as an independent file.
2022-02-01 13:47:44 +09:00
Rui Ueyama
00203dbc7c [ELF][RISC-V] Implement TLS_GOT_HI20 and TLS_GD_HI20
Now all test passed on my SiFive Unmatched RISC-V PC.
2022-01-29 22:35:04 +09:00
Rui Ueyama
e061e3ca70 [ELF][RISC-V] Add a test for dynamically-linked executable 2022-01-29 14:24:46 +09:00
Rui Ueyama
e76f7c0d47 Add an initial support of RISC-V
With this patch, mold can now produce a statically-link "Hello wrold"
program for RISC-V.
2022-01-28 18:08:42 +09:00
Rui Ueyama
b4fa51e981 Fix tests for musl libc 2022-01-24 10:29:31 +09:00
Rui Ueyama
dc7432a6dd Avoid GNU extensions in tests 2022-01-24 10:21:08 +09:00
Rui Ueyama
0a0f9b3ad5 [ELF] Protect the last page of a RELRO segment
PT_GNU_RELRO works on page granularity. We always align the begining
of a RELRO segment to a page boundary, but the end was not. Since the
runtime conservatively align _down_ it to a page boundary, the last
page weren't be marked as read-only.

This patch makes the size of a RELRO always a multiple of the page size.
2022-01-24 09:40:21 +09:00
Rui Ueyama
f8e7b157c7 Fix a test 2022-01-23 11:41:19 +09:00
Rui Ueyama
5cf2328a8b [ELF] Support negation and range in glob pattern 2022-01-22 11:01:55 +09:00
Rui Ueyama
e9a5d1cee3 [ELF] Handle glob patterns directly instead of converting them to regex
Converting a glob pattern to a regex is fragile, and std::regex is slow.
So we should handle glob patterns ourselves.
2022-01-21 23:32:27 +09:00
Rui Ueyama
4ee3062054 [ELF] Fix version pattern matching 2022-01-21 21:27:49 +09:00
Rui Ueyama
d0c1c4db19 [ELF] Use Aho-Corasick algo to handle version script patternsC
To process version scriots, we have to match glob patterns against
symbol strings. Sometimes, we have hundreds or thousands of glob
patterns and have to match them against millions of mangled long
C++ symbol names. This step can be very slow.

In this patch, I implemented the Aho-Corasick algorithm to match glob
patterns to symbol strings as quickly as possible. For the details
of the algorithm, see https://en.wikipedia.org/wiki/Glob_(programming).

This patch improves mold's performance for programs that uses large
version scripts. For example, linking libQt6Gui.so.6.3.0 reduced from
1.10s to 0.05s with this patch.

This patch also changes how symbol versions are applied if two or more
version patterns match to a single symbol string. Previously, the last
one in a script file took precedence. Now, the first one takes
precedence. I believe the new behavior is compatible with GNU ld.

Fixes https://github.com/rui314/mold/issues/156
Fixed https://github.com/rui314/mold/issues/287
2022-01-21 20:30:05 +09:00
Rui Ueyama
8b1905453d [ELF] Do not use BND prefix
BND prefix is defined by Intel MPX extension which is now deprecated by Intel.
2022-01-20 13:39:31 +09:00
Rui Ueyama
1b01448f01
Merge pull request #286 from tklauser/test-exception-aarch64
[ELF] Pass -fno-PIC along with -mcmodel=large on aarch64
2022-01-20 09:46:42 +09:00
Rui Ueyama
809652d740 [ELF] Handle glob patterns other than * for local: in version scripts
Previously, we didn't handle version scripts like this correctly:

  ver {
    global: *;
    local: foo*;
  }

We didn't handle `local:` part correctly except for `*`.

Fixes https://github.com/rui314/mold/issues/277
2022-01-20 08:51:04 +09:00
Tobias Klauser
fbd4e559e6
[ELF] Pass -fno-PIC along with -mcmodel=large on aarch64
The -mcmodel=large option is incompatible with -fPIC on aarch64, see
https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-mcmodel_003dlarge

This makes test/elf/exception.sh pass on linux/arm64.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2022-01-19 21:36:53 +01:00
Rui Ueyama
9453488424 [ELF] Fix test for ARM64 2022-01-18 13:28:57 +09:00
Rui Ueyama
3411511a8b [ELF] Ignore i386-specific linkonce symbols
This is a follow-up to the previously commit patch
0c19046721. We needed to ignore symbols
whose address is in a discarded .gnu.linkonce sections.

Fixes https://github.com/rui314/mold/issues/270
2022-01-15 14:28:34 +09:00
Rui Ueyama
bd6afa1b23 [ELF] Add -pack-dyn-relocs=relr
.relr.dyn is a new section that has been implemented in other linkers
recently. That section contains only the RELATIVE-type dynamic
relocations (i.e. base relocations). Compared to the regular
.rela.dyn, a .relr.dyn's size is typically less than 1/10 because the
section is compressed.

Since PIEs (position-independent executables) tend to contain lots of
RELATIVE-type relocations and PIEs are now the default on many Linux
distributions for security reasons, .relr.dyn is more effective than
it was. It can reduce binary size by a few percent or more.

Note that the runtime support is catching up, so binaries built with
`-pack-dyn-relocs=relr` may not work on your system unless you are
running a very recent version of Linux.
2022-01-14 20:54:37 +09:00
Rui Ueyama
a9cca00933 [ELF] Fix symbol visibility
This commit fixes a regression introduced in
ce5749ce2f.
2022-01-13 22:59:04 +09:00
Rui Ueyama
011a7d35d6 [ELF] Add a test
https://github.com/rui314/mold/issues/244
2022-01-13 13:06:37 +09:00
Rui Ueyama
9d27ee0839 [ELF] Skip incompatible files specified by linker script GROUP command
Fixes https://github.com/rui314/mold/issues/260
2022-01-13 10:42:13 +09:00
Rui Ueyama
74e0e4f6d0 [ELF] Resurrect a file that was deleted by accident 2022-01-12 22:40:04 +09:00
Rui Ueyama
60c134893c [ELF] Create DT_DEBUG dynamic entry only for executables
gdb uses this field only if it is an executable. Having an extra
dynamic entry is usually harmless, but unfortunately, RPM's `rpmdeps`
tool uses the presence of this entry to distinguish executables from
shared object files. So, it is better not to create a DT_DEBUG entry
for shared object files.

Fixes https://github.com/rui314/mold/issues/254
2022-01-12 22:13:13 +09:00
Rui Ueyama
d2c57e99ca Refactor 2022-01-12 20:35:41 +09:00
Rui Ueyama
bb18b29e13 [ELF] Fix --trace-symbol for DSO
Previously, --trace-symbol didn't work for shared object files.
2022-01-12 17:30:51 +09:00
Rui Ueyama
cea6a569af [ELF] Remove "GNU gold" from the --version string
That substring was introduced in de7ba9014f
to appease Gentoo's dev-libs/jansson-2.13.1-r1 package. But I think I
shouldn't done that from the beginning to avoid the sitaution of the
"User-Agent" string of the web browser, which everybody claims they
are Mozilla, AppleWebKit, Chrome and Safari simultaneously.
2022-01-12 16:38:04 +09:00
Rui Ueyama
9ca6a9dc5e [ELF] Add -z ibt
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:38:38 +09:00
Rui Ueyama
31a43a7ba6 [ELF] Add -z cet-report
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:34:32 +09:00
Rui Ueyama
e29bd8f42b [ELF] Add -z shstk
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:34:24 +09:00
Rui Ueyama
013e6ea06e [ELF] Fix .got.plt for IBTPLT
Previously, the `bnd jmp` instruction in a IBTPLT entry jumps to the
middle of an instruction due to an incorrect GOTPLT value. That happened
to work because a value that was there after the jump can be interpreted
as an `add` instruction and the control falled through the next `pushq`.
2022-01-09 10:14:35 +09:00
Rui Ueyama
27d836180f [ELF] Make an undefined symbol to be resolved to a common symbol in an archive
Previously, mold ignored common symbols in an archive when resolving
symbols. As a result, even if an undefined symbol could be resolved
using a common symbol in an archive, mold would end up with an undefined
symbol error.

This commit changes the behavior. Now, an undefined symbol is resolved
to a common symbol in an archive if exists.

Fixes https://github.com/rui314/mold/issues/256
2022-01-08 20:44:22 +09:00
Rui Ueyama
0370e7f1b3 [ELF] Emit a compact PLT section if -z now is passed
Each entry in the regular PLT section takes 16 bytes.
This new PLT section reduces it to 8 bytes.
2022-01-08 14:57:50 +09:00
Rui Ueyama
fbfa01dcd1 [ELF] Implement -z ibtplt
https://github.com/rui314/mold/issues/229
2022-01-08 14:09:12 +09:00
Rui Ueyama
badc733488 [ELF] Report an error if an incompatible object file is given
Previously, mold would crash if an incompatible object file was given.
https://github.com/rui314/mold/issues/260
2022-01-07 23:04:08 +09:00
Rui Ueyama
3dd76cd953 Attempt to fix buildbots 2022-01-07 18:18:00 +09:00
Rui Ueyama
d86a774ebf Fix Mach-O tests 2022-01-07 18:12:40 +09:00
Rui Ueyama
e7decd2c77 Use relative paths in tests 2022-01-07 18:08:06 +09:00
Rui Ueyama
4324cb2998 Use cc and c++ instead of clang, gcc, clang++ or g++ in tests 2022-01-07 18:02:35 +09:00
Rui Ueyama
4348417dd8 [ELF] Do not convert .ctors/.dtors to .init_array/.fini_array
The .ctors section contains a list of pointers that have to be run
before `main`. It usually contains pointers to global constructors.
The .dtors are for global destructors.

The .init_array and .fini_array serve the same purpose as .ctors and
.dtors. The former sections are newer than the latter sections, and
most programs have already migrated to .{init,fini}_array.

.ctors/.dtors are very similar to .{init,fini}_array, but the order
in which pointers are executed is different. .ctors/.dtors are executed
from the end to the beginning, while .{init,fini}_array are executed
from the beginning to the end.

Previously, we converted .ctors/.dtors sections into .{init,fini}_array
sections. In order to do that, we not only merge .ctors/.dtors to
.{init,fini}_array but also reverse their section contents, so that
the initialization order remains the same.

However, there was a bug in that logic. We forgot to reverse the
locations of dynamic relocations for the converted sections.
So, .ctors/.dtors sections converted to .{init,fini}_array were executed
in a wrong order.

We have two choices to "fix" the issue: (1) reverse not only section
contents but also dynamic relocations, or (2) stop converting .ctors/.dtors.
In this patch, I chose (2).

Since LLVM lld doesn't convert .ctors/.dtors, it shouldn't cause an
issue for most programs.
2022-01-07 17:47:14 +09:00
Rui Ueyama
0e17dbeda8 [ELF] Make --defsym'ed symbols absolute
If a symbol is defined in the form of --defsym=foo=0x<hexvalue>,
it should be defined as an absolute symbol with the given value.
2022-01-07 16:28:14 +09:00
Rui Ueyama
3b33420fe5 [ELF] Support R_X86_64_PLTOFF64 2022-01-07 14:44:17 +09:00
Rui Ueyama
e075e622ba Fix buildbots 2022-01-07 13:24:42 +09:00
Rui Ueyama
092286fc1d [ELF] Fix tests so that they work if CC is clang 2022-01-07 12:45:20 +09:00
Rui Ueyama
2f86fef3a0 [ELF] Fix assertion failure
This patch fixes a regression introduced in
43fa021d48.

Fixes https://github.com/rui314/mold/issues/259
2022-01-06 22:01:56 +09:00
Rui Ueyama
daa88f2f06 [ELF] Handle '[]' in glob patterns
Previously, mold crashes due to an invalid regex pattern exception
when `[...]` is given as a version script pattern.

Fixes https://github.com/rui314/mold/issues/258
2022-01-06 20:45:46 +09:00
Rui Ueyama
404fa1288b [ELF] Add a test
https://github.com/rui314/mold/issues/258
2022-01-06 18:27:31 +09:00
Rui Ueyama
43fa021d48 [ELF] Do not place non-exported symbols into .gnu.hash
Previously, mold put all global symbols into .gnu.hash. Although I
believe it was not an error, it bloated the size of .gnu.hash because
.gnu.hash needs only exported symbols.

https://github.com/rui314/mold/issues/255
2022-01-06 17:47:19 +09:00
Christoph Erhardt
df865725ed Fix test failures on aarch64
Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-01-05 12:26:56 +01:00
Rui Ueyama
be49d673a5 [ELF] Deduce emulation from input files if -m is not given 2022-01-05 19:55:32 +09:00
Rui Ueyama
285c9e2c32 [ELF] Attempt to fix buildbots 2022-01-04 20:59:33 +09:00
Rui Ueyama
a5029d19a8 [ELF] Automatically fall back to ld.bfd or ld.lld if LTO is in use
This is very hacky but highly practical, so I couldn't resist to not
implement this. We should support LTO natively in the future. In the
meantime, this feature should work as a poor-man's replacement.

Fixes https://github.com/rui314/mold/issues/242
2022-01-04 20:50:16 +09:00
Rui Ueyama
9894b3173b [ELF] Add --default-symver
Fixes https://github.com/rui314/mold/issues/228
2022-01-03 20:29:33 +09:00
Rui Ueyama
4b2f10d009 [ELF] Improve test 2022-01-03 20:15:04 +09:00
Rui Ueyama
5618038463 [ELF] Show a better error message for the empty input file
Fixes https://github.com/rui314/mold/issues/227
2022-01-02 19:33:07 +09:00
Rui Ueyama
0a8231b59d [ELF] Support R_X86_64_GOTOFF64
Fixes https://github.com/rui314/mold/issues/224
2022-01-02 11:14:33 +09:00
Rui Ueyama
1f7727975c [ELF] Improve test 2022-01-02 11:13:12 +09:00
Rui Ueyama
b5172caeb5 Improve test
I think `-m32` means ARM32 if this test runs on ARM64.
2021-12-31 00:13:07 +09:00
Tobias Klauser
66c9659f5a
Fix skip check in i386-mergable-strings.sh
Check for the ability to build 32-bit binaries like in the other i386
test cases.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2021-12-30 15:58:11 +01:00
Rui Ueyama
d49c50ddaf [ELF] Add --defsym
Fixes https://github.com/rui314/mold/issues/208
2021-12-30 14:48:39 +09:00
Rui Ueyama
44ae92c4ed Remove redundant "../../" from test script paths
So that it's easier to see the output of the test script running
with `bash -x` . This change was made using sed.
2021-12-30 11:11:27 +09:00
Christoph Erhardt
0dcc910223 Add lots of quotes to shell scripts
This makes it possible to build and test mold in a path that contains
whitespace characters - with the notable exception of the tests where
`LD_PRELOAD` is used. That's because `LD_PRELOAD` unconditionally treats
any whitespace as separator, regardless of quoting.

The following ShellCheck warnings are eliminated by this commit:
* SC2046: Quote this to prevent word splitting.
* SC2086: Double quote to prevent globbing and word splitting.

Signed-off-by: Christoph Erhardt <github@sicherha.de>
2021-12-29 22:18:19 +01:00
Rui Ueyama
f3766cda81 [ELF] Add -z {max,common}-page-size
Fixes https://github.com/rui314/mold/issues/203
2021-12-29 17:14:08 +09:00
Rui Ueyama
b151de6684 [ELF] Fix .tbss layout
Fixes https://github.com/rui314/mold/issues/126
2021-12-29 15:50:56 +09:00
Rui Ueyama
cfed33ee42 Revert "[ELF] Fix a layout issue for thread-local bss sections"
This reverts commit 5c35d2a41f
because it causes a regression https://github.com/rui314/mold/issues/201.

I'll fix https://github.com/rui314/mold/issues/126 in another patch.
2021-12-28 18:36:31 +09:00
Rui Ueyama
1228bf3865
Merge pull request #200 from jmglogow/fix_version_globbing
[ELF] Fix '?' for globbing + version scripts
2021-12-26 23:29:02 +09:00
Jan-Marek Glogowski
31b0248b05 [ELF] Fix '?' for globbing + version scripts
For globbing, '?' matches a single character, so must be replaced
with '.'. As a result, don't skip the later regex matching for
version scripts, if the pattern contains either '*' or '?'.

Signed-off-by: Jan-Marek Glogowski <glogow@fbihome.de>
2021-12-26 15:02:43 +01:00
Rui Ueyama
d1161137d9 [ELF] Fix Initial-Exec TLS variables
Previously, GOTTPOFF relocations against Initial-Exec TLS variables
got wrong value.

Fixes https://github.com/rui314/mold/issues/197
2021-12-26 20:51:37 +09:00
Rui Ueyama
5c35d2a41f [ELF] Fix a layout issue for thread-local bss sections
Previously, if there are more than one TLS BSS section (e.g. .tbss and
.tcommon), mold layout them in such a way that they overlap in memory.
That caused a mysterious program crash to the programs compiled with DMD,
a D compiler.

Fixes https://github.com/rui314/mold/issues/126
2021-12-25 20:32:33 +09:00
Rui Ueyama
6e290aab3e [ELF] Implement --color-diagnostics 2021-12-25 16:55:51 +09:00
Rui Ueyama
7aa5c393e4 [ELF] Support extern "C++" in dynamic lists
Fixes https://github.com/rui314/mold/issues/149
2021-12-25 15:10:24 +09:00
Rui Ueyama
7b3c640472 Fix --dynamic-list
Previously, symbols were not exported from an executable even if
they are specified so by a dynamic list.
2021-12-25 13:38:24 +09:00
Rui Ueyama
04ccd4dbdd [ELF] Export undef symbols if both -z defs and -warn-undefined-symbols are given
When we are creating a DSO, unresolved undefined symbols are promoted to
dynamic symbols by default so that they will get another chance to be
resolved at runtime.

You can suppress this behavior by passing `-z defs`. If that option is
given, remaining undefs are reported as errors instead of being silently
promoted.

It looks like `-warn-undefined-symbols` negates the effect of `-z defs`.
So, if both options are given, remaining undefs are promoted to dynamic
symbols. mold previously silently make such symbols absolute symbols with
value 0.

Fixed https://github.com/rui314/mold/issues/152
2021-12-24 21:13:15 +09:00
Rui Ueyama
5601cf4236 [ELF] Add -z separate-code, -z noseparate-code and -z separate-lodable-segments
Fixes https://github.com/rui314/mold/issues/172
2021-12-24 20:28:45 +09:00
Rui Ueyama
088912e2fc [ELF] Create less number of PT_NOTE segments 2021-12-24 20:15:56 +09:00
Rui Ueyama
29d956a7b0 [ELF] Fix handling of DSO symbols with default version
Fixes https://github.com/rui314/mold/issues/150
2021-12-24 16:10:01 +09:00
Rui Ueyama
1ba6cc9188 [ELF] Handle relocation referring 0th symbol correctly 2021-12-24 16:09:57 +09:00
Rui Ueyama
135f17c5aa [ELF] Handle --sysroot
Attempt to fix https://github.com/rui314/mold/issues/150
2021-12-23 21:23:00 +09:00
Rui Ueyama
8c86c28496 Add -z nodefaultlib
Fixes https://github.com/rui314/mold/issues/184
2021-12-23 15:01:57 +09:00
Rui Ueyama
76407a6646 Do not create a PT_NOTE segment for non-alloc .note sections
Fixes https://github.com/rui314/mold/issues/185
2021-12-23 14:04:08 +09:00
Rui Ueyama
4d5e4730a2 Fix typo 2021-12-22 20:44:29 +09:00
Rui Ueyama
24bf92c27c [ELF] Fix a crash bug 2021-12-22 20:41:11 +09:00
Rui Ueyama
8bc57363c8 [ELF] Issue a warning instead of error for an unknown -z option
Fixes https://github.com/rui314/mold/issues/180
2021-12-22 20:08:14 +09:00
Rui Ueyama
74fdf90d70 Fix a test for clang and clang-as
clang-as does not support --keep-locals, so use its synonym -L
which is supported both by GNU as and clang-as.

Fixes https://github.com/rui314/mold/issues/173
2021-12-22 11:42:29 +09:00
Rui Ueyama
f9ff04866e [ELF] Add --threads=N option
Fixes https://github.com/rui314/mold/issues/168
2021-12-20 16:29:22 +09:00
Rui Ueyama
1d6d0e2fe3
Merge pull request #158 from sylvestre/second-fix
test/pie.sh: extend the check to other output
2021-12-17 20:16:07 +09:00
Rui Ueyama
4f37c3d024 Fix tests in non-English environment
These test files are not only invoked by make by also directly by hand.
Unsetting `LANG` on each file so that they don't fail in a non-English
environment.

This change is mechanically created by the following command:

  sed -i '1 a export LANG=' test/*/*.sh
2021-12-17 20:06:50 +09:00
Sylvestre Ledru
fbee0ec588 test/pie.sh: extend the check to other output
On debian unstable, the output doesn't contain 'Shared object file'
Parsing a different output

Signed-off-by: Sylvestre Ledru <sylvestre@debian.org>
2021-12-17 10:02:21 +01:00
Rui Ueyama
36633895e5 [ELF] Fix undefined symbol versions
Previously, if the following conditions are met:

 - we are creating a shared object file,
 - there's an undefined symbol in an input object file that are
   to be promoted to a dynamic symbol, and
 - a version script defining a default version is given,

then the symbol gets the default version. But that's a wrong behavior
because version scripts should not affect symbols that are not defined
in an output file.

This change fixes the issue by not setting version to such symbol.

Fixes https://github.com/rui314/mold/issues/151
2021-12-17 17:07:36 +09:00
Rui Ueyama
27f72ac320 Fix tests 2021-12-15 20:42:27 +09:00
Rui Ueyama
c9a2fd1d7d Fix a test 2021-12-15 10:36:51 +09:00
Rui Ueyama
10a318d5ba [ELF] Fix -exclude_libs option 2021-12-10 20:45:57 +09:00
Rui Ueyama
22116629f1 [ELF] Add --start-lib and --end-lib
Fixes https://github.com/rui314/mold/issues/133
2021-12-06 20:09:46 +09:00
Rui Ueyama
0328f37b2a [Mach-O] Add -bundle 2021-12-05 16:52:35 +09:00
Rui Ueyama
c5f5e6153f [Mach-O] Add -headerpad_max_install_names 2021-12-05 15:53:41 +09:00
Rui Ueyama
6fae1d8555 [Mach-O] Report an error on -search_dylibs_first 2021-12-05 15:40:36 +09:00
Rui Ueyama
a3e0e9f197 wip 2021-12-04 16:41:51 +09:00
Rui Ueyama
6a3ddf1ab4 wip 2021-12-04 16:31:15 +09:00
Rui Ueyama
a415accbc3 wip 2021-12-04 12:55:21 +09:00
Rui Ueyama
d6a9005b14 wip 2021-12-04 12:10:18 +09:00
Rui Ueyama
bf7366438b wip 2021-12-03 23:06:07 +09:00
Rui Ueyama
4bd92c0d46 [Mach-O] Do not emit PAGEZERO segment for dylibs 2021-12-01 15:14:38 +09:00
Rui Ueyama
8ceaf53728 [Mach-O] Add -needed_framework 2021-12-01 13:45:25 +09:00
Rui Ueyama
ee05f3a65f [Mach-O] Add -dead_strip_dylibs 2021-11-30 19:20:29 +09:00
Rui Ueyama
7156dd265f [Mach-O] Add -needed-l 2021-11-30 18:05:28 +09:00
Rui Ueyama
9e7e41cfac [Mach-O] Fix -L 2021-11-30 15:23:00 +09:00
Rui Ueyama
4998a130e5 [Mach-O] Support -dylib 2021-11-29 18:12:48 +09:00
Rui Ueyama
e99727f87f [Mach-O] Add -Z 2021-11-28 10:05:23 +09:00
Rui Ueyama
1219d3250c [ELF] Fix a test for AArch64 2021-11-27 21:03:47 +09:00
Rui Ueyama
8ae43210e7 [Mach-O] Add -framework and -F 2021-11-27 20:03:12 +09:00
Rui Ueyama
72cea9a0bf [Mach-O] Improve -filelist 2021-11-21 22:18:55 +09:00
Rui Ueyama
5804d6b4b2 [Mach-O] Add -ObjC 2021-11-21 20:26:41 +09:00
Rui Ueyama
efb6e6729a [Mach-O] Handle response files correctly 2021-11-21 14:53:50 +09:00
Rui Ueyama
6087782660 [Mach-O] Add -filepath 2021-11-20 19:26:29 +09:00
Rui Ueyama
cee6412e3d [Mach-O] Add -rpath 2021-11-20 19:01:18 +09:00
Rui Ueyama
39676ef7a9 Define BINDIR, LIBDIR and MANDIR
So that it is easy to specify alternative install target paths.
2021-11-19 17:18:15 +09:00
Rui Ueyama
8b41bb923a [ELF] Fix canonical PLT entry
Previously, an executable linked by mold could fall into an infinite
loop between .plt.got and .got entries. This commit fixes the issue
by creating .plt entries instead of .plt.got.

Fixes https://github.com/rui314/mold/issues/129
2021-11-18 20:53:15 +09:00
Rui Ueyama
18cfe1f4ca [Mach-O] Add -pagezero_size option 2021-11-14 14:23:44 +09:00
Rui Ueyama
06bc828a9b [Mach-O] wip 2021-11-14 13:30:55 +09:00
Rui Ueyama
433666a470 [Mach-O] Implement -dead_strip 2021-11-13 15:21:52 +09:00
Rui Ueyama
fcd592e53d [Mach-O] Add -e option 2021-11-12 19:10:00 +09:00
Rui Ueyama
4a1ec53c24 [Mach-O] wip 2021-11-12 19:10:00 +09:00
Rui Ueyama
87c4c1df15 [Mach-O] Relax GOT/TLV load instructions 2021-11-09 19:09:07 +09:00
Rui Ueyama
92f56aa73f [Mach-O] Support thread-local variables 2021-11-09 16:23:43 +09:00
Rui Ueyama
3a24532d2a [Mach-O] wip 2021-11-08 20:36:27 +09:00
Rui Ueyama
72587e643f [Mach-O] wip 2021-11-07 23:57:43 +09:00
Rui Ueyama
ea6d310576 [Mach-O] wip 2021-11-07 20:01:36 +09:00
Rui Ueyama
6d709de396 [Mach-O] wip 2021-11-06 16:22:55 +09:00
Rui Ueyama
f232e857f0 [Mach-O] wip 2021-11-06 10:53:44 +09:00
Rui Ueyama
cbc990d459 [Mach-O] wip 2021-11-05 18:40:59 +09:00
Rui Ueyama
247655179f [Mach-O] Add -map option 2021-11-05 14:23:28 +09:00
Rui Ueyama
bfa50ac015 [Mach-O] Handle Universal binaries 2021-11-03 16:38:29 +09:00
Rui Ueyama
00e45a4ba1 [Mach-O] wip 2021-11-02 15:08:02 +09:00
Rui Ueyama
4de3bb9a78 [Mach-O] wip 2021-11-02 10:07:49 +09:00
Rui Ueyama
bfec2435da [Mach-O] wip 2021-11-01 21:06:33 +09:00
Rui Ueyama
3c297c2254 [Mach-O] wip 2021-11-01 15:13:28 +09:00
Rui Ueyama
0a6d3986cd [Mach-O] Align common symbols properly 2021-10-29 21:34:27 +09:00
Rui Ueyama
4afc68d74d [Mach-O] Handle common symbols 2021-10-29 16:19:05 +09:00
Rui Ueyama
c227286dd5 [Mach-O] Handle .bss 2021-10-29 13:28:52 +09:00
Rui Ueyama
e1ab83155a [Mach-O] wip 2021-10-28 18:51:54 +09:00
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
Rui Ueyama
035aa73c43 Fix CI 2021-07-28 23:40:29 +09:00
Rui Ueyama
d25c2553ad Intercept all invocations of ld, ld.gold or ld.lld
Previously, only /usr/bin/ld, /usr/bin/ld.lld and /usr/bin/ld.gold
were intercepted. Now, mold ignores the directory part when comparing
a command name with `ld`, `ld.lld` or `ld.gold`.

This change is made because ld is often installed other than /usr/bin.

Fixes https://github.com/rui314/mold/issues/101
2021-07-28 22:42:35 +09:00
Rui Ueyama
965da0af4a Use hyphen instead of underscore in filename
Test files are following this convention already, but source files weren't.
2021-07-26 21:34:04 +09:00
Rui Ueyama
73d1dcac5d Add a test 2021-07-26 21:32:34 +09:00
Rui Ueyama
79787360c6 Fix test
This piece of code is intended to be position-independent,
but it actually directly called printf without PLT.

Fixes https://github.com/rui314/mold/issues/100
2021-07-26 20:17:28 +09:00
Rui Ueyama
6fa659c41b Remove an argument from test scripts 2021-07-21 16:27:29 +09:00
Rui Ueyama
271c9151f4 Disable tests for mold-wrapper if ASAN is enabled
ASAN doens't work well if other libraries are LD_PRELOAD'ed.
2021-07-20 13:32:02 +09:00
Rui Ueyama
59822bf07e Attempt to fix CI 2021-07-20 00:43:14 +09:00
Rui Ueyama
fe26dad744 Fix cmake build
You can now build mold with the following commands:

  $ mkdir -p out/debug
  $ cd out/debug
  $ cmake -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug ../..
  $ ninja

To run tests, use the following commands:

  $ cd out/debug
  $ ctest -j$(nproc)
2021-07-20 00:33:28 +09:00
Rui Ueyama
04e9aa4ebc Skip i386/aarch64 tests if cross compilers are not available
https://github.com/rui314/mold/issues/89
2021-07-17 01:23:58 +09:00
Rui Ueyama
280892f061 Fix tests for musl 2021-07-16 15:30:54 +09:00
Rui Ueyama
d79cdb8371 Fix a broken test
Fixes https://github.com/rui314/mold/issues/89
2021-07-13 19:24:26 +09:00
Artur Sinila
5fb7ecbd03
Fix test/run.sh for cases when /usr/bin/ld -> /usr/bin/mold
Signed-off-by: Artur Sinila <freesoftware@logarithmus.dev>
2021-07-12 05:27:21 +03:00
Rui Ueyama
3204bb01d9 Fix function pointer equality
Previously, a GOT relocation (e.g. R_X86_64_REX_GOTPCRELX) and a
R_X86_64_64 relocation referring the same imported symbols were
resolved to different addresses. Here is why:

 - When we saw a R_X86_64_64 relocation against an imported symbol,
   we created a PLT and resolve the relocation there.

 - GOT relocation is resolved to a GOT entry, which has a true
   address of an imported function at runtime, which is different
   from PLT entries that redirect calls to the real function.

With this patch, we no longer create a PLT entry for R_X86_64_64.
Instead, we emit a dynamic relocation so that it is always resolved
to a real function address.

Fixes GNU MP's `make check` failure, which was reported at
https://github.com/rui314/mold/issues/81
2021-07-10 17:54:57 +09:00
Rui Ueyama
faac31f217 Support VERSION linker script command
The grammar of the command is this

  VERSION { <version-script> }

where <version-script> is a version script you can specify with
the --version-script option.
2021-07-09 23:34:44 +09:00
Rui Ueyama
63b6d30876 Compress .repro section contents
Previously, .repro contains an uncompressed tar file containing all
input files. This patch compresses the contents in the gzip format.
2021-07-09 00:47:15 +09:00
Rui Ueyama
50b7497e19 Align section header to a E::wordsize boundary
Fixes https://github.com/rui314/mold/issues/80
2021-07-08 15:58:55 +09:00
Rui Ueyama
84d9e4d5ac Fix regexp 2021-07-07 23:12:24 +09:00
Rui Ueyama
72cc07fb42
Merge pull request #83 from nehaljwani/dynsym-IFUNC
Do not replace IFUNC with FUNC in .dynsym
2021-07-07 21:48:15 +09:00
Rui Ueyama
6ae115ac69 Support R_AARCH_ABS{32,64} relocations 2021-07-07 21:06:18 +09:00
Nehal J Wani
1aec54efdb
Do not replace IFUNC with FUNC in .dynsym
This is a partial revert of dd04357

Signed-off-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
2021-07-07 07:59:51 -04:00
Rui Ueyama
e3dccd0157 Add a test 2021-07-07 20:38:48 +09:00
Rui Ueyama
6d6df45a23 Fix definition of __GLOBAL_OFFSET_TABLE__ for AArch64 2021-07-07 12:51:23 +09:00
Rui Ueyama
d4a67f6f38 Disable an AArch64 test 2021-07-06 23:06:02 +09:00
Rui Ueyama
41497d7990 Support AARCH64 relocations
With this change, mold can now create a "Hello world" program
for the AArch64 target.
2021-07-06 22:24:48 +09:00
Nehal J Wani
be6d443bc8
[tests] Improve test for -spare-dynamic-tags
The default size and offsets of the .dynamic section are not necessarily
same with different builds of clang. For example, some builds can make
clang pass --hash-style=gnu to the linker and some --hash-style=both.

This change updates the test to compute the difference in size of the
.dynamic section before and after using the flag -spare-dynamic-tags,
making it independent of the compiler build.

Signed-off-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
2021-07-03 22:35:42 -04:00
Rui Ueyama
accf96877f Add a stub for AArch64
It can generate an executable, but generated executable won't run
correctly because we don't process relocations at all yet.
2021-07-03 21:39:44 +09:00
Rui Ueyama
d502b6ec60 Initial AARCH64 support 2021-07-03 20:48:38 +09:00
Rui Ueyama
3c992c02ea
Merge pull request #72 from nehaljwani/fix-pie-test
[tests] Fix pie test when cc isn't built with --enable-default-pie
2021-07-03 14:30:05 +09:00
Rui Ueyama
2abca8b5c1 Fix tests for non-Ubuntu-20 systems
Fixes https://github.com/rui314/mold/issues/67
2021-07-03 14:26:38 +09:00
Nehal J Wani
3208ceaac6
[tests] Fix pie test when cc isn't built with --enable-default-pie
mold: /__w/mold/mold/test/tmp/pie/a.o:(.text): R_X86_64_32 relocation
       against symbol `.rodata' can not be used; recompile with -fPIE
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Signed-off-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
2021-07-03 01:05:28 -04:00
Rui Ueyama
475fad3a78 Allow sysroot to be a relative path
Chromium cannot be built with out this patch.
2021-07-03 12:02:32 +09:00
Rui Ueyama
0fd62ce693 Fix sysroot handling
Fix https://github.com/rui314/mold/issues/59
2021-07-01 17:40:45 +09:00
Rui Ueyama
9abfeee0e3 Split a function and add tests 2021-07-01 10:00:08 +09:00
Rui Ueyama
6432114e2a Fix handling of --sysroot
Fixes https://github.com/rui314/mold/issues/59
2021-06-30 22:15:19 +09:00
Rui Ueyama
989f69fdc5 Do not apply version scripts to DSO symbols
This is needed by Gentoo's dev-perl/Image-Imlib2-2.30.0-r1 package
because this fixes a mis-link issue of libbsd.
2021-06-27 21:44:42 +09:00
Rui Ueyama
5761dbc399 Fix a broken test 2021-06-27 17:03:59 +09:00
Rui Ueyama
570a3556c5 Fix exported weak symbol
This is needed by Gentoo's app-admin/filebeat-7.9.3 package.
2021-06-27 12:37:14 +09:00
Rui Ueyama
4436e4a57d Improve error message for an attempt of LTO 2021-06-26 15:05:05 +09:00
Rui Ueyama
bd1b044afc Accept extern "C" in version script
This is needed by Gentoo's dev-libs/opencl-clang-10.0.0.1-r1 package.
2021-06-25 16:48:40 +09:00
Rui Ueyama
2e5088a001 Fix common symbol
This is needed by Gentoo's sci-electronics/voacapl-0.7.6 package.
2021-06-25 15:42:16 +09:00
Rui Ueyama
bd8059a366 Fix an issue that a .dynsym for PLT refers itself 2021-06-25 13:33:14 +09:00
Rui Ueyama
5046fae0cf Do not directly call imported functions
This is needed by Gentoo's sci-libs/lapack-3.9.0-r1 package.
2021-06-25 01:05:57 +09:00
Rui Ueyama
d9ecc2e3e6 Promote weak undefined symbols to weak dynamic symbols
Previously, if a weak undefined symbol cannot be resolved within
an output of the linker, mold turned it into an absolute symbol
with value 0. However, other linkers export such symbols as a
weak dynamic symbol, so that the symbol gets another chance to be
resolved at runtime.

This patch implements the behavior.

This is needed by Gentoo's dev-libs/nsync-1.20.1 package.
2021-06-25 00:44:35 +09:00
Rui Ueyama
fd1855a67b Make --version to exit immediately
This is needed by Gentoo's dev-lang/spidermonkey-78.10.1 package,
as its configure script assumes that the linker exit normally
even if extra options are given after `--version`.
2021-06-24 16:45:04 +09:00
Rui Ueyama
81dbbdda62 DSOs referenced by used DSOs are considered used
This is needed by Gentoo's sys-cluster/ampi-0_pre20140616 package.
2021-06-24 15:54:25 +09:00
Rui Ueyama
de668b125a Refactor 2021-06-24 15:50:08 +09:00
Rui Ueyama
dd04357363 Do not set STT_GNU_IFUNC to symbols .dynsym
We should not set STT_GNU_IFUNC to symbols in .dynsym because
from the other ELF module's point of view, it doens't matter
whether a symbol is IFUNC or not.

This is needed by Gentoo's sci-mathematics/nauty-2.6.7 package.
2021-06-21 10:32:30 +09:00
Rui Ueyama
f127281d05 Allow empty input files
mmap(2) fails if you pass 0 as an argument for `length` parameter,
so this case has to be handled as a special case.

This is needed by Gentoo's media-plugins/calf-0.90.3-r1 package.
2021-06-21 09:33:35 +09:00