Previously, it was difficult to write code that handled both synthetic and regular sections generically. We solve this problem by creating a fake InputSection at the start of every SyntheticSection. This refactor allows us to handle DSOHandle like a regular Defined symbol (since Defined symbols must be attached to an InputSection), and paves the way for supporting `__mh_*header` symbols. Additionally, it simplifies our binding/rebase code. I did have to extend Defined a little -- it now has a `linkerInternal` flag, to indicate that `___dso_handle` should not be in the final symbol table. I've also added some additional testing for `___dso_handle`. Reviewed By: #lld-macho, oontvoo Differential Revision: https://reviews.llvm.org/D98545
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
//===- Symbols.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 "Symbols.h"
|
|
#include "InputFiles.h"
|
|
#include "SyntheticSections.h"
|
|
|
|
using namespace llvm;
|
|
using namespace lld;
|
|
using namespace lld::macho;
|
|
|
|
// Returns a symbol for an error message.
|
|
static std::string demangle(StringRef symName) {
|
|
if (config->demangle)
|
|
return demangleItanium(symName);
|
|
return std::string(symName);
|
|
}
|
|
|
|
std::string lld::toString(const Symbol &sym) {
|
|
return demangle(sym.getName());
|
|
}
|
|
|
|
std::string lld::toMachOString(const object::Archive::Symbol &b) {
|
|
return demangle(b.getName());
|
|
}
|
|
|
|
uint64_t Defined::getVA() const {
|
|
if (isAbsolute())
|
|
return value;
|
|
return isec->getVA() + value;
|
|
}
|
|
|
|
uint64_t Defined::getFileOffset() const {
|
|
if (isAbsolute()) {
|
|
error("absolute symbol " + toString(*this) +
|
|
" does not have a file offset");
|
|
return 0;
|
|
}
|
|
return isec->getFileOffset() + value;
|
|
}
|
|
|
|
void LazySymbol::fetchArchiveMember() { getFile()->fetch(sym); }
|