[lld] r326279 - [WebAssembly] Simplify createLikingSection.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 16:28:07 PST 2018
Author: ruiu
Date: Tue Feb 27 16:28:07 2018
New Revision: 326279
URL: http://llvm.org/viewvc/llvm-project?rev=326279&view=rev
Log:
[WebAssembly] Simplify createLikingSection.
Summary: [WebAssembly] Simplify createLikingSection.
Reviewers: sbc100
Subscribers: jfb, dschuff, jgravelle-google, aheejin, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D43715
Modified:
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=326279&r1=326278&r2=326279&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Tue Feb 27 16:28:07 2018
@@ -371,6 +371,19 @@ void Writer::createRelocSections() {
}
}
+static uint32_t getWasmFlags(const Symbol *Sym) {
+ uint32_t Flags = 0;
+ if (Sym->isLocal())
+ Flags |= WASM_SYMBOL_BINDING_LOCAL;
+ if (Sym->isWeak())
+ Flags |= WASM_SYMBOL_BINDING_WEAK;
+ if (Sym->isHidden())
+ Flags |= WASM_SYMBOL_VISIBILITY_HIDDEN;
+ if (Sym->isUndefined())
+ Flags |= WASM_SYMBOL_UNDEFINED;
+ return Flags;
+}
+
// Create the custom "linking" section containing linker metadata.
// This is only created when relocatable output is requested.
void Writer::createLinkingSection() {
@@ -387,15 +400,11 @@ void Writer::createLinkingSection() {
for (const Symbol *Sym : SymtabEntries) {
assert(Sym->isDefined() || Sym->isUndefined());
WasmSymbolType Kind = Sym->getWasmType();
- uint32_t Flags = Sym->isLocal() ? WASM_SYMBOL_BINDING_LOCAL : 0;
- if (Sym->isWeak())
- Flags |= WASM_SYMBOL_BINDING_WEAK;
- if (Sym->isHidden())
- Flags |= WASM_SYMBOL_VISIBILITY_HIDDEN;
- if (Sym->isUndefined())
- Flags |= WASM_SYMBOL_UNDEFINED;
+ uint32_t Flags = getWasmFlags(Sym);
+
writeUleb128(SubSection.getStream(), Kind, "sym kind");
writeUleb128(SubSection.getStream(), Flags, "sym flags");
+
switch (Kind) {
case llvm::wasm::WASM_SYMBOL_TYPE_FUNCTION:
case llvm::wasm::WASM_SYMBOL_TYPE_GLOBAL:
@@ -415,6 +424,7 @@ void Writer::createLinkingSection() {
break;
}
}
+
SubSection.finalizeContents();
SubSection.writeToStream(OS);
}
More information about the llvm-commits
mailing list