[lld] r372660 - [lld][WebAssembly] Preserve symbol flags in --relocatable output
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 23 14:28:29 PDT 2019
Author: sbc
Date: Mon Sep 23 14:28:29 2019
New Revision: 372660
URL: http://llvm.org/viewvc/llvm-project?rev=372660&view=rev
Log:
[lld][WebAssembly] Preserve symbol flags in --relocatable output
Fixes https://github.com/emscripten-core/emscripten/issues/8879
Differential Revision: https://reviews.llvm.org/D67729
Modified:
lld/trunk/test/wasm/relocatable.ll
lld/trunk/wasm/Driver.cpp
lld/trunk/wasm/InputFiles.cpp
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/SyntheticSections.cpp
Modified: lld/trunk/test/wasm/relocatable.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/relocatable.ll?rev=372660&r1=372659&r2=372660&view=diff
==============================================================================
--- lld/trunk/test/wasm/relocatable.ll (original)
+++ lld/trunk/test/wasm/relocatable.ll Mon Sep 23 14:28:29 2019
@@ -34,6 +34,9 @@ entry:
ret i32 ptrtoint ([3 x i8]* @data_comdat to i32)
}
+; Test that __attribute__(used) (i.e NO_STRIP) is preserved in the relocated symbol table
+ at llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @my_func to i8*)], section "llvm.metadata"
+
; CHECK: --- !WASM
; CHECK-NEXT: FileHeader:
; CHECK-NEXT: Version: 0x00000001
@@ -188,7 +191,7 @@ entry:
; NORMAL-NEXT: - Index: 3
; NORMAL-NEXT: Kind: FUNCTION
; NORMAL-NEXT: Name: my_func
-; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN ]
+; NORMAL-NEXT: Flags: [ VISIBILITY_HIDDEN, NO_STRIP ]
; NORMAL-NEXT: Function: 4
; NORMAL-NEXT: - Index: 4
; NORMAL-NEXT: Kind: FUNCTION
Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=372660&r1=372659&r2=372660&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Mon Sep 23 14:28:29 2019
@@ -441,10 +441,8 @@ static Symbol *handleUndefined(StringRef
static UndefinedGlobal *
createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) {
- auto *sym =
- cast<UndefinedGlobal>(symtab->addUndefinedGlobal(name, name,
- defaultModule, 0,
- nullptr, type));
+ auto *sym = cast<UndefinedGlobal>(symtab->addUndefinedGlobal(
+ name, name, defaultModule, WASM_SYMBOL_UNDEFINED, nullptr, type));
config->allowUndefinedSymbols.insert(sym->getName());
sym->isUsedInRegularObj = true;
return sym;
@@ -582,7 +580,8 @@ struct WrappedSymbol {
};
static Symbol *addUndefined(StringRef name) {
- return symtab->addUndefinedFunction(name, "", "", 0, nullptr, nullptr, false);
+ return symtab->addUndefinedFunction(name, "", "", WASM_SYMBOL_UNDEFINED,
+ nullptr, nullptr, false);
}
// Handles -wrap option.
Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=372660&r1=372659&r2=372660&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Mon Sep 23 14:28:29 2019
@@ -421,7 +421,7 @@ Symbol *ObjFile::createDefined(const Was
Symbol *ObjFile::createUndefined(const WasmSymbol &sym, bool isCalledDirectly) {
StringRef name = sym.Info.Name;
- uint32_t flags = sym.Info.Flags;
+ uint32_t flags = sym.Info.Flags | WASM_SYMBOL_UNDEFINED;
switch (sym.Info.Kind) {
case WASM_SYMBOL_TYPE_FUNCTION:
@@ -509,6 +509,7 @@ static Symbol *createBitcodeSymbol(const
bool excludedByComdat = c != -1 && !keptComdats[c];
if (objSym.isUndefined() || excludedByComdat) {
+ flags |= WASM_SYMBOL_UNDEFINED;
if (objSym.isExecutable())
return symtab->addUndefinedFunction(name, name, defaultModule, flags, &f,
nullptr, true);
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=372660&r1=372659&r2=372660&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Mon Sep 23 14:28:29 2019
@@ -401,6 +401,7 @@ Symbol *SymbolTable::addUndefinedFunctio
LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << name << " ["
<< (sig ? toString(*sig) : "none")
<< "] IsCalledDirectly:" << isCalledDirectly << "\n");
+ assert(flags & WASM_SYMBOL_UNDEFINED);
Symbol *s;
bool wasInserted;
@@ -443,6 +444,7 @@ Symbol *SymbolTable::addUndefinedFunctio
Symbol *SymbolTable::addUndefinedData(StringRef name, uint32_t flags,
InputFile *file) {
LLVM_DEBUG(dbgs() << "addUndefinedData: " << name << "\n");
+ assert(flags & WASM_SYMBOL_UNDEFINED);
Symbol *s;
bool wasInserted;
@@ -464,6 +466,7 @@ Symbol *SymbolTable::addUndefinedGlobal(
InputFile *file,
const WasmGlobalType *type) {
LLVM_DEBUG(dbgs() << "addUndefinedGlobal: " << name << "\n");
+ assert(flags & WASM_SYMBOL_UNDEFINED);
Symbol *s;
bool wasInserted;
Modified: lld/trunk/wasm/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SyntheticSections.cpp?rev=372660&r1=372659&r2=372660&view=diff
==============================================================================
--- lld/trunk/wasm/SyntheticSections.cpp (original)
+++ lld/trunk/wasm/SyntheticSections.cpp Mon Sep 23 14:28:29 2019
@@ -362,26 +362,6 @@ bool DataCountSection::isNeeded() const
return numSegments && config->sharedMemory;
}
-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;
- if (auto *f = dyn_cast<UndefinedFunction>(sym)) {
- if (f->getName() != f->importName)
- flags |= WASM_SYMBOL_EXPLICIT_NAME;
- } else if (auto *g = dyn_cast<UndefinedGlobal>(sym)) {
- if (g->getName() != g->importName)
- flags |= WASM_SYMBOL_EXPLICIT_NAME;
- }
- return flags;
-}
-
void LinkingSection::writeBody() {
raw_ostream &os = bodyOutputStream;
@@ -394,7 +374,7 @@ void LinkingSection::writeBody() {
for (const Symbol *sym : symtabEntries) {
assert(sym->isDefined() || sym->isUndefined());
WasmSymbolType kind = sym->getWasmType();
- uint32_t flags = getWasmFlags(sym);
+ uint32_t flags = sym->getFlags();
writeU8(sub.os, kind, "sym kind");
writeUleb128(sub.os, flags, "sym flags");
More information about the llvm-commits
mailing list