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

240 Commits

Author SHA1 Message Date
Rui Ueyama
c797408167 Refactor 2022-05-27 14:07:20 +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
48c9157fb1 Refactor 2022-05-24 20:39:13 +08:00
Rui Ueyama
75df1c82f1 [Mach-O] Implement range extension thunks
mold can now link LLVM/Clang 15 on macOS.
2022-05-24 18:25:21 +08:00
Rui Ueyama
754b995e1c Refactor 2022-05-24 16:58:19 +08:00
Rui Ueyama
760f39d129 Refactor 2022-05-24 15:52:33 +08:00
Rui Ueyama
16735e1e68 [ELF] Simplify range extension thunk algorithm
We eliminate unneeded symbols at the end of the algorithm, but that
didn't save too much space. In fact, I didn't observe any difference
by eliminating that last step from the algorithm.
2022-05-24 11:19:32 +08:00
Rui Ueyama
18e24a6e4d [ELF][ARM32] Handle a displacement larger than 2^24 2022-05-23 20:47:52 +08:00
Rui Ueyama
0692db3481 Merge elf/output-file.cc and macho/output-file.cc into a single file 2022-05-17 16:22:17 +08:00
Rui Ueyama
f392b4aeb3 Refactor 2022-05-16 18:57:16 +08:00
Rui Ueyama
466e93ea46 [ELF] Change a variable name for consistency
We use the same spelling for a variable name and a command line option.
2022-05-16 10:20:36 +08:00
Tatsuyuki Ishi
e8166bcb1b [elf] Implement ignore-data-address-equality.
Closes: https://github.com/rui314/mold/issues/485
Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
2022-05-15 21:54:58 +09:00
Tatsuyuki Ishi
27908af67d [elf] Implement icf=safe.
Closes: https://github.com/rui314/mold/issues/484
Signed-off-by: Tatsuyuki Ishi <ishitatsuyuki@gmail.com>
2022-05-15 21:35:25 +09: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
fcb3bedf0d Refactor 2022-05-13 19:28:15 +08:00
Rui Ueyama
adb1ee4c0a Refactor 2022-05-11 20:17:47 +08:00
Rui Ueyama
ed9a29b713 Refactor 2022-05-03 20:23:18 +08:00
Rui Ueyama
06cdd7e951 Refactor 2022-05-03 20:04:01 +08:00
Rui Ueyama
86ad2c5b4d Simplify 2022-05-03 14:35:49 +08:00
Rui Ueyama
44228d91b0 Refactor 2022-05-03 13:34:03 +08:00
Rui Ueyama
3e18883b4b Refactor 2022-05-02 19:09:39 +08:00
Rui Ueyama
12cfddc611 Refactor
- Rename data types so that we have LittleEndian and BigEndian types.

- Do not assume that "base" integral types are aligned to 2 bytes
  boundaries, because that doesn't make much difference in terms of
  performance.

- Remove `pu8` type
2022-05-01 14:27:53 +08:00
Dawid Jurczak
3499ee6ac7 Add UBSan support
Core part of this change is cleaning up Mold from UBSan alignment errors.
Following approach inspired by LLVM's ELFTypes is done here:

    1. Introduce generic Packed class acting as proxy for unaligned aggregated value.
       Every access to such value through proxy is secured by memcpy call.
    2. Replace plain struct members with Packed members wherever it matters.
    3. Use explicit castings through Packed type for misaligned loads.

For more background please check: https://github.com/rui314/mold/discussions/477

Signed-off-by: Dawid Jurczak <dawid_jurek@vp.pl>
2022-04-30 17:37:14 +02:00
Rui Ueyama
2ce5e22193 Refactor
This commit makes it clear that Header, Output Section and Synthetic
Section are distinctive.
2022-04-30 17:07:39 +08:00
Rui Ueyama
a85b1f539a [ELF] Remove --preload 2022-04-30 15:03:24 +08:00
Rui Ueyama
e5bcbdf487 [ELF] Remove extraneous guards 2022-04-29 19:53:48 +08:00
Rui Ueyama
fafb75b0e5 [ELF] Fix race condition found by ThreadSanitizer 2022-04-29 19:53:48 +08:00
Rui Ueyama
f1f2d40469 [ELF] Support object files with more than 2^19 symbols
Previously, Symbol::sym_idx overflows if there are more than 524,288
symbols in a single file. That's a very large number but is not impossible.

Fixes https://github.com/rui314/mold/issues/405
2022-04-28 17:08:42 +08:00
Rui Ueyama
a63c25b020 [ELF] Respect --as-needed for LTO
Previously, we accidentally create DT_NEEDED entries for all DSOs
even if it is guaraded by --as-needed and is not used.
2022-04-28 11:40:31 +08:00
Rui Ueyama
43ab68b95d Simplify 2022-04-27 18:11:11 +08:00
Luboš Luňák
8b584f8297 [ELF] the --gdb-index code does not handle .debug_types
And there is probably little need to do so, since it's DWARF4-only
and requires explicit -fdebug-types-section, but at least detect
and abort in this case.
2022-04-27 07:55:48 +02: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
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
Rui Ueyama
a830fcdb58 Simplify 2022-04-23 17:01:24 +08:00
Rui Ueyama
ac244ede10 [ELF] Make .gdb_index contents reproducible
Previously, our output for .gdb_index depended on the iteration order of
ConcurrentMap. Since the iteration order varies on every run of the linker
 due to thread scheduling randomness, our .gdb_index were different on
 every lihnker invocation.

In mold, we guarantee that our output is the same as long as the same
command line options and input files are given to the same version of mold.
So the situation clearly violated the rule.

This commit fixes that issue.
2022-04-23 15:36:21 +08:00
Rui Ueyama
f9768c6352 [ELF] Set _TLS_MODULE_BAES_ to 0 if there's no TLS segment 2022-04-22 17:10:23 +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
Luboš Luňák
267a1ff5b7 [ELF] handle properly DW_FORM_rnglistx
The value is an index (offset by DW_AT_rnglists_base) into the first
part of .debug_rnglists, which is a list of offsets into the second
part of .debug_rnglists, which lists ranges, each entry starting
with a value describing how to interpret the data.

Signed-off-by: Luboš Luňák <l.lunak@centrum.cz>
2022-04-21 11:04:16 +02:00
Luboš Luňák
93cefc5280 [ELF] handle properly DW_FORM_addrx*
The value is not the address, it's an index into .debug_addr
that's additionally offset by DW_AT_addr_base.

Signed-off-by: Luboš Luňák <l.lunak@centrum.cz>
2022-04-21 11:04:16 +02:00
Rui Ueyama
fc798bc4ea Refactor 2022-04-21 09:59:36 +08:00
Rui Ueyama
8a5a9e1ffe Revert "[ELF] Do not emit address ranges for --gdb-index"
This reverts commit d4cc0ed3fb
because it broke gdb's stacktrace.
2022-04-21 09:59:36 +08: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
fa2ff3b9e9 [ELF] Align .gdb_index to a 4 bytes boundary
.gdb_index contains lots of 4 bytes integers, so we should align
them to 4 bytes boundaries.
2022-04-20 13:59:56 +08:00
Rui Ueyama
d4cc0ed3fb [ELF] Do not emit address ranges for --gdb-index
.gdb_index contains two maps: a map from identifiers (type names,
function names or variable names) to compunits, and a map from
function address ranges to compunits. The latter is harder to create
because we needed to parse DWARF debug records to read function
address ranges. We generally don't want to do that.

This commit stops emitting address ranges. Now, .gdb_index sections
created by our linker contains the zero-length map as address ranges.
Though I'm not 100% sure if this is actually OK, it looks like gdb
works fine with that. It's at least worth a try.

https://github.com/rui314/mold/issues/439
https://github.com/rui314/mold/issues/396
2022-04-19 13:38:25 +08:00
Rui Ueyama
a4398c7c32 [ELF] Factor out DWARF-related code to dwarf.cc 2022-04-19 12:43:51 +08:00
Rui Ueyama
369e8a19c5 Simplify 2022-04-17 19:25:22 +08:00
Rui Ueyama
d73587033f Simplify 2022-04-17 19:07:17 +08:00
Rui Ueyama
1fa6b3cd17 [ELF] Allow to build only for x86-64 or ARM64
mold is usually built for all supported tagets, namely, x86-64, i386,
ARM32, ARM64 and RISCV64. This is a good thing because it makes cross
compilation easy. That is, as long as you have a copy of the mold linker,
it is guaranteed to work as a cross linker.

However, during a quick debug session in which you build mold many
times, you may want to build mold only for your native target. That
greatly reduces build time because it reduces the amount of code
after template instantiation.

Therefore, in this commit, I introduced new macros,
MOLD_DEBUG_X86_64_ONLY and MOLD_DEBUG_ARM64_ONLY, to build mold for
x86-64 and ARM64 only, respectively.

These flags should never be used for production. They are solely for
debugging purpose.
2022-04-17 13:02:19 +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