2020-04-22 04:37:57 +08:00
|
|
|
//===- SyntheticSections.h -------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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_SYNTHETIC_SECTIONS_H
|
|
|
|
#define LLD_MACHO_SYNTHETIC_SECTIONS_H
|
|
|
|
|
2020-05-19 11:28:50 +08:00
|
|
|
#include "Config.h"
|
2020-04-30 06:42:19 +08:00
|
|
|
#include "ExportTrie.h"
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
#include "InputSection.h"
|
2020-05-02 07:29:06 +08:00
|
|
|
#include "OutputSection.h"
|
2020-08-13 10:50:09 +08:00
|
|
|
#include "OutputSegment.h"
|
2020-04-22 04:37:57 +08:00
|
|
|
#include "Target.h"
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
|
2020-08-21 05:45:51 +08:00
|
|
|
#include "llvm/ADT/PointerUnion.h"
|
2020-04-22 04:37:57 +08:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2021-01-07 10:11:44 +08:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2020-04-22 04:37:57 +08:00
|
|
|
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
namespace llvm {
|
|
|
|
class DWARFUnit;
|
|
|
|
} // namespace llvm
|
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
namespace lld {
|
|
|
|
namespace macho {
|
|
|
|
|
2020-08-28 06:59:30 +08:00
|
|
|
class Defined;
|
2020-04-22 04:37:57 +08:00
|
|
|
class DylibSymbol;
|
2020-04-28 03:50:59 +08:00
|
|
|
class LoadCommand;
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
class ObjFile;
|
2020-04-28 03:50:59 +08:00
|
|
|
|
2020-05-02 07:29:06 +08:00
|
|
|
class SyntheticSection : public OutputSection {
|
|
|
|
public:
|
|
|
|
SyntheticSection(const char *segname, const char *name);
|
|
|
|
virtual ~SyntheticSection() = default;
|
2020-05-06 07:37:34 +08:00
|
|
|
|
|
|
|
static bool classof(const OutputSection *sec) {
|
|
|
|
return sec->kind() == SyntheticKind;
|
|
|
|
}
|
[lld-macho] Refactor segment/section creation, sorting, and merging
Summary:
There were a few issues with the previous setup:
1. The section sorting comparator used a declarative map of section names to
determine the correct order, but it turns out we need to match on more than
just names -- in particular, an upcoming diff will sort based on whether the
S_ZERO_FILL flag is set. This diff changes the sorter to a more imperative but
flexible form.
2. We were sorting OutputSections stored in a MapVector, which left the
MapVector in an inconsistent state -- the wrong keys map to the wrong values!
In practice, we weren't doing key lookups (only container iteration) after the
sort, so this was fine, but it was still a dubious state of affairs. This diff
copies the OutputSections to a vector before sorting them.
3. We were adding unneeded OutputSections to OutputSegments and then filtering
them out later, which meant that we had to remember whether an OutputSegment
was in a pre- or post-filtered state. This diff only adds the sections to the
segments if they are needed.
In addition to those major changes, two minor ones worth noting:
1. I renamed all OutputSection variable names to `osec`, to parallel `isec`.
Previously we were using some inconsistent combination of `osec`, `os`, and
`section`.
2. I added a check (and a test) for InputSections with names that clashed with
those of our synthetic OutputSections.
Reviewers: #lld-macho
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81887
2020-06-15 15:03:24 +08:00
|
|
|
|
|
|
|
const StringRef segname;
|
2021-03-13 06:26:12 +08:00
|
|
|
// This fake InputSection makes it easier for us to write code that applies
|
|
|
|
// generically to both user inputs and synthetics.
|
|
|
|
InputSection *isec;
|
2020-05-02 07:29:06 +08:00
|
|
|
};
|
|
|
|
|
2020-07-31 05:29:14 +08:00
|
|
|
// All sections in __LINKEDIT should inherit from this.
|
|
|
|
class LinkEditSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
LinkEditSection(const char *segname, const char *name)
|
|
|
|
: SyntheticSection(segname, name) {
|
2021-04-03 06:46:18 +08:00
|
|
|
align = target->wordSize;
|
2020-07-31 05:29:14 +08:00
|
|
|
}
|
|
|
|
|
2021-04-08 07:55:45 +08:00
|
|
|
virtual void finalizeContents() {}
|
|
|
|
|
2020-08-28 08:43:19 +08:00
|
|
|
// Sections in __LINKEDIT are special: their offsets are recorded in the
|
|
|
|
// load commands like LC_DYLD_INFO_ONLY and LC_SYMTAB, instead of in section
|
|
|
|
// headers.
|
|
|
|
bool isHidden() const override final { return true; }
|
|
|
|
|
2020-07-31 05:29:14 +08:00
|
|
|
virtual uint64_t getRawSize() const = 0;
|
|
|
|
|
|
|
|
// codesign (or more specifically libstuff) checks that each section in
|
|
|
|
// __LINKEDIT ends where the next one starts -- no gaps are permitted. We
|
|
|
|
// therefore align every section's start and end points to WordSize.
|
|
|
|
//
|
|
|
|
// NOTE: This assumes that the extra bytes required for alignment can be
|
|
|
|
// zero-valued bytes.
|
|
|
|
uint64_t getSize() const override final {
|
2021-01-07 10:11:44 +08:00
|
|
|
return llvm::alignTo(getRawSize(), align);
|
2020-07-31 05:29:14 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-28 03:50:59 +08:00
|
|
|
// The header of the Mach-O file, which must have a file offset of zero.
|
2020-05-02 07:29:06 +08:00
|
|
|
class MachHeaderSection : public SyntheticSection {
|
2020-04-28 03:50:59 +08:00
|
|
|
public:
|
|
|
|
void addLoadCommand(LoadCommand *);
|
|
|
|
bool isHidden() const override { return true; }
|
|
|
|
|
2021-04-03 06:46:18 +08:00
|
|
|
protected:
|
|
|
|
MachHeaderSection();
|
2020-04-28 03:50:59 +08:00
|
|
|
std::vector<LoadCommand *> loadCommands;
|
|
|
|
uint32_t sizeOfCmds = 0;
|
|
|
|
};
|
|
|
|
|
2021-04-03 06:46:18 +08:00
|
|
|
template <class LP> MachHeaderSection *makeMachHeaderSection();
|
|
|
|
|
2020-04-28 03:50:59 +08:00
|
|
|
// A hidden section that exists solely for the purpose of creating the
|
|
|
|
// __PAGEZERO segment, which is used to catch null pointer dereferences.
|
2020-05-02 07:29:06 +08:00
|
|
|
class PageZeroSection : public SyntheticSection {
|
2020-04-28 03:50:59 +08:00
|
|
|
public:
|
|
|
|
PageZeroSection();
|
|
|
|
bool isHidden() const override { return true; }
|
2021-04-03 06:46:18 +08:00
|
|
|
uint64_t getSize() const override { return target->pageZeroSize; }
|
2020-04-28 03:50:59 +08:00
|
|
|
uint64_t getFileSize() const override { return 0; }
|
2020-05-02 07:29:06 +08:00
|
|
|
void writeTo(uint8_t *buf) const override {}
|
2020-04-28 03:50:59 +08:00
|
|
|
};
|
2020-04-22 04:37:57 +08:00
|
|
|
|
2020-08-13 10:50:09 +08:00
|
|
|
// This is the base class for the GOT and TLVPointer sections, which are nearly
|
|
|
|
// functionally identical -- they will both be populated by dyld with addresses
|
|
|
|
// to non-lazily-loaded dylib symbols. The main difference is that the
|
|
|
|
// TLVPointerSection stores references to thread-local variables.
|
|
|
|
class NonLazyPointerSectionBase : public SyntheticSection {
|
2020-04-22 04:37:57 +08:00
|
|
|
public:
|
2020-08-13 10:50:09 +08:00
|
|
|
NonLazyPointerSectionBase(const char *segname, const char *name);
|
2020-04-22 04:37:57 +08:00
|
|
|
|
2020-06-14 11:00:06 +08:00
|
|
|
const llvm::SetVector<const Symbol *> &getEntries() const { return entries; }
|
2020-04-22 04:37:57 +08:00
|
|
|
|
2020-04-28 03:50:59 +08:00
|
|
|
bool isNeeded() const override { return !entries.empty(); }
|
|
|
|
|
2021-04-03 06:46:18 +08:00
|
|
|
uint64_t getSize() const override {
|
|
|
|
return entries.size() * target->wordSize;
|
|
|
|
}
|
2020-05-02 07:29:06 +08:00
|
|
|
|
2020-06-14 11:00:06 +08:00
|
|
|
void writeTo(uint8_t *buf) const override;
|
2020-04-22 04:37:57 +08:00
|
|
|
|
2020-08-21 05:45:51 +08:00
|
|
|
void addEntry(Symbol *sym);
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
private:
|
2020-06-14 11:00:06 +08:00
|
|
|
llvm::SetVector<const Symbol *> entries;
|
2020-04-22 04:37:57 +08:00
|
|
|
};
|
|
|
|
|
2020-08-13 10:50:09 +08:00
|
|
|
class GotSection : public NonLazyPointerSectionBase {
|
|
|
|
public:
|
|
|
|
GotSection()
|
|
|
|
: NonLazyPointerSectionBase(segment_names::dataConst,
|
|
|
|
section_names::got) {
|
|
|
|
// TODO: section_64::reserved1 should be an index into the indirect symbol
|
|
|
|
// table, which we do not currently emit
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TlvPointerSection : public NonLazyPointerSectionBase {
|
|
|
|
public:
|
|
|
|
TlvPointerSection()
|
|
|
|
: NonLazyPointerSectionBase(segment_names::data,
|
|
|
|
section_names::threadPtrs) {}
|
|
|
|
};
|
|
|
|
|
2020-09-06 01:55:33 +08:00
|
|
|
struct Location {
|
2021-03-13 06:26:12 +08:00
|
|
|
const InputSection *isec;
|
|
|
|
uint64_t offset;
|
2020-08-21 05:45:51 +08:00
|
|
|
|
2021-03-13 06:26:12 +08:00
|
|
|
Location(const InputSection *isec, uint64_t offset)
|
|
|
|
: isec(isec), offset(offset) {}
|
|
|
|
uint64_t getVA() const { return isec->getVA() + offset; }
|
2020-07-03 12:19:55 +08:00
|
|
|
};
|
|
|
|
|
2020-09-06 01:55:33 +08:00
|
|
|
// Stores rebase opcodes, which tell dyld where absolute addresses have been
|
|
|
|
// encoded in the binary. If the binary is not loaded at its preferred address,
|
|
|
|
// dyld has to rebase these addresses by adding an offset to them.
|
|
|
|
class RebaseSection : public LinkEditSection {
|
|
|
|
public:
|
|
|
|
RebaseSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-09-06 01:55:33 +08:00
|
|
|
uint64_t getRawSize() const override { return contents.size(); }
|
|
|
|
bool isNeeded() const override { return !locations.empty(); }
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
|
2021-03-13 06:26:12 +08:00
|
|
|
void addEntry(const InputSection *isec, uint64_t offset) {
|
2020-09-06 01:55:33 +08:00
|
|
|
if (config->isPic)
|
2021-03-13 06:26:12 +08:00
|
|
|
locations.push_back({isec, offset});
|
2020-09-06 01:55:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<Location> locations;
|
|
|
|
SmallVector<char, 128> contents;
|
|
|
|
};
|
|
|
|
|
2020-08-25 12:57:59 +08:00
|
|
|
struct BindingEntry {
|
|
|
|
const DylibSymbol *dysym;
|
2020-09-06 01:55:33 +08:00
|
|
|
int64_t addend;
|
|
|
|
Location target;
|
|
|
|
BindingEntry(const DylibSymbol *dysym, int64_t addend, Location target)
|
|
|
|
: dysym(dysym), addend(addend), target(std::move(target)) {}
|
2020-08-25 12:57:59 +08:00
|
|
|
};
|
|
|
|
|
2020-04-28 03:50:59 +08:00
|
|
|
// Stores bind opcodes for telling dyld which symbols to load non-lazily.
|
2020-07-31 05:29:14 +08:00
|
|
|
class BindingSection : public LinkEditSection {
|
2020-04-28 03:50:59 +08:00
|
|
|
public:
|
|
|
|
BindingSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-07-31 05:29:14 +08:00
|
|
|
uint64_t getRawSize() const override { return contents.size(); }
|
2020-08-21 05:45:51 +08:00
|
|
|
bool isNeeded() const override { return !bindings.empty(); }
|
2020-05-02 07:29:06 +08:00
|
|
|
void writeTo(uint8_t *buf) const override;
|
2020-04-28 03:50:59 +08:00
|
|
|
|
2021-03-13 06:26:12 +08:00
|
|
|
void addEntry(const DylibSymbol *dysym, const InputSection *isec,
|
2020-08-21 05:45:51 +08:00
|
|
|
uint64_t offset, int64_t addend = 0) {
|
2021-03-13 06:26:12 +08:00
|
|
|
bindings.emplace_back(dysym, addend, Location(isec, offset));
|
2020-07-03 12:19:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<BindingEntry> bindings;
|
2020-04-28 03:50:59 +08:00
|
|
|
SmallVector<char, 128> contents;
|
|
|
|
};
|
|
|
|
|
2020-08-25 12:57:59 +08:00
|
|
|
struct WeakBindingEntry {
|
|
|
|
const Symbol *symbol;
|
2020-09-06 01:55:33 +08:00
|
|
|
int64_t addend;
|
|
|
|
Location target;
|
|
|
|
WeakBindingEntry(const Symbol *symbol, int64_t addend, Location target)
|
|
|
|
: symbol(symbol), addend(addend), target(std::move(target)) {}
|
2020-08-25 12:57:59 +08:00
|
|
|
};
|
|
|
|
|
2020-08-28 06:59:30 +08:00
|
|
|
// Stores bind opcodes for telling dyld which weak symbols need coalescing.
|
|
|
|
// There are two types of entries in this section:
|
|
|
|
//
|
|
|
|
// 1) Non-weak definitions: This is a symbol definition that weak symbols in
|
|
|
|
// other dylibs should coalesce to.
|
|
|
|
//
|
|
|
|
// 2) Weak bindings: These tell dyld that a given symbol reference should
|
|
|
|
// coalesce to a non-weak definition if one is found. Note that unlike in the
|
|
|
|
// entries in the BindingSection, the bindings here only refer to these
|
|
|
|
// symbols by name, but do not specify which dylib to load them from.
|
2020-08-25 12:57:59 +08:00
|
|
|
class WeakBindingSection : public LinkEditSection {
|
|
|
|
public:
|
|
|
|
WeakBindingSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-08-25 12:57:59 +08:00
|
|
|
uint64_t getRawSize() const override { return contents.size(); }
|
2020-08-28 06:59:30 +08:00
|
|
|
bool isNeeded() const override {
|
|
|
|
return !bindings.empty() || !definitions.empty();
|
|
|
|
}
|
2020-08-25 12:57:59 +08:00
|
|
|
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
|
2021-03-13 06:26:12 +08:00
|
|
|
void addEntry(const Symbol *symbol, const InputSection *isec, uint64_t offset,
|
|
|
|
int64_t addend = 0) {
|
|
|
|
bindings.emplace_back(symbol, addend, Location(isec, offset));
|
2020-08-25 12:57:59 +08:00
|
|
|
}
|
|
|
|
|
2020-08-28 06:59:30 +08:00
|
|
|
bool hasEntry() const { return !bindings.empty(); }
|
|
|
|
|
|
|
|
void addNonWeakDefinition(const Defined *defined) {
|
|
|
|
definitions.emplace_back(defined);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasNonWeakDefinition() const { return !definitions.empty(); }
|
|
|
|
|
2020-08-25 12:57:59 +08:00
|
|
|
private:
|
|
|
|
std::vector<WeakBindingEntry> bindings;
|
2020-08-28 06:59:30 +08:00
|
|
|
std::vector<const Defined *> definitions;
|
2020-08-25 12:57:59 +08:00
|
|
|
SmallVector<char, 128> contents;
|
|
|
|
};
|
|
|
|
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
// The following sections implement lazy symbol binding -- very similar to the
|
|
|
|
// PLT mechanism in ELF.
|
|
|
|
//
|
2020-08-28 06:54:42 +08:00
|
|
|
// ELF's .plt section is broken up into two sections in Mach-O: StubsSection
|
|
|
|
// and StubHelperSection. Calls to functions in dylibs will end up calling into
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
// StubsSection, which contains indirect jumps to addresses stored in the
|
|
|
|
// LazyPointerSection (the counterpart to ELF's .plt.got).
|
|
|
|
//
|
2020-08-28 06:54:42 +08:00
|
|
|
// We will first describe how non-weak symbols are handled.
|
|
|
|
//
|
|
|
|
// At program start, the LazyPointerSection contains addresses that point into
|
|
|
|
// one of the entry points in the middle of the StubHelperSection. The code in
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
// StubHelperSection will push on the stack an offset into the
|
|
|
|
// LazyBindingSection. The push is followed by a jump to the beginning of the
|
|
|
|
// StubHelperSection (similar to PLT0), which then calls into dyld_stub_binder.
|
|
|
|
// dyld_stub_binder is a non-lazily-bound symbol, so this call looks it up in
|
|
|
|
// the GOT.
|
|
|
|
//
|
|
|
|
// The stub binder will look up the bind opcodes in the LazyBindingSection at
|
2020-08-28 06:54:42 +08:00
|
|
|
// the given offset. The bind opcodes will tell the binder to update the
|
|
|
|
// address in the LazyPointerSection to point to the symbol, so that subsequent
|
|
|
|
// calls don't have to redo the symbol resolution. The binder will then jump to
|
|
|
|
// the resolved symbol.
|
|
|
|
//
|
|
|
|
// With weak symbols, the situation is slightly different. Since there is no
|
|
|
|
// "weak lazy" lookup, function calls to weak symbols are always non-lazily
|
|
|
|
// bound. We emit both regular non-lazy bindings as well as weak bindings, in
|
|
|
|
// order that the weak bindings may overwrite the non-lazy bindings if an
|
|
|
|
// appropriate symbol is found at runtime. However, the bound addresses will
|
|
|
|
// still be written (non-lazily) into the LazyPointerSection.
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
|
|
|
|
class StubsSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
StubsSection();
|
2020-06-17 08:27:28 +08:00
|
|
|
uint64_t getSize() const override;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
bool isNeeded() const override { return !entries.empty(); }
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
2020-08-28 06:54:42 +08:00
|
|
|
const llvm::SetVector<Symbol *> &getEntries() const { return entries; }
|
|
|
|
// Returns whether the symbol was added. Note that every stubs entry will
|
|
|
|
// have a corresponding entry in the LazyPointerSection.
|
|
|
|
bool addEntry(Symbol *);
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
|
|
|
|
private:
|
2020-08-28 06:54:42 +08:00
|
|
|
llvm::SetVector<Symbol *> entries;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class StubHelperSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
StubHelperSection();
|
2020-06-17 08:27:28 +08:00
|
|
|
uint64_t getSize() const override;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
bool isNeeded() const override;
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
|
|
|
|
void setup();
|
|
|
|
|
|
|
|
DylibSymbol *stubBinder = nullptr;
|
[lld/mac] Implement support for private extern symbols
Private extern symbols are used for things scoped to the linkage unit.
They cause duplicate symbol errors (so they're in the symbol table,
unlike TU-scoped truly local symbols), but they don't make it into the
export trie. They are created e.g. by compiling with
-fvisibility=hidden.
If two weak symbols have differing privateness, the combined symbol is
non-private external. (Example: inline functions and some TUs that
include the header defining it were built with
-fvisibility-inlines-hidden and some weren't).
A weak private external symbol implicitly has its "weak" dropped and
behaves like a regular strong private external symbol: Weak is an export
trie concept, and private symbols are not in the export trie.
If a weak and a strong symbol have different privateness, the strong
symbol wins.
If two common symbols have differing privateness, the larger symbol
wins. If they have the same size, the privateness of the symbol seen
later during the link wins (!) -- this is a bit lame, but it matches
ld64 and this behavior takes 2 lines less to implement than the less
surprising "result is non-private external), so match ld64.
(Example: `int a` in two .c files, both built with -fcommon,
one built with -fvisibility=hidden and one without.)
This also makes `__dyld_private` a true TU-local symbol, matching ld64.
To make this work, make the `const char*` StringRefZ ctor to correctly
set `size` (without this, writing the string table crashed when calling
getName() on the __dyld_private symbol).
Mention in CommonSymbol's comment that common symbols are now disabled
by default in clang.
Mention in -keep_private_externs's HelpText that the flag only has an
effect with `-r` (which we don't implement yet -- so this patch here
doesn't regress any behavior around -r + -keep_private_externs)). ld64
doesn't explicitly document it, but the commit text of
http://reviews.llvm.org/rL216146 does, and ld64's
OutputFile::buildSymbolTable() checks `_options.outputKind() ==
Options::kObjectFile` before calling `_options.keepPrivateExterns()`
(the only reference to that function).
Fixes PR48536.
Differential Revision: https://reviews.llvm.org/D93609
2020-12-18 02:30:18 +08:00
|
|
|
Defined *dyldPrivate = nullptr;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// This section contains space for just a single word, and will be used by dyld
|
|
|
|
// to cache an address to the image loader it uses. Note that unlike the other
|
|
|
|
// synthetic sections, which are OutputSections, the ImageLoaderCacheSection is
|
|
|
|
// an InputSection that gets merged into the __data OutputSection.
|
|
|
|
class ImageLoaderCacheSection : public InputSection {
|
|
|
|
public:
|
|
|
|
ImageLoaderCacheSection();
|
2021-04-03 06:46:18 +08:00
|
|
|
uint64_t getSize() const override { return target->wordSize; }
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
};
|
|
|
|
|
2020-08-28 06:54:42 +08:00
|
|
|
// Note that this section may also be targeted by non-lazy bindings. In
|
|
|
|
// particular, this happens when branch relocations target weak symbols.
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
class LazyPointerSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
LazyPointerSection();
|
2020-06-17 08:27:28 +08:00
|
|
|
uint64_t getSize() const override;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
bool isNeeded() const override;
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
};
|
|
|
|
|
2020-07-31 05:29:14 +08:00
|
|
|
class LazyBindingSection : public LinkEditSection {
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
public:
|
|
|
|
LazyBindingSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-07-31 05:29:14 +08:00
|
|
|
uint64_t getRawSize() const override { return contents.size(); }
|
2020-08-28 06:54:42 +08:00
|
|
|
bool isNeeded() const override { return !entries.empty(); }
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
void writeTo(uint8_t *buf) const override;
|
2020-08-28 06:54:42 +08:00
|
|
|
// Note that every entry here will by referenced by a corresponding entry in
|
|
|
|
// the StubHelperSection.
|
|
|
|
void addEntry(DylibSymbol *dysym);
|
|
|
|
const llvm::SetVector<DylibSymbol *> &getEntries() const { return entries; }
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
|
|
|
|
private:
|
2020-08-28 06:54:42 +08:00
|
|
|
uint32_t encode(const DylibSymbol &);
|
|
|
|
|
|
|
|
llvm::SetVector<DylibSymbol *> entries;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
SmallVector<char, 128> contents;
|
|
|
|
llvm::raw_svector_ostream os{contents};
|
|
|
|
};
|
|
|
|
|
2020-04-29 07:58:22 +08:00
|
|
|
// Stores a trie that describes the set of exported symbols.
|
2020-07-31 05:29:14 +08:00
|
|
|
class ExportSection : public LinkEditSection {
|
2020-04-29 07:58:22 +08:00
|
|
|
public:
|
|
|
|
ExportSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-07-31 05:29:14 +08:00
|
|
|
uint64_t getRawSize() const override { return size; }
|
2020-05-02 07:29:06 +08:00
|
|
|
void writeTo(uint8_t *buf) const override;
|
2020-04-29 07:58:22 +08:00
|
|
|
|
2020-08-28 06:59:15 +08:00
|
|
|
bool hasWeakSymbol = false;
|
|
|
|
|
2020-04-30 06:42:19 +08:00
|
|
|
private:
|
|
|
|
TrieBuilder trieBuilder;
|
|
|
|
size_t size = 0;
|
2020-04-29 07:58:22 +08:00
|
|
|
};
|
|
|
|
|
2021-03-09 14:00:37 +08:00
|
|
|
class FunctionStartsSection : public LinkEditSection {
|
|
|
|
public:
|
|
|
|
FunctionStartsSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2021-03-09 14:00:37 +08:00
|
|
|
uint64_t getRawSize() const override { return contents.size(); }
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SmallVector<char, 128> contents;
|
|
|
|
};
|
|
|
|
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
// Stores the strings referenced by the symbol table.
|
2020-07-31 05:29:14 +08:00
|
|
|
class StringTableSection : public LinkEditSection {
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
public:
|
|
|
|
StringTableSection();
|
|
|
|
// Returns the start offset of the added string.
|
|
|
|
uint32_t addString(StringRef);
|
2020-07-31 05:29:14 +08:00
|
|
|
uint64_t getRawSize() const override { return size; }
|
2020-05-02 07:29:06 +08:00
|
|
|
void writeTo(uint8_t *buf) const override;
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
|
2021-04-08 00:08:14 +08:00
|
|
|
static constexpr size_t emptyStringIndex = 1;
|
|
|
|
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
private:
|
2020-12-02 06:45:10 +08:00
|
|
|
// ld64 emits string tables which start with a space and a zero byte. We
|
|
|
|
// match its behavior here since some tools depend on it.
|
2021-04-08 00:08:14 +08:00
|
|
|
// Consequently, the empty string will be at index 1, not zero.
|
2020-12-02 06:45:10 +08:00
|
|
|
std::vector<StringRef> strings{" "};
|
|
|
|
size_t size = 2;
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SymtabEntry {
|
|
|
|
Symbol *sym;
|
|
|
|
size_t strx;
|
|
|
|
};
|
|
|
|
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
struct StabsEntry {
|
2020-12-02 06:45:12 +08:00
|
|
|
uint8_t type = 0;
|
2021-04-08 00:08:14 +08:00
|
|
|
uint32_t strx = StringTableSection::emptyStringIndex;
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
uint8_t sect = 0;
|
|
|
|
uint16_t desc = 0;
|
|
|
|
uint64_t value = 0;
|
|
|
|
|
2020-12-02 06:45:12 +08:00
|
|
|
StabsEntry() = default;
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
explicit StabsEntry(uint8_t type) : type(type) {}
|
|
|
|
};
|
|
|
|
|
2020-12-02 06:45:09 +08:00
|
|
|
// Symbols of the same type must be laid out contiguously: we choose to emit
|
|
|
|
// all local symbols first, then external symbols, and finally undefined
|
|
|
|
// symbols. For each symbol type, the LC_DYSYMTAB load command will record the
|
|
|
|
// range (start index and total number) of those symbols in the symbol table.
|
2020-08-28 08:43:19 +08:00
|
|
|
class SymtabSection : public LinkEditSection {
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
public:
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-12-02 06:45:09 +08:00
|
|
|
uint32_t getNumSymbols() const;
|
|
|
|
uint32_t getNumLocalSymbols() const {
|
|
|
|
return stabs.size() + localSymbols.size();
|
|
|
|
}
|
|
|
|
uint32_t getNumExternalSymbols() const { return externalSymbols.size(); }
|
|
|
|
uint32_t getNumUndefinedSymbols() const { return undefinedSymbols.size(); }
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
|
|
|
|
private:
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
void emitBeginSourceStab(llvm::DWARFUnit *compileUnit);
|
|
|
|
void emitEndSourceStab();
|
|
|
|
void emitObjectFileStab(ObjFile *);
|
2020-12-02 06:45:12 +08:00
|
|
|
void emitEndFunStab(Defined *);
|
|
|
|
void emitStabs();
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
|
2021-04-03 06:46:18 +08:00
|
|
|
protected:
|
|
|
|
SymtabSection(StringTableSection &);
|
|
|
|
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
StringTableSection &stringTableSection;
|
2020-12-02 06:45:09 +08:00
|
|
|
// STABS symbols are always local symbols, but we represent them with special
|
|
|
|
// entries because they may use fields like n_sect and n_desc differently.
|
[lld-macho] Emit STABS symbols for debugging, and drop debug sections
Debug sections contain a large amount of data. In order not to bloat the size
of the final binary, we remove them and instead emit STABS symbols for
`dsymutil` and the debugger to locate their contents in the object files.
With this diff, `dsymutil` is able to locate the debug info. However, we need
a few more features before `lldb` is able to work well with our binaries --
e.g. having `LC_DYSYMTAB` accurately reflect the number of local symbols,
emitting `LC_UUID`, and more. Those will be handled in follow-up diffs.
Note also that the STABS we emit differ slightly from what ld64 does. First, we
emit the path to the source file as one `N_SO` symbol instead of two. (`ld64`
emits one `N_SO` for the dirname and one of the basename.) Second, we do not
emit `N_BNSYM` and `N_ENSYM` STABS to mark the start and end of functions,
because the `N_FUN` STABS already serve that purpose. @clayborg recommended
these changes based on his knowledge of what the debugging tools look for.
Additionally, this current implementation doesn't accurately reflect the size
of function symbols. It uses the size of their containing sectioins as a proxy,
but that is only accurate if `.subsections_with_symbols` is set, and if there
isn't an `N_ALT_ENTRY` in that particular subsection. I think we have two
options to solve this:
1. We can split up subsections by symbol even if `.subsections_with_symbols`
is not set, but include constraints to ensure those subsections retain
their order in the final output. This is `ld64`'s approach.
2. We could just add a `size` field to our `Symbol` class. This seems simpler,
and I'm more inclined toward it, but I'm not sure if there are use cases
that it doesn't handle well. As such I'm punting on the decision for now.
Reviewed By: clayborg
Differential Revision: https://reviews.llvm.org/D89257
2020-12-02 06:45:01 +08:00
|
|
|
std::vector<StabsEntry> stabs;
|
2020-12-02 06:45:09 +08:00
|
|
|
std::vector<SymtabEntry> localSymbols;
|
|
|
|
std::vector<SymtabEntry> externalSymbols;
|
|
|
|
std::vector<SymtabEntry> undefinedSymbols;
|
[lld-macho][reland] Add basic symbol table output
This diff implements basic support for writing a symbol table.
Attributes are loosely supported for extern symbols and not at all for
other types.
Initial version by Kellie Medlin <kelliem@fb.com>
Originally committed in a3d95a50ee33 and reverted in fbae153ca583 due to
UBSAN erroring over unaligned writes. That has been fixed in the
current diff with the following changes:
```
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -133,6 +133,9 @@ SymtabSection::SymtabSection(StringTableSection &stringTableSection)
: stringTableSection(stringTableSection) {
segname = segment_names::linkEdit;
name = section_names::symbolTable;
+ // TODO: When we introduce the SyntheticSections superclass, we should make
+ // all synthetic sections aligned to WordSize by default.
+ align = WordSize;
}
size_t SymtabSection::getSize() const {
diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp
--- a/lld/MachO/Writer.cpp
+++ b/lld/MachO/Writer.cpp
@@ -371,6 +371,7 @@ void Writer::assignAddresses(OutputSegment *seg) {
ArrayRef<InputSection *> sections = p.second;
for (InputSection *isec : sections) {
addr = alignTo(addr, isec->align);
+ // We must align the file offsets too to avoid misaligned writes of
+ // structs.
+ fileOff = alignTo(fileOff, isec->align);
isec->addr = addr;
addr += isec->getSize();
fileOff += isec->getFileSize();
@@ -396,6 +397,7 @@ void Writer::writeSections() {
uint64_t fileOff = seg->fileOff;
for (auto § : seg->getSections()) {
for (InputSection *isec : sect.second) {
+ fileOff = alignTo(fileOff, isec->align);
isec->writeTo(buf + fileOff);
fileOff += isec->getFileSize();
}
```
I don't think it's easy to write a test for alignment (that doesn't
involve brittly hard-coding file offsets), so there isn't one... but
UBSAN builds pass now.
Differential Revision: https://reviews.llvm.org/D79050
2020-04-29 07:58:19 +08:00
|
|
|
};
|
|
|
|
|
2021-04-03 06:46:18 +08:00
|
|
|
template <class LP> SymtabSection *makeSymtabSection(StringTableSection &);
|
|
|
|
|
2020-09-05 09:02:07 +08:00
|
|
|
// The indirect symbol table is a list of 32-bit integers that serve as indices
|
|
|
|
// into the (actual) symbol table. The indirect symbol table is a
|
2020-12-02 09:27:33 +08:00
|
|
|
// concatenation of several sub-arrays of indices, each sub-array belonging to
|
2020-09-05 09:02:07 +08:00
|
|
|
// a separate section. The starting offset of each sub-array is stored in the
|
|
|
|
// reserved1 header field of the respective section.
|
|
|
|
//
|
|
|
|
// These sub-arrays provide symbol information for sections that store
|
|
|
|
// contiguous sequences of symbol references. These references can be pointers
|
|
|
|
// (e.g. those in the GOT and TLVP sections) or assembly sequences (e.g.
|
|
|
|
// function stubs).
|
|
|
|
class IndirectSymtabSection : public LinkEditSection {
|
|
|
|
public:
|
|
|
|
IndirectSymtabSection();
|
2021-04-08 07:55:45 +08:00
|
|
|
void finalizeContents() override;
|
2020-09-05 09:02:07 +08:00
|
|
|
uint32_t getNumSymbols() const;
|
|
|
|
uint64_t getRawSize() const override {
|
|
|
|
return getNumSymbols() * sizeof(uint32_t);
|
|
|
|
}
|
|
|
|
bool isNeeded() const override;
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
};
|
|
|
|
|
2021-01-07 10:11:44 +08:00
|
|
|
// The code signature comes at the very end of the linked output file.
|
|
|
|
class CodeSignatureSection : public LinkEditSection {
|
|
|
|
public:
|
|
|
|
static constexpr uint8_t blockSizeShift = 12;
|
|
|
|
static constexpr size_t blockSize = (1 << blockSizeShift); // 4 KiB
|
|
|
|
static constexpr size_t hashSize = 256 / 8;
|
|
|
|
static constexpr size_t blobHeadersSize = llvm::alignTo<8>(
|
|
|
|
sizeof(llvm::MachO::CS_SuperBlob) + sizeof(llvm::MachO::CS_BlobIndex));
|
|
|
|
static constexpr uint32_t fixedHeadersSize =
|
|
|
|
blobHeadersSize + sizeof(llvm::MachO::CS_CodeDirectory);
|
|
|
|
|
|
|
|
uint32_t fileNamePad = 0;
|
|
|
|
uint32_t allHeadersSize = 0;
|
|
|
|
StringRef fileName;
|
|
|
|
|
|
|
|
CodeSignatureSection();
|
|
|
|
uint64_t getRawSize() const override;
|
|
|
|
bool isNeeded() const override { return true; }
|
|
|
|
void writeTo(uint8_t *buf) const override;
|
|
|
|
uint32_t getBlockCount() const;
|
|
|
|
void writeHashes(uint8_t *buf) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert((CodeSignatureSection::blobHeadersSize % 8) == 0, "");
|
|
|
|
static_assert((CodeSignatureSection::fixedHeadersSize % 8) == 0, "");
|
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
struct InStruct {
|
2020-07-31 05:28:41 +08:00
|
|
|
MachHeaderSection *header = nullptr;
|
2020-09-06 01:55:33 +08:00
|
|
|
RebaseSection *rebase = nullptr;
|
2020-07-03 12:19:55 +08:00
|
|
|
BindingSection *binding = nullptr;
|
2020-08-25 12:57:59 +08:00
|
|
|
WeakBindingSection *weakBinding = nullptr;
|
2020-08-28 06:54:42 +08:00
|
|
|
LazyBindingSection *lazyBinding = nullptr;
|
2020-08-28 06:59:15 +08:00
|
|
|
ExportSection *exports = nullptr;
|
2020-04-28 03:50:59 +08:00
|
|
|
GotSection *got = nullptr;
|
2020-08-13 10:50:09 +08:00
|
|
|
TlvPointerSection *tlvPointers = nullptr;
|
[lld-macho] Support calls to functions in dylibs
Summary:
This diff implements lazy symbol binding -- very similar to the PLT
mechanism in ELF.
ELF's .plt section is broken up into two sections in Mach-O:
StubsSection and StubHelperSection. Calls to functions in dylibs will
end up calling into StubsSection, which contains indirect jumps to
addresses stored in the LazyPointerSection (the counterpart to ELF's
.plt.got).
Initially, the LazyPointerSection contains addresses that point into one
of the entry points in the middle of the StubHelperSection. The code in
StubHelperSection will push on the stack an offset into the
LazyBindingSection. The push is followed by a jump to the beginning of
the StubHelperSection (similar to PLT0), which then calls into
dyld_stub_binder. dyld_stub_binder is a non-lazily bound symbol, so this
call looks it up in the GOT.
The stub binder will look up the bind opcodes in the LazyBindingSection
at the given offset. The bind opcodes will tell the binder to update the
address in the LazyPointerSection to point to the symbol, so that
subsequent calls don't have to redo the symbol resolution. The binder
will then jump to the resolved symbol.
Depends on D78269.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D78270
2020-05-06 08:38:10 +08:00
|
|
|
LazyPointerSection *lazyPointers = nullptr;
|
|
|
|
StubsSection *stubs = nullptr;
|
|
|
|
StubHelperSection *stubHelper = nullptr;
|
|
|
|
ImageLoaderCacheSection *imageLoaderCache = nullptr;
|
2020-04-22 04:37:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern InStruct in;
|
[lld-macho] Refactor segment/section creation, sorting, and merging
Summary:
There were a few issues with the previous setup:
1. The section sorting comparator used a declarative map of section names to
determine the correct order, but it turns out we need to match on more than
just names -- in particular, an upcoming diff will sort based on whether the
S_ZERO_FILL flag is set. This diff changes the sorter to a more imperative but
flexible form.
2. We were sorting OutputSections stored in a MapVector, which left the
MapVector in an inconsistent state -- the wrong keys map to the wrong values!
In practice, we weren't doing key lookups (only container iteration) after the
sort, so this was fine, but it was still a dubious state of affairs. This diff
copies the OutputSections to a vector before sorting them.
3. We were adding unneeded OutputSections to OutputSegments and then filtering
them out later, which meant that we had to remember whether an OutputSegment
was in a pre- or post-filtered state. This diff only adds the sections to the
segments if they are needed.
In addition to those major changes, two minor ones worth noting:
1. I renamed all OutputSection variable names to `osec`, to parallel `isec`.
Previously we were using some inconsistent combination of `osec`, `os`, and
`section`.
2. I added a check (and a test) for InputSections with names that clashed with
those of our synthetic OutputSections.
Reviewers: #lld-macho
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81887
2020-06-15 15:03:24 +08:00
|
|
|
extern std::vector<SyntheticSection *> syntheticSections;
|
2020-04-22 04:37:57 +08:00
|
|
|
|
2021-03-19 06:49:45 +08:00
|
|
|
void createSyntheticSymbols();
|
|
|
|
|
2020-04-22 04:37:57 +08:00
|
|
|
} // namespace macho
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|