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

936 Commits

Author SHA1 Message Date
Rui Ueyama
d4ccc10ed4
Merge pull request #571 from clemenswasser/cmake
CMake Port
2022-08-07 10:37:44 +08:00
Rui Ueyama
da2f3fe12c Revert "Re-submit b23c47ae6dbe285e02627803eac0604cfaaa1e78"
This reverts commit a70b1eb58b because
it's too risky to include it into 1.4.0.
2022-08-04 20:46:09 +08:00
Rui Ueyama
10c211f1ab [ELF] Fix a regression for libprotobuf
The `extern "C"` directive in a version script should match a non-C++
mangled name for the sake of compatibility with other linkers. It
caused a regression for libprotobuf.
2022-08-04 18:15:05 +08:00
Rui Ueyama
d3cf7cd239 Fix CI 2022-08-04 14:57:10 +08:00
Rui Ueyama
d9db6bcf49 [ELF] Add an initial 32-bit RISC-V support 2022-08-02 13:12:05 +08:00
Rui Ueyama
a70b1eb58b Re-submit b23c47ae6d
With a fix for a bug in my previous test script.
2022-08-01 09:38:12 +08:00
Rui Ueyama
bb999c5e93 Revert "[ELF] Garbage-collect C identifier sections"
This reverts commit b23c47ae6d because
it broke CI.
2022-07-31 20:56:37 +08:00
Rui Ueyama
b23c47ae6d [ELF] Garbage-collect C identifier sections
If a section name is valid as a C identifier (i.e. it doesn't start
with '.' and doesn't contain any punctuators), the linker automatically
creates new symbols by prepending `__start_` and `__stop_` to the
section name.

Previously, we conservatively keep such C identifier sections during
garbage collection. However, since `__start_` and `__stop_` symbols
are hidden symbols, if we do not have `__start_foo` or `__stop_foo`,
we can safely discard section `foo`.
2022-07-31 20:26:31 +08:00
Tatsuyuki Ishi
536e0e7dca [elf] Align .symtab's ELF attributes with .dynsym's.
Notably, we previously wrote symbols that have been demoted into STB_LOCAL
as STB_GLOBAL. Fix this by using a logic shared with dynsym to determine
the output attributes.

Also reorder the symbols since the LOCAL ones need to come first.

Found in Mesa test suite.

Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
2022-07-30 22:30:57 +09:00
Rui Ueyama
4a73ca28ca Fix CI 2022-07-29 21:37:23 +08:00
Rui Ueyama
b2b16e66b4 [Mach-O] Add -no_function_starts 2022-07-29 10:48:12 +08:00
Rui Ueyama
8143fe2fcc [Mach-O] Fix a relaxation bug 2022-07-29 09:13:18 +08:00
Rui Ueyama
12f941c58d [Mach-O] Improve LOH_ARM64_ADRP_LDR_GOT_LDR 2022-07-28 17:15:37 +08:00
Rui Ueyama
0e1b60dd6e [Mach-O] Fix mis-optimization bug for LOH_ARM64_ADRP_LDR_GOT_LDR 2022-07-28 15:18:14 +08:00
Rui Ueyama
54399fe567 [Mach-O] Support LOH_ARM64_ADRP_LDR_GOT_LDR 2022-07-27 14:45:13 +08:00
Tatsuyuki Ishi
1c8778b6e3 [elf] Add test for globs in --dynamic-list, --export-dynamic-symbol-list.
Glob and function names are inherited from version-script14.sh.

Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi
58f393ac8b [elf] Add test for --export-dynamic-symbol[-list].
Piggybacked on existing tests for --dynamic-list.

Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
2022-07-23 19:21:19 +09:00
Clemens Wasser
0a73cf1bfc Port CTest
Signed-off-by: Clemens Wasser <clemens.wasser@gmail.com>
2022-07-18 18:58:17 +02:00
Rui Ueyama
d7b42f29f2 [Mach-O] Define ${section,segment}${start,end}$ symbols. 2022-07-18 19:39:11 +08:00
Rui Ueyama
3ba30f7f09 Create a test workdir for each machine/test pair 2022-07-18 15:25:56 +08:00
Rui Ueyama
29af9b5177 Unmask amd64 2022-07-16 19:51:46 +08:00
Rui Ueyama
ed7e7c7ae0 Merge makefiles for tests into the main makefile 2022-07-12 21:03:54 +08:00
Rui Ueyama
764d7575f7 [ELF] Define __dso_handle
`cxa_finalize` takes `__dso_handle` to uniquify identify an ELF module
in memory. Its actual location doesn't matter but needs to be different
for each ELF module.

Fixes https://github.com/rui314/mold/issues/507
2022-07-11 18:01:23 +08:00
Rui Ueyama
e3e371dcd3 [ELF][x86-64] Always create PLT entries starting with ENDBR64
This change removes the compact PLT and non-IBT PLT and replaces
them with IBT PLT. The compact PLT wasn't compatible with `-z ibtplt`.

Fixes https://github.com/rui314/mold/issues/581
2022-07-11 13:59:32 +08:00
Rui Ueyama
55379e1142 Fix tests for i686
Fixes https://github.com/rui314/mold/issues/579
2022-07-10 12:40:25 +08:00
Peter Wang
31d2a902e5 Fix run.sh failure on musl
The command "mold -run foo.ld" can fail when foo.ld is an empty file.
The musl execvp() call fails with "Exec format error" when the script
to be executed is empty. The fix is to create foo.ld with a valid
Unix shebang.

Signed-off-by: Peter Wang <novalazy@gmail.com>
2022-07-09 17:37:57 +10:00
Rui Ueyama
593f2cfdbc Do not run LTO tests if LTO is not supported
Fixes https://github.com/rui314/mold/issues/577
2022-07-09 15:30:38 +08:00
Rui Ueyama
12c9c53b90 Add a test 2022-07-08 22:51:05 +08:00
Rui Ueyama
5071c42e72 Add a test for Rust demangler
https://github.com/rui314/mold/issues/371
2022-07-05 15:09:44 +08:00
Rui Ueyama
2bfc724e42 [Mach-O] Add -dependency_info 2022-07-05 10:52:15 +08:00
Rui Ueyama
8d29501887 [Mach-O] Ignore OS name part of targets in TBD files 2022-07-02 13:57:12 +08:00
Rui Ueyama
ea308bc77b [Mach-O] Add -add_ast_path 2022-07-02 13:52:19 +08:00
Rui Ueyama
ad427f8629 [ELF] Skip one more test if musl
https://github.com/rui314/mold/issues/565
2022-07-01 19:05:32 +08:00
Rui Ueyama
23b90dfc38 [ELF] Detect musl libc in a more reliably way
Fixes https://github.com/rui314/mold/issues/565
2022-07-01 18:00:19 +08:00
Rui Ueyama
14392e7720 Fix a test for musl 2022-07-01 09:51:32 +08:00
Rui Ueyama
3b75398786 [ELF] Support .preinit_array
It looks like AddressSanitizer depends on this feature.

Fixes https://github.com/rui314/mold/issues/562
2022-06-30 16:29:50 +08:00
Rui Ueyama
ded9cd4ffa Add -application_extension 2022-06-28 19:53:28 +08:00
Rui Ueyama
b0c6aa9a0f [Mach-O] Add -add_empty_section 2022-06-28 15:20:47 +08:00
Rui Ueyama
b81f3c22be Add a test 2022-06-28 11:35:36 +08:00
Rui Ueyama
26d45ed4c1 Fix a test
We passed two input files (/dev/null and "-") to the command which
is plainly wrong.

Fixes https://github.com/rui314/mold/issues/559
2022-06-28 10:42:26 +08:00
Rui Ueyama
b5d7335e35 Revert "Implement `--(no-)allow-shlib-undefined."
This reverts the following commits because it causes a regression.

 - 62be1fcdb0
 - a7b8da9345
 - 21a2d6bb6c

Fixes https://github.com/rui314/mold/issues/559
2022-06-27 20:53:26 +08:00
Rui Ueyama
bdee09ad02 [Mach-O] Handle LC_REEXPORT_DYLIB 2022-06-27 20:49:02 +08:00
Rui Ueyama
335698851b [Mach-O] Add -reexport-l 2022-06-26 18:27:36 +08:00
Rui Ueyama
7b5b1a340b [Mach-O] Handle weak dynamic symbols 2022-06-26 17:21:26 +08:00
Rui Ueyama
3e6f6fe8b5
Merge pull request #557 from wangp/grep-P
Don't use grep -P in tests
2022-06-26 16:42:20 +08:00
Rui Ueyama
1524746a80 [Mach-O] Fix weak undef symbols 2022-06-26 15:57:15 +08:00
Peter Wang
2963ab672c Don't use grep -P in tests
The version of grep being used may not support the -P flag
(Perl-compatible regular expressions).
2022-06-26 15:51:25 +10:00
Rui Ueyama
fe72463f55 [Mach-O] Set mold's version to LC_BUILD_VERSION
I chose 0x6d6f6c64 as a magic number without coordinating with other
tools or Apple, but it should be fine.
2022-06-26 13:14:07 +08:00
Rui Ueyama
831f872886 [Mach-O] Do not emit corrupted unwind table 2022-06-25 19:22:38 +08:00
Rui Ueyama
d9a28221dd [Mach-O] Sort the symtab and fill LC_DYSYMTAB fields 2022-06-24 16:00:50 +08:00
Rui Ueyama
a7b8da9345 Simplify 2022-06-24 10:44:35 +08:00
Robert Bartlensky
21a2d6bb6c
Implement `--(no-)allow-shlib-undefined.
This also fixes the `note-property` test which was hanging on my
machine. Turns out `$CC` was stuck waiting to read from `stdin`,
and as such I decided to write something into it.

Signed-off-by: Robert Bartlensky <bartlensky.robert@gmail.com>
2022-06-23 23:46:15 +01:00
Rui Ueyama
9a3188bcf5 [Mach-O] Compute LC_UUID using the entire code signature section
We used to compute a file UUID using only the hashes in the code
signature section. So we computes the same UUID even if two files
are differnet only in some field of the code signature section.
2022-06-22 20:29:03 +08:00
Rui Ueyama
c214bfc96b [Mach-O] Remove -dump
I added this option for debugging. Since mold is now mature enough,
we no longer need this option.
2022-06-16 20:53:27 +08:00
Rui Ueyama
7b8d7a6417 [Mach-O] Add -order_file 2022-06-16 16:52:25 +08:00
Rui Ueyama
285ea7ba26 [Mach-O] Add -u 2022-06-16 14:24:59 +08:00
Rui Ueyama
b05a671789 [Mach-O] Do not split into subsections if MH_SUBSECTIONS_VIA_SYMBOLS is not set 2022-06-15 17:45:25 +08:00
Rui Ueyama
dcbc85b412 Attempt to fix CI 2022-06-15 11:52:45 +08:00
Luboš Luňák
87163c667a fix tests to work with new undefined references reporting
Signed-off-by: Luboš Luňák <l.lunak@centrum.cz>
2022-06-09 13:32:23 +02:00
Rui Ueyama
6f04ef9cf2 [Mach-O] Handle $ld$install_name$ symbols 2022-06-06 20:24:52 +08:00
Rui Ueyama
880204ebe5 [Mach-O] Handle $ld$hide$ symbols 2022-06-06 20:20:16 +08:00
Rui Ueyama
e11e68d508 [Mach-O] Handle $ld$add$ symbols 2022-06-06 19:49:58 +08:00
Rui Ueyama
d5b5b9afe1 [Mach-O] Handle $ld$previous$ symbols 2022-06-06 17:23:10 +08:00
Rui Ueyama
b364b3f453 [Mach-O] Add -weak-l<LIB> 2022-06-06 14:02:28 +08:00
Rui Ueyama
ea31281149 Add tests 2022-06-06 12:03:01 +08:00
Rui Ueyama
eee315ea52 [Mach-O] Allow glob patterns in -exported_symbols_list and -unexported_symbols_list 2022-06-05 17:47:42 +08:00
Rui Ueyama
1b52d228d4 Add a test 2022-06-04 20:17:16 +08:00
Rui Ueyama
0de862191b [Mach-O] Add --unexported_symbol and --unexported_symbols_list 2022-06-03 19:48:57 +08:00
Rui Ueyama
7478c27ce8 [Mach-O] Add --exported_symbol and --exported_symbols_list 2022-06-03 18:55:00 +08:00
Rui Ueyama
7097946eee [Mach-O] Merge symbol visibility 2022-06-03 15:03:29 +08:00
Rui Ueyama
67ec8f3376 [Mach-O] Handle symbols with N_WEAK_DEF|N_WEAK_REF as private extern 2022-06-03 13:23:45 +08:00
Rui Ueyama
0723476fa5 Add a test 2022-06-03 11:50:05 +08:00
Rui Ueyama
f730dde6e7 [Mach-O] Add -object_path_lto 2022-06-02 16:29:50 +08:00
Rui Ueyama
66c1433be1 [Mach-O] Merge string constants in __TEXT,__cstring 2022-06-02 13:39:51 +08:00
Rui Ueyama
826bb56d59 [Mach-O] Fix thread-local variables 2022-05-31 16:54:05 +08:00
Rui Ueyama
3f12a843a6 Revert "[Mach-O] Merge string constants in __TEXT,__cstring"
This reverts commit e770df42d9 because
it broke many clang tests.
2022-05-30 17:13:09 +08:00
Rui Ueyama
4826d393d1 [Mach-O] Set a LC_UUID even if -no_adhoc_codesign is given 2022-05-30 12:46:00 +08:00
Rui Ueyama
b82aa99bca [Mach-O] Do not create LC_CODE_SIGNATURE if -no_adhoc_codesign is given 2022-05-30 12:26:05 +08:00
Rui Ueyama
e9f6715c6e [ELF] Support --package-metadata
Fixes https://github.com/rui314/mold/issues/505
2022-05-26 21:04:36 +08:00
Rui Ueyama
e770df42d9 [Mach-O] Merge string constants in __TEXT,__cstring 2022-05-26 15:30:28 +08:00
Rui Ueyama
bd292ef782 [Mach-O] Support LC_LINKER_OPTION
Fixes https://github.com/rui314/mold/issues/523
2022-05-25 13:50:05 +08:00
Rui Ueyama
e293d56cc1 [Mach-O] Add -sectcreate 2022-05-21 15:56:36 +08:00
Rui Ueyama
33e00f2fb5 [Mach-O] Make output reproducible 2022-05-21 12:54:54 +08:00
Rui Ueyama
ef053c41fe Revert "[CI] Always upload test results as artifacts"
This reverts commit 03cda81af6.
2022-05-20 17:07:05 +08:00
Rui Ueyama
03cda81af6 [CI] Always upload test results as artifacts 2022-05-20 16:28:08 +08:00
Rui Ueyama
51f99db269 Attempt to fix CI 2022-05-20 14:52:03 +08:00
Rui Ueyama
94c100c211 Attempt to fix CI 2022-05-20 14:28:56 +08:00
Rui Ueyama
eb90d1bcbb [Mach-O] Fix x86-64 CI 2022-05-20 14:18:31 +08:00
Rui Ueyama
7156ef7daa Attempt to fix CI 2022-05-20 13:36:12 +08:00
Rui Ueyama
6b77349b4a [Mach-O] Fix thread-local variables
With this change, mold can now link mold itself on macOS!
2022-05-20 13:12:58 +08:00
Rui Ueyama
2c5582b9e9 [Mach-O] Fix references to dyld_stub_binder 2022-05-19 18:14:34 +08:00
Rui Ueyama
c654d42c14
Merge pull request #520 from tapthaker/macho-tbd-files
[Mach-O] Adds support for objc and weak symbols in TBD files
2022-05-18 12:03:11 +08:00
Rui Ueyama
4b945c839f Extend a test 2022-05-18 11:41:37 +08:00
Tapan Thaker
6d67614004 [Mach-O] Adds support for objc and weak symbols in TBD files
Signed-off-by: Tapan Thaker <tapan.d.thaker@gmail.com>
2022-05-17 20:16:27 -07:00
Rui Ueyama
1052b93c4f [Mach-O] Deduplicate comdat symbols 2022-05-17 20:08:29 +08:00
Rui Ueyama
4d380ec645 [Mach-O] Add tests 2022-05-16 19:34:24 +08:00
Rui Ueyama
deebb497d3 [Mach-O][LTO] Add a basic support of LTO
mold/macOS can now link a "hello world" program with LTO.
2022-05-16 15:07:09 +08:00
Rui Ueyama
3cf8fc4b35 [Mach-O] Add -no_uuid and -uuid_random and -final_output 2022-05-14 15:51:42 +08:00
Rui Ueyama
64b8168916 Fix tests for OpenSUSE Leap
Fixes https://github.com/rui314/mold/issues/515
2022-05-14 13:47:35 +08:00
Rui Ueyama
b1c0a13386 [ELF] Add --rosegment and --no-rosegment
Fixes https://github.com/rui314/mold/issues/514
2022-05-13 19:41:32 +08:00
Rui Ueyama
1a8ebf89db Fix CI 2022-05-13 14:07:19 +08:00
Rui Ueyama
f086145fc4 Fix CI 2022-05-13 13:16:51 +08:00
Rui Ueyama
8cbcd9777f [ELF] Support SHF_GNU_RETAIN
https://github.com/rui314/mold/issues/511
2022-05-13 13:09:16 +08:00
Rui Ueyama
2e47fe5815 Do not create a .gdb_index section if there's no debug info section 2022-05-13 11:45:32 +08:00
Rui Ueyama
7f3a05ad0f [Mach-O] Add -hidden-l 2022-05-12 20:15:26 +08:00
Rui Ueyama
a5c7c98af8 [Mach-O] Add -stack_size 2022-05-12 19:07:04 +08:00
Rui Ueyama
00148f4d5e [Mach-O] Add -install_name 2022-05-12 18:55:56 +08:00
Rui Ueyama
4bc287ff48 [Mach-O] Add -search_paths_first and -search_dylibs_first 2022-05-12 16:49:10 +08:00
Rui Ueyama
5e389f99d4 Use mold to build mold 2022-05-11 17:34:36 +08:00
Rui Ueyama
c054e3d197 Fix CI 2022-05-11 17:23:29 +08:00
Rui Ueyama
05acf9da2c Add test-asan, test-tsan and test-ubsan targets 2022-05-11 15:51:44 +08:00
Rui Ueyama
3c284f09ab [ELF] Skip a failing test on RV64
https://github.com/rui314/mold/issues/503
2022-05-10 22:20:28 +08:00
Rui Ueyama
f59bd5ea23 [ELF] Fix an unsafe memory access
Fixes https://github.com/rui314/mold/issues/506
2022-05-10 21:42:12 +08:00
Rui Ueyama
b6e9c6da66 [Mach-O] Add -U 2022-05-10 20:02:48 +08:00
Rui Ueyama
f8296ba0fc Disable a few tests for RV64
Fixes https://github.com/rui314/mold/issues/503
2022-05-10 19:23:33 +08:00
Rui Ueyama
c1ba1707fc [Mach-O] Add -force_load 2022-05-10 14:17:41 +08:00
Rui Ueyama
6b5c47882a [ELF] Fix mold-wrapper's execle
Fixes https://github.com/rui314/mold/issues/501
2022-05-10 12:43:17 +08:00
Rui Ueyama
144c156dc6 Fix a test
Fixes https://github.com/rui314/mold/issues/502
2022-05-09 19:34:00 +08:00
Rui Ueyama
edc1c68efb Relax a test
Fixes https://github.com/rui314/mold/issues/500
2022-05-09 19:20:41 +08:00
Rui Ueyama
72ef8fc73a [Mach-O] Support -all_load 2022-05-09 16:48:12 +08:00
Rui Ueyama
537a062d25 Remove unnecessary shell variable 2022-05-09 13:56:48 +08:00
Rui Ueyama
5d7064c01e [Mach-O] Remove absolute addresses from tests 2022-05-09 11:57:42 +08:00
Rui Ueyama
f822898c2f [Mach-O] Remove a hook to run executables under Qemu
Qemu does not suport user process emulation for macOS, so we'll
never use it.
2022-05-09 11:44:38 +08:00
Rui Ueyama
b2cf48de33 [Mach-O] Fix test for GitHub Actions 2022-05-09 11:43:09 +08:00
Rui Ueyama
e4d6c8c382 [Mach-O] Fix test runner
If one of the test scripts fail, the entire test should fail.
2022-05-09 11:35:18 +08:00
Rui Ueyama
727d34d727 Do not show "skipped" if valgrind is not available 2022-05-05 18:59:48 +08:00
Martin Liska
6910f8e590 tests: print skipped if valgrind is missing
Signed-off-by: Martin Liska <mliska@suse.cz>
2022-05-05 12:42:17 +02:00
Rui Ueyama
ca25f1fd20 [ELF] Redefine --color-diagnostics as an alias for --color-diagnostics=auto
It was accidentally mapped to --color-diagnostics=always, but it
was a bug. For the sake of compatibility with other tools such as
clang or lld, it should be defined as an alias for `auto`.
2022-05-05 18:01:04 +08:00
Rui Ueyama
3694ffe61d Fix execl-family wrappers
Previously, we didn't terminate an argv with a null pointer.

Fixes https://github.com/rui314/mold/issues/495
2022-05-05 17:37:57 +08:00
Rui Ueyama
232dafa8d0 [ELF] Do not allow -- for a single-letter option 2022-05-03 19:35:48 +08:00
Rui Ueyama
dd8e15952f [ELF] Fix --omagic 2022-05-02 15:52:29 +08:00
Christoph Erhardt
b5a1d3ace2 Skip -static-pie tests on i686, not just on i386
Signed-off-by: Christoph Erhardt <github@sicherha.de>
2022-05-01 00:31:27 +02:00
Rui Ueyama
eae062f815 [ELF] Fix ICF so that all tests pass with ICF 2022-04-30 19:37:29 +08:00
Rui Ueyama
d714819759 Rename a test 2022-04-29 20:06:48 +08:00
Rui Ueyama
62b3a3dca9 Fix tests for ASAN and TSAN 2022-04-29 19:53:48 +08:00
Rui Ueyama
ee95df673b [ELF] Remove a test for a feature that is deprecated 2022-04-27 22:30:00 +08:00
Rui Ueyama
3455e8bd82 Include popular large libs to the base Docker image
So that each test doesn't have to compile them individually.
2022-04-27 16:36:45 +08:00
Rui Ueyama
8298c0ad16 [ELF] Fix symbol resolution for versioned symbols
My last commit d391fd9a59 changes how we
resolve versioned symbols, but that affected too many programs.
In particular it broke GCC build, so reverted in
f378fdc495.

This commit is an attempt to fix the same issue with a minimal change.

Fixes https://github.com/rui314/mold/issues/475
2022-04-27 13:13:14 +08:00
Rui Ueyama
f378fdc495 Revert "[ELF] Fix regression in symbol name resolution"
This reverts commit d391fd9a59 because
it broke GCC builds.
2022-04-27 12:57:22 +08:00
Rui Ueyama
1b5735543f
Merge pull request #470 from llunak/gdb-index-address-size
Gdb index address size
2022-04-26 18:48:56 +08:00
Rui Ueyama
d391fd9a59 [ELF] Fix regression in symbol name resolution
This fix is needed to build Gentoo's net-fs/fuse package.
2022-04-26 15:26:52 +08:00
Luboš Luňák
face536c39 launch gdb with -nx (ignore all .gdbinit)
Otherwise the test may fail simply because .gdbinit setup does
something strange (I happen to have 'set auto-solib-add off', which
disables loading debug info by default).
2022-04-26 09:12:29 +02:00
Rui Ueyama
fc9f9e570e Simplify 2022-04-25 14:26:22 +08:00
Rui Ueyama
ea600a752b Do not run ./dist.sh on every invocation 2022-04-24 16:36:17 +08:00
Rui Ueyama
fa6d0c33d7 [ELF] Hide an unversioned symbol if a versioned one exists
An object file can contain both unversioned and versioned symbols for
the same symbol. For example, the following piece of code will be
compiled to an object file that will contain `foo` and `foo@VERSION`.

  void foo() {}
  asm(".symver foo, foo@VERSION");

If this object file is given to GNU BFD linker, it exports only
`foo@VERSION` and suppresses `foo`. I believe the rationale for doing
that is, if a symbol is versioned, all of its versions must be
versioned. In other words, `foo@VER1`, `foo@VER2` and `foo@@VER3` can
co-exist, but `foo@VER1` and `foo` can't. In the latter case, if you
want to provide `foo` as the default version, it should be exported
not as `foo` but as `foo@@SOME_VERSION` (with double at-signs).

Fixes https://github.com/rui314/mold/issues/426
2022-04-24 12:09:50 +08:00
Rui Ueyama
6baef60a48 [ELF] Fix .debug_rnglists reader
Fixes https://github.com/rui314/mold/issues/453
2022-04-22 15:00:02 +08:00
Rui Ueyama
8c5e4df741 [ELF] Ignore comdat groups GCC emits for .debug_macro
GCC creates a .debug_macro section if -g3 is given. That section
is in a comdat group, but the section is directly referred by another
section, which is a violation of the ELF spec.

If a section is deduplicated, we handle any references to that section
as if they had value 0. But that causes a mysterious gdb slowdown.
So we can't set 0 for a dead .debug_macro section.

In this commit, we simply stop deduplicating .debug_macro sections.
This will bloat up debug info, but that's better than producing an
effectively non-debuggable binary.

Fixes https://github.com/rui314/mold/issues/357
Fixes https://github.com/rui314/mold/issues/438
2022-04-22 12:24:22 +08:00
Rui Ueyama
ad3487376c Imrpove tests 2022-04-22 11:10:45 +08:00
Rui Ueyama
3b3333a27f [ELF] Make --gdb-index work with compressed output debug sections
Previously, we read compressed bogus data from the .debug_info section.

Fixes https://github.com/rui314/mold/issues/440
2022-04-22 08:55:16 +08:00
Rui Ueyama
eed62bd9d4 Update a test 2022-04-21 20:05:52 +08:00
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