2020-04-02 11:54:05 -07:00
|
|
|
//===- InputSection.cpp ---------------------------------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "InputSection.h"
|
2020-04-27 12:50:59 -07:00
|
|
|
#include "OutputSegment.h"
|
2020-04-02 11:54:05 -07:00
|
|
|
#include "Symbols.h"
|
|
|
|
|
#include "Target.h"
|
|
|
|
|
#include "lld/Common/Memory.h"
|
|
|
|
|
#include "llvm/Support/Endian.h"
|
|
|
|
|
|
2020-05-18 15:46:33 -07:00
|
|
|
using namespace llvm;
|
2020-04-02 11:54:05 -07:00
|
|
|
using namespace llvm::MachO;
|
|
|
|
|
using namespace llvm::support;
|
|
|
|
|
using namespace lld;
|
|
|
|
|
using namespace lld::macho;
|
|
|
|
|
|
|
|
|
|
std::vector<InputSection *> macho::inputSections;
|
|
|
|
|
|
2020-04-27 12:50:59 -07:00
|
|
|
uint64_t InputSection::getFileOffset() const {
|
2020-05-01 16:29:06 -07:00
|
|
|
return parent->fileOff + outSecFileOff;
|
2020-04-27 12:50:59 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-01 16:29:06 -07:00
|
|
|
uint64_t InputSection::getVA() const { return parent->addr + outSecOff; }
|
|
|
|
|
|
2020-04-02 11:54:05 -07:00
|
|
|
void InputSection::writeTo(uint8_t *buf) {
|
2020-04-28 11:29:30 -07:00
|
|
|
if (!data.empty())
|
|
|
|
|
memcpy(buf, data.data(), data.size());
|
2020-04-02 11:54:05 -07:00
|
|
|
|
|
|
|
|
for (Reloc &r : relocs) {
|
|
|
|
|
uint64_t va = 0;
|
2020-06-13 20:00:06 -07:00
|
|
|
if (auto *s = r.target.dyn_cast<Symbol *>())
|
|
|
|
|
va = target->getSymbolVA(*s, r.type);
|
|
|
|
|
else if (auto *isec = r.target.dyn_cast<InputSection *>())
|
2020-05-01 16:29:06 -07:00
|
|
|
va = isec->getVA();
|
2020-04-02 11:54:05 -07:00
|
|
|
|
[lld-macho][re-land] Support .subsections_via_symbols
Summary:
This diff restores and builds upon @pcc and @ruiu's initial work on
subsections.
The .subsections_via_symbols directive indicates we can split each
section along symbol boundaries, unless those symbols have been marked
with `.alt_entry`.
We exercise this functionality in our tests by using order files that
rearrange those symbols.
Depends on D79668.
Reviewers: ruiu, pcc, MaskRay, smeenai, alexshap, gkm, Ktwu, christylee
Reviewed By: smeenai
Subscribers: thakis, llvm-commits, pcc, ruiu
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79926
2020-05-19 08:46:07 -07:00
|
|
|
uint64_t val = va + r.addend;
|
2020-05-19 08:53:53 -07:00
|
|
|
if (r.pcrel)
|
2020-05-01 16:29:06 -07:00
|
|
|
val -= getVA() + r.offset;
|
2020-06-13 19:52:20 -07:00
|
|
|
target->relocateOne(buf + r.offset, r, val);
|
2020-04-02 11:54:05 -07:00
|
|
|
}
|
|
|
|
|
}
|