1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-15 14:36:25 +03:00
Commit Graph

348 Commits

Author SHA1 Message Date
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