1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-19 08:57:39 +03:00
Commit Graph

1265 Commits

Author SHA1 Message Date
Rui Ueyama
596ffa959a Add --separate-debug-info
This option is to separate debug info to a different file. The debug
info file's filename is stored to the main output file's .gnu_debuglink
section. gdb can read the section contents and followg the link to
find debug info in another file.

Fixes https://github.com/rui314/mold/issues/1294
2024-07-08 09:28:32 +09:00
Martin Liska
08f2a74be7 Improve --gdb-index test by using readelf --debug=gdb_index 2024-06-30 16:07:47 +02:00
Rui Ueyama
82fb10fe26 Fix a test 2024-06-28 15:57:10 +09:00
Rui Ueyama
63f26708fd Unbreak daily buildbot 2024-06-23 12:38:59 +09:00
Rui Ueyama
06b592683c Make weak undefined symbols to mark shared libraries as "needed"
It is not clearly defined when undefined weak symbols are resolved.
It looks like there are two possible approaches:

 1. Promote all weak undefined symbols to dynamic ones so that they'll
    have another chance to be resolved at load-time, or

 2. Promote weak undefined symbols to dynamic ones only when there are
    definitions in other DSOs at link-time.

(1) provides the maximum flexibility. For example, consider a main program
that has a weak undefined symbol `foo` and there's no DSO that defines it
at link-time. In (1), `foo` gets promoted to a dynamic symbol, so that one
of its depending DSO is upgraded to define `foo`, the main executable's
`foo` is resolved to that symbol at load-time. On the other hand, in (2),
`foo` would have already been converted to an absolute symbol at address
zero at link-time, so you need to rebuild the main executable to use the
new definition of `foo` in the shared library.

However, (1) is not compatible with copy relocations. This is because we
need to know the size of the symbol when creating a copy relocation, but
that information is not available unless we have a definition. It's also
not compatible with canonical PLTs because canonical PLTs have non-zero
addresses and therefore weak undefined symbols would always be resolved to
non-zero addresses.

As a workaround, GNU ld promotes weak undefs to dynamic symbols only when
they don't need copy relocations or canonical PLTs. In other words, weak
undef's behavior is different between -fPIC and -fno-PIC. In the former
case, they become dynamic symbols, and vice versa.

I don't think that workaround is a good one. So, mold took the second
approach.

There is, however, another thing to consider. What if we can find a
defined symbol in a DSO that is specified as `-as-needed`? Previously,
mold did not mark the library as "needed" and converted the weak undef
into an absolute symbol.

However, libstdc++ assumes that if weak undef symbol
`__pthread_key_create` is not resolved, it assumes that multi-threading is
not used in the executable, which resulted in a mis-detection with mold.

Therefore, this patch changes the mold's behavior so that it makes weak
undefs to keep DSOs "needed".

Fixes https://github.com/rui314/mold/issues/1286
2024-06-22 10:46:17 +09:00
Rui Ueyama
863893057e Allow numbers other than 1 for MOLD_JOBS 2024-06-18 18:28:28 +09:00
Yao Zi
d2774b0da9 Use $CXX to detect cxxflags
Use $CXX instead of $CC to detect whether C++ programs could be built
statically. Add function test_cxxflags for convenience.

Fix test error in an environment where C++ programs cannot be built
statically, with error like:

  mold: fatal: library not found: c++

Signed-off-by: Yao Zi <ziyao@disroot.org>
2024-06-16 20:16:34 +00:00
Rui Ueyama
8cd85aaa29 Make --undefined=ignore-in-object-files to override -z defs
The interaction between these flags are unnecessarily complicated,
but it looks like `--undefined=ignore-in-object-files` needs to
share the same internal flag as `-z defs` so that they override
each other.

Fixes https://github.com/rui314/mold/issues/1270
2024-05-31 22:00:03 +09:00
Rui Ueyama
c7c8583946 Allow larger range extension thunks
Fixes https://github.com/rui314/mold/issues/1224
2024-05-27 15:43:43 +09:00
Rui Ueyama
08b0a1629d Do not emit incorrect relocations for mergeable sections with --relocatable
Fixes https://github.com/rui314/mold/issues/1265
2024-05-24 13:01:10 +09:00
Rui Ueyama
4281f45f06 Do not record response files as dependency files
Fixes https://github.com/rui314/mold/issues/1258
2024-05-16 10:31:21 +09:00
Rui Ueyama
74129bfc86 Fix a test
Fixes https://github.com/rui314/mold/issues/1249
2024-05-06 13:54:17 +09:00
Rui Ueyama
595f98da78 Do not attempt to run an executable built with -z rodynamic
Such executables seem to crash immediately on older systems.
2024-05-06 13:12:33 +09:00
Rui Ueyama
2649b69e95 Fix CI 2024-05-05 22:43:58 +09:00
Rui Ueyama
9a233df7e2 Support -z rodynamic
LLVM lld supports the flag.

Fixes https://github.com/rui314/mold/issues/1253
2024-05-05 22:17:52 +09:00
Rui Ueyama
7b2cb47727 Refactor 2024-05-05 13:08:04 +09:00
Rui Ueyama
d683e8aa0b Add a test for SHF_GNU_RETAIN 2024-05-05 12:41:55 +09:00
Rui Ueyama
2b67afb8a3 Simplify
We no longer use `sold` as a command name.
2024-05-03 15:55:26 +09:00
Rui Ueyama
ed1e3c06a2 Do not copy mold executable to a test directory
mold executable can be quite large (~600 MiB with debug info),
so we don't want to casually copy that file.
2024-05-03 10:04:01 +09:00
Sam James
ec0a9d09dd
test: use command -v, not non-portable which
`which` isn't in POSIX and several Linux distributions are trying to
remove it from their base system, see e.g. https://lwn.net/Articles/874049/.

Just use `command -v` which is POSIX.

Signed-off-by: Sam James <sam@gentoo.org>
2024-04-30 07:54:40 +01:00
Rui Ueyama
ea054ccced Allow a newline or a tab at the begining of a linker script
Previously, the first four byte must have been "printable" bytes,
which exclude newlines or tabs.
2024-04-29 19:41:11 +09:00
Rui Ueyama
14952546a4 Do not edit binary files with sed
Fixes https://github.com/rui314/mold/issues/1244
2024-04-28 15:43:28 +09:00
Rui Ueyama
002d619b11 Attempt to fix a test failure
I believe some version of objcopy corrupts an object file when
renaming a section. In this change, I use sed instead of objcopy
as a workaround.

Fixes https://github.com/rui314/mold/issues/1244
2024-04-25 16:59:40 +09:00
Rui Ueyama
a9346f5c82 Add a test 2024-04-24 12:54:54 +09:00
Rui Ueyama
db8758060a Fix CI 2024-04-21 16:40:54 +09:00
Rui Ueyama
e498e2fd83 Do not create .copyrel.rel.ro if -z norelro is given 2024-04-21 14:52:51 +09:00
Rui Ueyama
6463a7c48a Fix non-deterministic behavior 2024-04-18 20:21:55 +09:00
Rui Ueyama
7434465334 Fix CI 2024-04-18 17:00:29 +09:00
Rui Ueyama
1648f716f4 Attempt to fix CI 2024-04-18 16:00:11 +09:00
Rui Ueyama
108b08fadb Fix a test 2024-04-18 14:47:36 +09:00
Rui Ueyama
204566cd14 Fix a crash bug involving synthesized symbols
If a synthesized symbol overrides an imported symbol, the symbol's
`is_imported` flag must be reset.

Technically, `compute_import_export` is called too early, and this
function call should be moved after `create_synthetic_sections`.
However, fixing the issue that way was very hard because until we
create output sections, we don't know what __start_/__stop_ symbols
need to be synthesized, but in order to create output sections,
we need to compute import/export bits.

So, in this commit, we simply reset `is_imported` flag for
synthesized symbols.

https://github.com/rui314/mold/pull/1236
2024-04-18 14:45:58 +09:00
Rui Ueyama
a3b4192e15 Revert "Give symbols in .so higher priority than those in .a"
This reverts commit dfa26d0882 because it
caused mysterious runtime issues with XWayland. I also observed that the
change affected gnupg and others.

Fixes https://github.com/rui314/mold/issues/1235
2024-04-15 21:42:52 +09:00
Rui Ueyama
dfa26d0882 1;10;0cGive symbols in .so higher priority than those in .a
Previously, .so and .a were of the same priority and therefore symbols
in those were resolved based on their positions in the command line;
whichever file appears first in the command line took precedence.

Here is the problem we are trying to solve with this change: KiCad
passes unnecessary .a files to the linker along with some .so files.
Some symbols are defined both by .a and by .so.

If a symbol is resolved from .a, the linker pulls out the file from
the archive, but because the .a file does not really provide a
complete set of object files, it ended with "undefined symbol" error.

If a symbol is resolved from .so, everything is fine.

This is arguably a bug in KiCad, or at least depending on the order of
files in the command line is very fragile. But maybe this change could
fix the issue without too much side effects. So let's see how it goes.

Fixes https://github.com/rui314/mold/discussions/1234
2024-04-15 12:19:50 +09:00
Rui Ueyama
77aefdf6a6 Refactor 2024-04-13 17:30:32 +09:00
Rui Ueyama
60ce1aaf01 Improve a test
We want to make sure that absolute symbols in DSOs are dynamically
resolved.
2024-04-12 16:36:40 +09:00
Rui Ueyama
7d17aa83eb Add --Bsymbolic-non-weak and --Bsymbolic-non-weak-functions
GNU ld doesn't support these options, but LLVM lld do.
2024-04-10 16:00:19 +09:00
Rui Ueyama
99a5b1541e Support -z start-stop-visibility=hidden
Fixes https://github.com/rui314/mold/issues/826
2024-04-08 13:11:15 +09:00
Rui Ueyama
4396784dbd Handle STT_COMMON as a synonym for STT_OBJECT 2024-04-05 20:33:13 +09:00
Rui Ueyama
9d8b243e39 Keep symbols specified by --undefined-glob during garbage collection 2024-03-29 17:39:12 +09:00
Rui Ueyama
95431aa7cf Do not run certain tests on qemu user-mode emulation
Fixes https://github.com/rui314/mold/pull/1206
2024-03-28 23:29:53 +09:00
Rui Ueyama
a1c835b993 Support --undefined-glob option 2024-03-28 16:44:43 +09:00
Rui Ueyama
4e3364ddd3 Format 2024-03-27 18:42:55 +09:00
Rui Ueyama
6e5ae45c1a Disable test on ppc64le
Fixes https://github.com/rui314/mold/issues/1221
2024-03-27 16:27:37 +09:00
Rui Ueyama
11c9376a50 Fix tests for musl libc-based systems
Fixes https://github.com/rui314/mold/issues/1221
2024-03-27 16:27:37 +09:00
Rui Ueyama
b5f2a7b1ce Do not call do_lto() if all LTO input files are dead
Fixes https://github.com/rui314/mold/issues/1226
2024-03-27 15:27:52 +09:00
Rui Ueyama
3df7c8e89c Export __global_pointer$ from executable
RISC-V psABI requires that symbol to be exported from an executable
if there's a GP-relative reference. For simplicity, we always export
it from executable as long as it has a .dynamic section.

https://github.com/rui314/mold/issues/1222
2024-03-25 17:57:52 +09:00
Rui Ueyama
0edbe29d38 Simplify 2024-03-25 17:57:52 +09:00
Rui Ueyama
32c4a09deb Fix file paths in .repro tar file
Previously, all pathnames were accidentally recorded as the name of
the tar file itself.

Fixes https://github.com/rui314/mold/issues/1227
2024-03-25 17:15:51 +09:00
Rui Ueyama
ee6907f678 Fix "skipping incompatible file" errors
https://github.com/rui314/mold/pull/1217
2024-03-25 14:52:54 +09:00
Rui Ueyama
163975d82a Make linker script INPUT command to look for a file from the script's directory
https://github.com/rui314/mold/pull/1217
2024-03-19 17:16:38 +09:00