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

195 Commits

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