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

74 Commits

Author SHA1 Message Date
Rui Ueyama
c1c20aa427 refactor 2022-04-30 16:40:05 +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
e088db72e0 [ELF] Do not set PLT addresses to .symtab
Fixes https://github.com/rui314/mold/issues/473
2022-04-27 13:31:47 +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
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
f1e925d416 Update comments 2022-04-25 13:31:12 +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
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
cf850f8993 [ELF] Handle TLS common symbols
Fixes https://github.com/rui314/mold/issues/447
2022-04-21 13:58:43 +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
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
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
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
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
006b13aec1 Refactor 2022-04-04 17:26:11 +08:00
Rui Ueyama
615a24d1dd Add comments 2022-04-03 19:12:10 +08:00
Rui Ueyama
e1e4e9fd9e Fix data races found by ThreadSanitizer 2022-04-03 15:08:57 +08:00
Rui Ueyama
f4753b34bf [ELF] Fix use-after-free found by ASAN 2022-04-01 13:12:10 +08:00
Rui Ueyama
812c59fd5c Refactor 2022-03-23 15:00:29 +00:00
Rui Ueyama
6af78bf17b [ELF][ARM32] Do not keep .ARM.attributes sections
ARM32 object files usually contain a .ARM.attributes section.
We need to parse and merge .ARM.attributes sections.
But for now, we just remove them from inputs.
2022-03-23 14:11:14 +00:00
Rui Ueyama
9360267cc3 Refactor 2022-03-23 11:18:27 +00:00
Rui Ueyama
66a057cce7 [ELF][ARM64] Add a stub for ARM32 2022-03-10 16:27:31 +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
aae3dc3c1e Refactor 2022-03-05 20:27:10 +09:00
Christoph Grüninger
2f03e46bb3 input-files: Remove unused variable size
Removed code has no effect.
Left-over from code removal in 4dae896726.

Signed-off-by: Christoph Grüninger <foss@grueninger.de>
2022-03-05 00:30:30 +01:00
Rui Ueyama
8714b78d48 [ELF] Reduce memory usage a bit 2022-03-03 10:28:27 +09:00
Rui Ueyama
4dae896726 [ELF] Reduce the size of InputSection from 88 bytes to 72 bytes 2022-03-02 17:27:31 +09:00
Rui Ueyama
83e05dae28 [ELF] Reduce the size of FdeRecord from 24 bytes to 16 bytes
It saves 8 bytes for each input function.
2022-03-02 16:25:17 +09:00
Rui Ueyama
f49e4024e9 Rename a variable 2022-03-01 17:08:14 +09:00
Rui Ueyama
567a78dbd5 [ELF] Do not directly read st_shndx
If st_shndx is 0xffff, the actual section index value is in a
SHT_SYMTAB_SHNDX section.
2022-03-01 14:47:51 +09:00
Rui Ueyama
f2d27d8d24 [ELF] Shrink the size of Symbol from 56 bytes to 48 bytes
This is a second attempt to reduce the size of the Symbol class.
2022-03-01 12:03:35 +09:00
Rui Ueyama
e469b04f0d Revert "[ELF] Shrink the size of Symbol from 56 bytes to 48 bytes"
This reverts commit 32e158d340
because it broke some tests when mold is built with itself.
2022-03-01 07:49:57 +09:00
Rui Ueyama
32e158d340 [ELF] Shrink the size of Symbol from 56 bytes to 48 bytes 2022-02-28 20:53:40 +09:00
Rui Ueyama
a1e6d8e8df Add comments 2022-02-22 13:18:09 +09:00
Rui Ueyama
c173f9c0ab Simplify 2022-02-21 18:26:51 +09:00
Rui Ueyama
d258140d54 Inline a default constructor 2022-02-20 16:04:00 +09:00
Rui Ueyama
15fa05eff6 [ELF][LTO] Clear symbols after LTO
This commit ensure that all symbol resolution results are cleared
after LTO, so that the following second symbol resolution will not
be affected by the previous results.
2022-02-18 22:05:14 +09:00
Rui Ueyama
d908d4c61c [ELF] Handle global symbols in mergeable sections correctly
Prior to this patch, mold computeed a wrong address for a global
symbol in a mergeable section. believe it was a regression in
60d0900496.

Fixes https://github.com/rui314/mold/issues/347
2022-02-16 12:05:40 +09:00
Rui Ueyama
b94dd6dbeb Revert "[ELF] add method to check whether an input file is shared object"
This reverts commit ddcb7b4197. `is_dso`
is used by hot functions such as `Symbol::get_addr()`, so we want to
eliminate the cost of virtual function dispatch.
2022-02-16 09:51:07 +09:00
Rui Ueyama
81cf1171a9 Simplify 2022-02-10 18:23:59 +09:00
Dmitry Antipov
ddcb7b4197 [ELF] add method to check whether an input file is shared object
Prefer pure virtual 'mold:🧝:InputFile::is_dso()' (actually
implemented in 'mold:🧝:ObjectFile' and 'mold:🧝:SharedFile')
over the field of the same name, adjust related code.

Signed-off-by: Dmitry Antipov dantipov@cloudlinux.com
2022-02-08 10:19:56 +03:00
Rui Ueyama
e65c5d2a1c [ELF] Handle ABI incompatibility between -fgnu-unique and -fno-gnu-unique
GCC creates symbols in comdat groups as STB_GNU_UNIQUE instead of STB_WEAK
if it was configured to do so at build time or the -fgnu-unique option was
given. If mold is given two object files with and without STB_GNU_UNIQUE,
it could end up selecting a sybmol that is in a de-duplicated comdat group.

This is arguably just an ABI incompatibility. Two comdat groups must
contain the same contents if their identifiers are the same. But we
can't handle it as an error because it is not uncommon to link object
files compiled using Clang (or GCC without -fgnu-unique) to static
libraries built with GCC that produces STB_GNU_UNIQUE symbols.

This patch gives the same priority to STB_GNU_UNIQUE as STB_WEAK so that
mold won't select symbols in discarded comdat groups.

Frankly, the situation around STB_GNU_UNIQUE is a mess. That GNU extension
shouldn't have been added to the GNU toolchain in the first place.
It looks like GCC shipped with Linux distros are nowadays do not produce
STB_GNU_UNIQUE symbols by default, but we still need to handle them.

Fixes https://github.com/rui314/mold/issues/324
2022-02-07 07:53:58 +09:00
Rui Ueyama
27c50e8158 [ELF] Report an error for an unresolved hidden undef correctly
Previously, if a protected/hidden undef symbol is resolved to a DSO
symbol,  mold didn't report a symbol undefined error.

Fixes https://github.com/rui314/mold/issues/329
2022-02-06 13:49:17 +09:00
Rui Ueyama
f24b997501 [ELF} Add --warn-once 2022-02-05 11:39:59 +09:00
Rui Ueyama
dca8d58b51 Refactor 2022-02-04 18:26:41 +09:00