1
1
mirror of https://github.com/rui314/mold.git synced 2024-10-06 01:28:12 +03:00
Commit Graph

3344 Commits

Author SHA1 Message Date
Rui Ueyama
9b710cf832 Refactor 2022-01-08 15:11:25 +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
18367e69a8 Refactor 2022-01-08 13:24:29 +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
54e71f43d4 [ELF] Use .got.plt instead of .got to compute GOT-relative reloc values 2022-01-07 22:27:48 +09:00
Rui Ueyama
329e382c6d Simplify 2022-01-07 20:56:36 +09:00
Rui Ueyama
644fdc8a2f Simplify 2022-01-07 20:42:25 +09:00
Rui Ueyama
c9352710f7 Fix clang buildbot 2022-01-07 18:53:01 +09:00
Rui Ueyama
f4a37b2e95 Do not use clang/clang++ as the default compilers
mold does not have to be built with clang/clang++, so don't use
these compiler frontends.

mold also doesn't have be built with g++ (GNU C++ compiler).
We use `c++` command instead.

Fixes https://github.com/rui314/mold/issues/261
2022-01-07 18:45:05 +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
9004c514da Suppress -Wformat-overflow GCC warning 2022-01-07 10:57:54 +09:00
Rui Ueyama
a27c113d35 Attempt to fix i386 host build
This change cherrypicks
542a27fa1c

https://github.com/rui314/mold/issues/240
2022-01-07 10:09:34 +09:00
Rui Ueyama
1acabd65e3 Add a comment 2022-01-06 23:42:15 +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
79e397ea03 Add a missing #include 2022-01-06 20:54:23 +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
c33df4771f Revert "[ELF] Keep SHF_MERGE and SHF_STRINGS bits"
This reverts commit 4d78510cb0.

If the SHF_MERGE bit is set, sh_entsize must have the size of the unit
for that section. In the previous commit, we changed the behavior of
mold so that it sets SHF_MERGE bits in the output file. However, we
didn't set sh_entsize. So, the resulting section is technically invalid.

We merge sections with different sh_entsize into a single output
section, so there's no easy way to "keep" the original value.

In this commit, we simply revert the previous change so that mold won't
set SHF_MERGE in the output file.

https://github.com/rui314/mold/issues/155
2022-01-06 18:19:06 +09:00
Rui Ueyama
8f23d17ece Fix macOS build 2022-01-06 17:53:40 +09:00
Rui Ueyama
09b9d0af1d [ELF] Remove redundant code 2022-01-06 17:48:46 +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
Rui Ueyama
907f713e51 [ELF] Remove NEEDS_DYNSYM flag from symbol
I wanted to make sure that a symbol X is in .dynsym if and only if
(X.is_imported || X.is_exported).
2022-01-06 15:27:39 +09:00
Rui Ueyama
276b9d005d [ELF] Add ARM64 to --help message
Fixes https://github.com/rui314/mold/issues/251
2022-01-05 21:41:53 +09:00
Rui Ueyama
fe14a08761 Make make to take EXTRA_CFLAGS and EXTRA_CXXFLAGS 2022-01-05 21:36:48 +09:00
Rui Ueyama
3865a10600
Merge pull request #252 from sicherha/fix-tests-on-aarch64
Fix test failures on aarch64
2022-01-05 21:07:26 +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
31a6a1164e
Merge pull request #248 from sina-ht/use-pkg-config
Use pkg-config to know where openssl header files reside
2022-01-05 18:40:55 +09:00
Hiroshi Takekawa
e8bdbaab22 Use pkg-config to know where openssl header files reside
Let Makefile know how to locate openssl header files in a directory other than
the default directories by using pkg-config. If you don't have pkg-config, then
$(shell) returns empty.

Signed-off-by: Hiroshi Takekawa <sian.ht@gmail.com>
2022-01-05 18:25:17 +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
0565a6a6ff
Merge pull request #241 from sina-ht/use-pkg-config
Use pkg-config to know where libcrypto resides
2022-01-04 15:05:34 +09:00
Hiroshi Takekawa
6987f06151 Use pkg-config to know where libcrypto resides
Let Makefile know how to link libcrypto in a directory other than the default
directories by using pkg-config. If you don't have pkg-config, then $(shell)
returns empty.

Signed-off-by: Hiroshi Takekawa <sian.ht@gmail.com>
2022-01-04 14:16:09 +09:00
Rui Ueyama
a2839f60dd [ELF] Improve an error message
Fixes https://github.com/rui314/mold/issues/233
2022-01-04 13:49:48 +09:00
Rui Ueyama
1bc7c332ab Do not link against librt on Android
Fixes https://github.com/rui314/mold/issues/231
2022-01-04 13:44:55 +09:00
Rui Ueyama
8ffe4cd472 [ELF] Ignore dead FDE entries
Looks like some CUDA object files contains FDEs whose relocation has
r_sym with value 0. Such FDEs are dead and should be ignored.

Unfortunately, there's no easy way to produce an object file containing
such relocation, so this change lacks a testcase.

Fixes https://github.com/rui314/mold/issues/235
2022-01-04 13:32:26 +09:00
Rui Ueyama
70704c7c09 Disable -Wc++11-narrowing on Android
Fixes https://github.com/rui314/mold/issues/231
2022-01-03 20:59:19 +09:00
Rui Ueyama
5029a6d044 Simplify 2022-01-03 20:56:59 +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
8590fd9947 Better way to suppress -Wint-to-pointer-cast 2022-01-03 18:15:51 +09:00