2020-08-21 04:05:13 +08:00
|
|
|
//===- UnwindInfoSection.h ------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_MACHO_UNWIND_INFO_H
|
|
|
|
#define LLD_MACHO_UNWIND_INFO_H
|
|
|
|
|
2021-05-26 02:57:16 +08:00
|
|
|
#include "ConcatOutputSection.h"
|
2020-08-21 04:05:13 +08:00
|
|
|
#include "SyntheticSections.h"
|
2021-10-27 04:04:06 +08:00
|
|
|
#include "llvm/ADT/MapVector.h"
|
2020-08-21 04:05:13 +08:00
|
|
|
|
|
|
|
#include "mach-o/compact_unwind_encoding.h"
|
|
|
|
|
2022-08-07 22:37:49 +08:00
|
|
|
namespace lld::macho {
|
2020-08-21 04:05:13 +08:00
|
|
|
|
|
|
|
class UnwindInfoSection : public SyntheticSection {
|
|
|
|
public:
|
2021-10-27 04:04:06 +08:00
|
|
|
// If all functions are free of unwind info, we can omit the unwind info
|
|
|
|
// section entirely.
|
|
|
|
bool isNeeded() const override { return !allEntriesAreOmitted; }
|
|
|
|
void addSymbol(const Defined *);
|
2022-04-14 04:17:29 +08:00
|
|
|
virtual void prepareRelocations() = 0;
|
2020-08-21 04:05:13 +08:00
|
|
|
|
2021-04-16 09:14:33 +08:00
|
|
|
protected:
|
[lld-macho] Move ICF earlier to avoid emitting redundant binds
This is a pretty big refactoring diff, so here are the motivations:
Previously, ICF ran after scanRelocations(), where we emitting
bind/rebase opcodes etc. So we had a bunch of redundant leftovers after
ICF. Having ICF run before Writer seems like a better design, and is
what LLD-ELF does, so this diff refactors it accordingly.
However, ICF had two dependencies on things occurring in Writer: 1) it
needs literals to be deduplicated beforehand and 2) it needs to know
which functions have unwind info, which was being handled by
`UnwindInfoSection::prepareRelocations()`.
In order to do literal deduplication earlier, we need to add literal
input sections to their corresponding output sections. So instead of
putting all input sections into the big `inputSections` vector, and then
filtering them by type later on, I've changed things so that literal
sections get added directly to their output sections during the 'gather'
phase. Likewise for compact unwind sections -- they get added directly
to the UnwindInfoSection now. This latter change is not strictly
necessary, but makes it easier for ICF to determine which functions have
unwind info.
Adding literal sections directly to their output sections means that we
can no longer determine `inputOrder` from iterating over
`inputSections`. Instead, we store that order explicitly on
InputSection. Bloating the size of InputSection for this purpose would
be unfortunate -- but LLD-ELF has already solved this problem: it reuses
`outSecOff` to store this order value.
One downside of this refactor is that we now make an additional pass
over the unwind info relocations to figure out which functions have
unwind info, since want to know that before `processRelocations()`. I've
made sure to run that extra loop only if ICF is enabled, so there should
be no overhead in non-optimizing runs of the linker.
The upside of all this is that the `inputSections` vector now contains
only ConcatInputSections that are destined for ConcatOutputSections, so
we can clean up a bunch of code that just existed to filter out other
elements from that vector.
I will test for the lack of redundant binds/rebases in the upcoming
cfstring deduplication diff. While binds/rebases can also happen in the
regular `.text` section, they're more common in `.data` sections, so it
seems more natural to test it that way.
This change is perf-neutral when linking chromium_framework.
Reviewed By: oontvoo
Differential Revision: https://reviews.llvm.org/D105044
2021-07-02 08:33:42 +08:00
|
|
|
UnwindInfoSection();
|
2020-12-07 14:33:38 +08:00
|
|
|
|
2021-10-27 04:04:06 +08:00
|
|
|
llvm::MapVector<std::pair<const InputSection *, uint64_t /*Defined::value*/>,
|
|
|
|
const Defined *>
|
|
|
|
symbols;
|
2021-07-07 23:28:27 +08:00
|
|
|
bool allEntriesAreOmitted = true;
|
2020-08-21 04:05:13 +08:00
|
|
|
};
|
|
|
|
|
2021-04-16 09:14:33 +08:00
|
|
|
UnwindInfoSection *makeUnwindInfoSection();
|
2021-02-09 02:47:33 +08:00
|
|
|
|
2022-08-07 22:37:49 +08:00
|
|
|
} // namespace lld::macho
|
2020-08-21 04:05:13 +08:00
|
|
|
|
|
|
|
#endif
|