2021-02-11 19:15:24 +08:00
|
|
|
//===- InputElement.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_WASM_INPUT_ELEMENT_H
|
|
|
|
#define LLD_WASM_INPUT_ELEMENT_H
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
#include "InputFiles.h"
|
|
|
|
#include "WriterUtils.h"
|
|
|
|
#include "lld/Common/LLVM.h"
|
|
|
|
#include "llvm/Object/Wasm.h"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
namespace wasm {
|
|
|
|
|
2021-06-15 16:49:43 +08:00
|
|
|
// Represents a single element (Global, Tag, Table, etc) within an input
|
2021-02-11 19:15:24 +08:00
|
|
|
// file.
|
|
|
|
class InputElement {
|
|
|
|
protected:
|
|
|
|
InputElement(StringRef name, ObjFile *f)
|
|
|
|
: file(f), live(!config->gcSections), name(name) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
StringRef getName() const { return name; }
|
|
|
|
uint32_t getAssignedIndex() const { return assignedIndex.getValue(); }
|
|
|
|
bool hasAssignedIndex() const { return assignedIndex.hasValue(); }
|
|
|
|
void assignIndex(uint32_t index) {
|
|
|
|
assert(!hasAssignedIndex());
|
|
|
|
assignedIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjFile *file;
|
|
|
|
bool live = false;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
StringRef name;
|
|
|
|
llvm::Optional<uint32_t> assignedIndex;
|
|
|
|
};
|
|
|
|
|
2021-04-23 07:54:58 +08:00
|
|
|
inline WasmInitExpr intConst(uint64_t value, bool is64) {
|
|
|
|
WasmInitExpr ie;
|
|
|
|
if (is64) {
|
|
|
|
ie.Opcode = llvm::wasm::WASM_OPCODE_I64_CONST;
|
|
|
|
ie.Value.Int64 = static_cast<int64_t>(value);
|
|
|
|
} else {
|
|
|
|
ie.Opcode = llvm::wasm::WASM_OPCODE_I32_CONST;
|
|
|
|
ie.Value.Int32 = static_cast<int32_t>(value);
|
|
|
|
}
|
|
|
|
return ie;
|
|
|
|
}
|
|
|
|
|
2021-02-11 19:15:24 +08:00
|
|
|
class InputGlobal : public InputElement {
|
|
|
|
public:
|
|
|
|
InputGlobal(const WasmGlobal &g, ObjFile *f)
|
|
|
|
: InputElement(g.SymbolName, f), type(g.Type), initExpr(g.InitExpr) {}
|
|
|
|
|
|
|
|
const WasmGlobalType &getType() const { return type; }
|
|
|
|
const WasmInitExpr &getInitExpr() const { return initExpr; }
|
|
|
|
|
|
|
|
void setPointerValue(uint64_t value) {
|
2021-04-23 07:54:58 +08:00
|
|
|
initExpr = intConst(value, config->is64.getValueOr(false));
|
2021-02-11 19:15:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
WasmGlobalType type;
|
|
|
|
WasmInitExpr initExpr;
|
|
|
|
};
|
|
|
|
|
2021-06-15 16:49:43 +08:00
|
|
|
class InputTag : public InputElement {
|
2021-02-11 19:15:24 +08:00
|
|
|
public:
|
2021-06-15 16:49:43 +08:00
|
|
|
InputTag(const WasmSignature &s, const WasmTag &t, ObjFile *f)
|
[WebAssembly] Remove WasmTagType
This removes `WasmTagType`. `WasmTagType` contained an attribute and a
signature index:
```
struct WasmTagType {
uint8_t Attribute;
uint32_t SigIndex;
};
```
Currently the attribute field is not used and reserved for future use,
and always 0. And that this class contains `SigIndex` as its property is
a little weird in the place, because the tag type's signature index is
not an inherent property of a tag but rather a reference to another
section that changes after linking. This makes tag handling in the
linker also weird that tag-related methods are taking both `WasmTagType`
and `WasmSignature` even though `WasmTagType` contains a signature
index. This is because the signature index changes in linking so it
doesn't have any info at this point. This instead moves `SigIndex` to
`struct WasmTag` itself, as we did for `struct WasmFunction` in D111104.
In this CL, in lib/MC and lib/Object, this now treats tag types in the
same way as function types. Also in YAML, this removes `struct Tag`,
because now it only contains the tag index. Also tags set `SigIndex` in
`WasmImport` union, as functions do.
I think this makes things simpler and makes tag handling more in line
with function handling. These two shares similar properties in that both
of them have signatures, but they are kind of nominal so having the same
signature doesn't mean they are the same element.
Also a drive-by fix: the reserved 'attirubute' part's encoding changed
from uleb32 to uint8 a while ago. This was fixed in lib/MC and
lib/Object but not in YAML. This doesn't change object files because the
field's value is always 0 and its encoding is the same for the both
encoding.
This is effectively NFC; I didn't mark it as such just because it
changed YAML test results.
Reviewed By: sbc100, tlively
Differential Revision: https://reviews.llvm.org/D111086
2021-10-02 10:07:41 +08:00
|
|
|
: InputElement(t.SymbolName, f), signature(s) {}
|
2021-02-11 19:15:24 +08:00
|
|
|
|
|
|
|
const WasmSignature &signature;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InputTable : public InputElement {
|
|
|
|
public:
|
|
|
|
InputTable(const WasmTable &t, ObjFile *f)
|
|
|
|
: InputElement(t.SymbolName, f), type(t.Type) {}
|
|
|
|
|
|
|
|
const WasmTableType &getType() const { return type; }
|
|
|
|
void setLimits(const WasmLimits &limits) { type.Limits = limits; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
WasmTableType type;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace wasm
|
|
|
|
|
|
|
|
inline std::string toString(const wasm::InputElement *d) {
|
|
|
|
return (toString(d->file) + ":(" + d->getName() + ")").str();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif // LLD_WASM_INPUT_ELEMENT_H
|