2019-05-21 17:13:09 +08:00
|
|
|
//===- SyntheticSection.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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Synthetic sections represent chunks of linker-created data. If you
|
|
|
|
// need to create a chunk of data that to be included in some section
|
|
|
|
// in the result, you probably want to create that as a synthetic section.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_WASM_SYNTHETIC_SECTIONS_H
|
|
|
|
#define LLD_WASM_SYNTHETIC_SECTIONS_H
|
|
|
|
|
|
|
|
#include "OutputSections.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallSet.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
2020-09-29 04:06:34 +08:00
|
|
|
#include "llvm/BinaryFormat/WasmTraits.h"
|
2019-05-21 17:13:09 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "lld"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
|
|
|
|
|
|
// An init entry to be written to either the synthetic init func or the
|
|
|
|
// linking metadata.
|
|
|
|
struct WasmInitEntry {
|
|
|
|
const FunctionSymbol *sym;
|
|
|
|
uint32_t priority;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SyntheticSection : public OutputSection {
|
|
|
|
public:
|
|
|
|
SyntheticSection(uint32_t type, std::string name = "")
|
|
|
|
: OutputSection(type, name), bodyOutputStream(body) {
|
|
|
|
if (!name.empty())
|
|
|
|
writeStr(bodyOutputStream, name, "section name");
|
|
|
|
}
|
|
|
|
|
|
|
|
void writeTo(uint8_t *buf) override {
|
|
|
|
assert(offset);
|
|
|
|
log("writing " + toString(*this));
|
|
|
|
memcpy(buf + offset, header.data(), header.size());
|
|
|
|
memcpy(buf + offset + header.size(), body.data(), body.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getSize() const override { return header.size() + body.size(); }
|
|
|
|
|
|
|
|
virtual void writeBody() {}
|
|
|
|
|
2019-08-14 01:02:02 +08:00
|
|
|
virtual void assignIndexes() {}
|
|
|
|
|
2019-05-21 17:13:09 +08:00
|
|
|
void finalizeContents() override {
|
|
|
|
writeBody();
|
|
|
|
bodyOutputStream.flush();
|
|
|
|
createHeader(body.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
raw_ostream &getStream() { return bodyOutputStream; }
|
|
|
|
|
|
|
|
std::string body;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
llvm::raw_string_ostream bodyOutputStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create the custom "dylink" section containing information for the dynamic
|
|
|
|
// linker.
|
|
|
|
// See
|
|
|
|
// https://github.com/WebAssembly/tool-conventions/blob/master/DynamicLinking.md
|
|
|
|
class DylinkSection : public SyntheticSection {
|
|
|
|
public:
|
2021-09-10 19:21:28 +08:00
|
|
|
DylinkSection() : SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "dylink.0") {}
|
2019-05-21 17:13:09 +08:00
|
|
|
bool isNeeded() const override { return config->isPic; }
|
|
|
|
void writeBody() override;
|
|
|
|
|
|
|
|
uint32_t memAlign = 0;
|
|
|
|
uint32_t memSize = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TypeSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
TypeSection() : SyntheticSection(llvm::wasm::WASM_SEC_TYPE) {}
|
|
|
|
|
|
|
|
bool isNeeded() const override { return types.size() > 0; };
|
|
|
|
void writeBody() override;
|
|
|
|
uint32_t registerType(const WasmSignature &sig);
|
|
|
|
uint32_t lookupType(const WasmSignature &sig);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<const WasmSignature *> types;
|
|
|
|
llvm::DenseMap<WasmSignature, int32_t> typeIndices;
|
|
|
|
};
|
|
|
|
|
2021-07-23 05:12:50 +08:00
|
|
|
/**
|
|
|
|
* A key for some kind of imported entity of type `T`.
|
|
|
|
*
|
|
|
|
* Used when de-duplicating imports.
|
|
|
|
*/
|
|
|
|
template <typename T> struct ImportKey {
|
|
|
|
public:
|
|
|
|
enum class State { Plain, Empty, Tombstone };
|
|
|
|
|
|
|
|
public:
|
|
|
|
T type;
|
|
|
|
llvm::Optional<StringRef> importModule;
|
|
|
|
llvm::Optional<StringRef> importName;
|
|
|
|
State state;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ImportKey(T type) : type(type), state(State::Plain) {}
|
|
|
|
ImportKey(T type, State state) : type(type), state(state) {}
|
|
|
|
ImportKey(T type, llvm::Optional<StringRef> importModule,
|
|
|
|
llvm::Optional<StringRef> importName)
|
|
|
|
: type(type), importModule(importModule), importName(importName),
|
|
|
|
state(State::Plain) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline bool operator==(const ImportKey<T> &lhs, const ImportKey<T> &rhs) {
|
|
|
|
return lhs.state == rhs.state && lhs.importModule == rhs.importModule &&
|
|
|
|
lhs.importName == rhs.importName && lhs.type == rhs.type;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
// `ImportKey<T>` can be used as a key in a `DenseMap` if `T` can be used as a
|
|
|
|
// key in a `DenseMap`.
|
2021-08-09 13:50:26 +08:00
|
|
|
namespace llvm {
|
|
|
|
template <typename T> struct DenseMapInfo<lld::wasm::ImportKey<T>> {
|
2021-07-23 05:12:50 +08:00
|
|
|
static lld::wasm::ImportKey<T> getEmptyKey() {
|
|
|
|
typename lld::wasm::ImportKey<T> key(llvm::DenseMapInfo<T>::getEmptyKey());
|
|
|
|
key.state = lld::wasm::ImportKey<T>::State::Empty;
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
static lld::wasm::ImportKey<T> getTombstoneKey() {
|
|
|
|
typename lld::wasm::ImportKey<T> key(llvm::DenseMapInfo<T>::getEmptyKey());
|
|
|
|
key.state = lld::wasm::ImportKey<T>::State::Tombstone;
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
static unsigned getHashValue(const lld::wasm::ImportKey<T> &key) {
|
|
|
|
uintptr_t hash = hash_value(key.importModule);
|
|
|
|
hash = hash_combine(hash, key.importName);
|
|
|
|
hash = hash_combine(hash, llvm::DenseMapInfo<T>::getHashValue(key.type));
|
|
|
|
hash = hash_combine(hash, key.state);
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
static bool isEqual(const lld::wasm::ImportKey<T> &lhs,
|
|
|
|
const lld::wasm::ImportKey<T> &rhs) {
|
|
|
|
return lhs == rhs;
|
|
|
|
}
|
|
|
|
};
|
2021-08-09 13:50:26 +08:00
|
|
|
} // end namespace llvm
|
2021-07-23 05:12:50 +08:00
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
|
|
|
2019-05-21 17:13:09 +08:00
|
|
|
class ImportSection : public SyntheticSection {
|
|
|
|
public:
|
2021-01-14 17:15:56 +08:00
|
|
|
ImportSection() : SyntheticSection(llvm::wasm::WASM_SEC_IMPORT) {}
|
2019-07-10 17:10:01 +08:00
|
|
|
bool isNeeded() const override { return getNumImports() > 0; }
|
2019-05-21 17:13:09 +08:00
|
|
|
void writeBody() override;
|
|
|
|
void addImport(Symbol *sym);
|
|
|
|
void addGOTEntry(Symbol *sym);
|
2019-05-23 17:41:03 +08:00
|
|
|
void seal() { isSealed = true; }
|
2019-07-10 17:10:01 +08:00
|
|
|
uint32_t getNumImports() const;
|
|
|
|
uint32_t getNumImportedGlobals() const {
|
2019-05-23 17:41:03 +08:00
|
|
|
assert(isSealed);
|
|
|
|
return numImportedGlobals;
|
|
|
|
}
|
2019-07-10 17:10:01 +08:00
|
|
|
uint32_t getNumImportedFunctions() const {
|
2019-05-23 17:41:03 +08:00
|
|
|
assert(isSealed);
|
|
|
|
return numImportedFunctions;
|
|
|
|
}
|
2021-06-15 16:49:43 +08:00
|
|
|
uint32_t getNumImportedTags() const {
|
2019-05-23 17:41:03 +08:00
|
|
|
assert(isSealed);
|
2021-06-15 16:49:43 +08:00
|
|
|
return numImportedTags;
|
2019-05-23 17:41:03 +08:00
|
|
|
}
|
2021-01-05 19:08:58 +08:00
|
|
|
uint32_t getNumImportedTables() const {
|
|
|
|
assert(isSealed);
|
|
|
|
return numImportedTables;
|
|
|
|
}
|
2019-05-21 17:13:09 +08:00
|
|
|
|
|
|
|
std::vector<const Symbol *> importedSymbols;
|
2020-11-19 13:38:23 +08:00
|
|
|
std::vector<const Symbol *> gotSymbols;
|
2019-05-21 17:13:09 +08:00
|
|
|
|
|
|
|
protected:
|
2019-05-23 17:41:03 +08:00
|
|
|
bool isSealed = false;
|
|
|
|
unsigned numImportedGlobals = 0;
|
|
|
|
unsigned numImportedFunctions = 0;
|
2021-06-15 16:49:43 +08:00
|
|
|
unsigned numImportedTags = 0;
|
2021-01-05 19:08:58 +08:00
|
|
|
unsigned numImportedTables = 0;
|
2021-07-23 05:12:50 +08:00
|
|
|
llvm::DenseMap<ImportKey<WasmGlobalType>, uint32_t> importedGlobals;
|
|
|
|
llvm::DenseMap<ImportKey<WasmSignature>, uint32_t> importedFunctions;
|
|
|
|
llvm::DenseMap<ImportKey<WasmTableType>, uint32_t> importedTables;
|
2021-09-30 05:17:14 +08:00
|
|
|
llvm::DenseMap<ImportKey<WasmSignature>, uint32_t> importedTags;
|
2019-05-21 17:13:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class FunctionSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
FunctionSection() : SyntheticSection(llvm::wasm::WASM_SEC_FUNCTION) {}
|
|
|
|
|
|
|
|
bool isNeeded() const override { return inputFunctions.size() > 0; };
|
|
|
|
void writeBody() override;
|
|
|
|
void addFunction(InputFunction *func);
|
|
|
|
|
|
|
|
std::vector<InputFunction *> inputFunctions;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
};
|
|
|
|
|
|
|
|
class TableSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
TableSection() : SyntheticSection(llvm::wasm::WASM_SEC_TABLE) {}
|
|
|
|
|
2021-01-14 17:15:56 +08:00
|
|
|
bool isNeeded() const override { return inputTables.size() > 0; };
|
2021-02-13 03:01:41 +08:00
|
|
|
void assignIndexes() override;
|
2019-05-21 17:13:09 +08:00
|
|
|
void writeBody() override;
|
2021-01-05 19:08:58 +08:00
|
|
|
void addTable(InputTable *table);
|
|
|
|
|
|
|
|
std::vector<InputTable *> inputTables;
|
2019-05-21 17:13:09 +08:00
|
|
|
};
|
|
|
|
|
2020-03-25 10:36:13 +08:00
|
|
|
class MemorySection : public SyntheticSection {
|
2019-05-21 17:13:09 +08:00
|
|
|
public:
|
2020-03-25 10:36:13 +08:00
|
|
|
MemorySection() : SyntheticSection(llvm::wasm::WASM_SEC_MEMORY) {}
|
2019-09-25 04:52:12 +08:00
|
|
|
|
2020-03-25 10:36:13 +08:00
|
|
|
bool isNeeded() const override { return !config->importMemory; }
|
|
|
|
void writeBody() override;
|
2019-05-21 17:13:09 +08:00
|
|
|
|
2020-06-30 08:53:09 +08:00
|
|
|
uint64_t numMemoryPages = 0;
|
|
|
|
uint64_t maxMemoryPages = 0;
|
2019-05-21 17:13:09 +08:00
|
|
|
};
|
|
|
|
|
2021-06-15 16:49:43 +08:00
|
|
|
// The tag section contains a list of declared wasm tags associated with the
|
|
|
|
// module. Currently the only supported tag kind is exceptions. All C++
|
|
|
|
// exceptions are represented by a single tag. A tag entry in this section
|
|
|
|
// contains information on what kind of tag it is (e.g. exception) and the type
|
|
|
|
// of values associated with the tag. (In Wasm, a tag can contain multiple
|
|
|
|
// values of primitive types. But for C++ exceptions, we just throw a pointer
|
|
|
|
// which is an i32 value (for wasm32 architecture), so the signature of C++
|
|
|
|
// exception is (i32)->(void), because all exception tag types are assumed to
|
|
|
|
// have void return type to share WasmSignature with functions.)
|
|
|
|
class TagSection : public SyntheticSection {
|
2019-05-21 17:13:09 +08:00
|
|
|
public:
|
2021-06-15 16:49:43 +08:00
|
|
|
TagSection() : SyntheticSection(llvm::wasm::WASM_SEC_TAG) {}
|
2019-05-21 17:13:09 +08:00
|
|
|
void writeBody() override;
|
2021-06-15 16:49:43 +08:00
|
|
|
bool isNeeded() const override { return inputTags.size() > 0; }
|
|
|
|
void addTag(InputTag *tag);
|
2019-05-21 17:13:09 +08:00
|
|
|
|
2021-06-15 16:49:43 +08:00
|
|
|
std::vector<InputTag *> inputTags;
|
2019-05-21 17:13:09 +08:00
|
|
|
};
|
|
|
|
|
2020-03-25 10:36:13 +08:00
|
|
|
class GlobalSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
GlobalSection() : SyntheticSection(llvm::wasm::WASM_SEC_GLOBAL) {}
|
2021-02-10 06:42:43 +08:00
|
|
|
|
|
|
|
static bool classof(const OutputSection *sec) {
|
|
|
|
return sec->type == llvm::wasm::WASM_SEC_GLOBAL;
|
|
|
|
}
|
|
|
|
|
2020-03-25 10:36:13 +08:00
|
|
|
uint32_t numGlobals() const {
|
|
|
|
assert(isSealed);
|
|
|
|
return inputGlobals.size() + dataAddressGlobals.size() +
|
2020-10-08 05:48:37 +08:00
|
|
|
internalGotSymbols.size();
|
2020-03-25 10:36:13 +08:00
|
|
|
}
|
|
|
|
bool isNeeded() const override { return numGlobals() > 0; }
|
|
|
|
void assignIndexes() override;
|
|
|
|
void writeBody() override;
|
|
|
|
void addGlobal(InputGlobal *global);
|
2020-10-08 05:48:37 +08:00
|
|
|
|
|
|
|
// Add an internal GOT entry global that corresponds to the given symbol.
|
|
|
|
// Normally GOT entries are imported and assigned by the external dynamic
|
|
|
|
// linker. However, when linking PIC code statically or when linking with
|
|
|
|
// -Bsymbolic we can internalize GOT entries by declaring globals the hold
|
|
|
|
// symbol addresses.
|
|
|
|
//
|
|
|
|
// For the static linking case these internal globals can be completely
|
|
|
|
// eliminated by a post-link optimizer such as wasm-opt.
|
|
|
|
//
|
|
|
|
// TODO(sbc): Another approach to optimizing these away could be to use
|
|
|
|
// specific relocation types combined with linker relaxation which could
|
|
|
|
// transform a `global.get` to an `i32.const`.
|
|
|
|
void addInternalGOTEntry(Symbol *sym);
|
2021-10-30 00:58:56 +08:00
|
|
|
bool needsRelocations() {
|
|
|
|
return llvm::find_if(internalGotSymbols, [=](Symbol *sym) {
|
|
|
|
return !sym->isTLS();
|
|
|
|
}) != internalGotSymbols.end();
|
|
|
|
}
|
|
|
|
bool needsTLSRelocations() {
|
|
|
|
return llvm::find_if(internalGotSymbols, [=](Symbol *sym) {
|
|
|
|
return sym->isTLS();
|
|
|
|
}) != internalGotSymbols.end();
|
|
|
|
}
|
2021-08-27 03:29:32 +08:00
|
|
|
void generateRelocationCode(raw_ostream &os, bool TLS) const;
|
2020-03-25 10:36:13 +08:00
|
|
|
|
2021-08-27 03:29:32 +08:00
|
|
|
std::vector<DefinedData *> dataAddressGlobals;
|
2020-11-19 13:38:23 +08:00
|
|
|
std::vector<InputGlobal *> inputGlobals;
|
|
|
|
std::vector<Symbol *> internalGotSymbols;
|
2020-03-25 10:36:13 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isSealed = false;
|
|
|
|
};
|
|
|
|
|
2019-05-21 17:13:09 +08:00
|
|
|
class ExportSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
ExportSection() : SyntheticSection(llvm::wasm::WASM_SEC_EXPORT) {}
|
|
|
|
bool isNeeded() const override { return exports.size() > 0; }
|
|
|
|
void writeBody() override;
|
|
|
|
|
|
|
|
std::vector<llvm::wasm::WasmExport> exports;
|
2020-09-15 09:28:26 +08:00
|
|
|
std::vector<const Symbol *> exportedSymbols;
|
2019-05-21 17:13:09 +08:00
|
|
|
};
|
|
|
|
|
2019-09-05 03:50:39 +08:00
|
|
|
class StartSection : public SyntheticSection {
|
|
|
|
public:
|
2020-12-10 23:40:48 +08:00
|
|
|
StartSection() : SyntheticSection(llvm::wasm::WASM_SEC_START) {}
|
2019-09-05 03:50:39 +08:00
|
|
|
bool isNeeded() const override;
|
|
|
|
void writeBody() override;
|
|
|
|
};
|
|
|
|
|
2019-05-21 17:13:09 +08:00
|
|
|
class ElemSection : public SyntheticSection {
|
|
|
|
public:
|
2019-08-27 12:19:34 +08:00
|
|
|
ElemSection()
|
|
|
|
: SyntheticSection(llvm::wasm::WASM_SEC_ELEM) {}
|
2019-05-21 17:13:09 +08:00
|
|
|
bool isNeeded() const override { return indirectFunctions.size() > 0; };
|
|
|
|
void writeBody() override;
|
|
|
|
void addEntry(FunctionSymbol *sym);
|
|
|
|
uint32_t numEntries() const { return indirectFunctions.size(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<const FunctionSymbol *> indirectFunctions;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataCountSection : public SyntheticSection {
|
|
|
|
public:
|
2019-10-16 03:05:11 +08:00
|
|
|
DataCountSection(ArrayRef<OutputSegment *> segments);
|
2019-05-21 17:13:09 +08:00
|
|
|
bool isNeeded() const override;
|
|
|
|
void writeBody() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t numSegments;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create the custom "linking" section containing linker metadata.
|
|
|
|
// This is only created when relocatable output is requested.
|
|
|
|
class LinkingSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
LinkingSection(const std::vector<WasmInitEntry> &initFunctions,
|
|
|
|
const std::vector<OutputSegment *> &dataSegments)
|
|
|
|
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "linking"),
|
|
|
|
initFunctions(initFunctions), dataSegments(dataSegments) {}
|
2019-05-24 21:28:27 +08:00
|
|
|
bool isNeeded() const override {
|
|
|
|
return config->relocatable || config->emitRelocs;
|
|
|
|
}
|
2019-05-21 17:13:09 +08:00
|
|
|
void writeBody() override;
|
|
|
|
void addToSymtab(Symbol *sym);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<const Symbol *> symtabEntries;
|
|
|
|
llvm::StringMap<uint32_t> sectionSymbolIndices;
|
|
|
|
const std::vector<WasmInitEntry> &initFunctions;
|
|
|
|
const std::vector<OutputSegment *> &dataSegments;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create the custom "name" section containing debug symbol names.
|
|
|
|
class NameSection : public SyntheticSection {
|
|
|
|
public:
|
2020-12-09 13:47:19 +08:00
|
|
|
NameSection(ArrayRef<OutputSegment *> segments)
|
|
|
|
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "name"),
|
|
|
|
segments(segments) {}
|
2021-07-24 07:57:37 +08:00
|
|
|
bool isNeeded() const override { return !config->stripAll && numNames() > 0; }
|
2019-05-21 17:13:09 +08:00
|
|
|
void writeBody() override;
|
2020-11-19 13:38:23 +08:00
|
|
|
unsigned numNames() const { return numNamedGlobals() + numNamedFunctions(); }
|
|
|
|
unsigned numNamedGlobals() const;
|
|
|
|
unsigned numNamedFunctions() const;
|
2020-12-09 13:47:19 +08:00
|
|
|
unsigned numNamedDataSegments() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ArrayRef<OutputSegment *> segments;
|
2019-05-21 17:13:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ProducersSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
ProducersSection()
|
|
|
|
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "producers") {}
|
|
|
|
bool isNeeded() const override {
|
|
|
|
return !config->stripAll && fieldCount() > 0;
|
|
|
|
}
|
|
|
|
void writeBody() override;
|
|
|
|
void addInfo(const llvm::wasm::WasmProducerInfo &info);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int fieldCount() const {
|
|
|
|
return int(!languages.empty()) + int(!tools.empty()) + int(!sDKs.empty());
|
|
|
|
}
|
|
|
|
SmallVector<std::pair<std::string, std::string>, 8> languages;
|
|
|
|
SmallVector<std::pair<std::string, std::string>, 8> tools;
|
|
|
|
SmallVector<std::pair<std::string, std::string>, 8> sDKs;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TargetFeaturesSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
TargetFeaturesSection()
|
|
|
|
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "target_features") {}
|
|
|
|
bool isNeeded() const override {
|
|
|
|
return !config->stripAll && features.size() > 0;
|
|
|
|
}
|
|
|
|
void writeBody() override;
|
|
|
|
|
|
|
|
llvm::SmallSet<std::string, 8> features;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RelocSection : public SyntheticSection {
|
|
|
|
public:
|
|
|
|
RelocSection(StringRef name, OutputSection *sec)
|
2020-01-29 03:23:46 +08:00
|
|
|
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, std::string(name)),
|
|
|
|
sec(sec) {}
|
2019-05-21 17:13:09 +08:00
|
|
|
void writeBody() override;
|
2019-07-10 17:10:01 +08:00
|
|
|
bool isNeeded() const override { return sec->getNumRelocations() > 0; };
|
2019-05-21 17:13:09 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
OutputSection *sec;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Linker generated output sections
|
|
|
|
struct OutStruct {
|
|
|
|
DylinkSection *dylinkSec;
|
|
|
|
TypeSection *typeSec;
|
|
|
|
FunctionSection *functionSec;
|
|
|
|
ImportSection *importSec;
|
|
|
|
TableSection *tableSec;
|
|
|
|
MemorySection *memorySec;
|
|
|
|
GlobalSection *globalSec;
|
2021-06-15 16:49:43 +08:00
|
|
|
TagSection *tagSec;
|
2019-05-21 17:13:09 +08:00
|
|
|
ExportSection *exportSec;
|
2019-09-05 03:50:39 +08:00
|
|
|
StartSection *startSec;
|
2019-05-21 17:13:09 +08:00
|
|
|
ElemSection *elemSec;
|
|
|
|
DataCountSection *dataCountSec;
|
|
|
|
LinkingSection *linkingSec;
|
|
|
|
NameSection *nameSec;
|
|
|
|
ProducersSection *producersSec;
|
|
|
|
TargetFeaturesSection *targetFeaturesSec;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern OutStruct out;
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|