[lld] r356102 - [WebAssembly] Improve support for "needed" list in dylink section
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 13 14:29:20 PDT 2019
Author: sbc
Date: Wed Mar 13 14:29:20 2019
New Revision: 356102
URL: http://llvm.org/viewvc/llvm-project?rev=356102&view=rev
Log:
[WebAssembly] Improve support for "needed" list in dylink section
This change adds basic support for shared library dependencies
via the dylink section.
See https://github.com/WebAssembly/tool-conventions/pull/77
Differential Revision: https://reviews.llvm.org/D59237
Added:
lld/trunk/test/wasm/shared-needed.ll
Modified:
lld/trunk/test/wasm/shared.ll
lld/trunk/wasm/InputFiles.cpp
lld/trunk/wasm/InputFiles.h
lld/trunk/wasm/SymbolTable.cpp
lld/trunk/wasm/SymbolTable.h
lld/trunk/wasm/Writer.cpp
Added: lld/trunk/test/wasm/shared-needed.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/shared-needed.ll?rev=356102&view=auto
==============================================================================
--- lld/trunk/test/wasm/shared-needed.ll (added)
+++ lld/trunk/test/wasm/shared-needed.ll Wed Mar 13 14:29:20 2019
@@ -0,0 +1,38 @@
+; RUN: llc -filetype=obj %s -o %t.o
+; RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
+
+; RUN: wasm-ld -shared -o %t1.so %t.o
+; RUN: obj2yaml %t1.so | FileCheck %s -check-prefix=SO1
+
+; RUN: wasm-ld -shared -o %t2.so %t1.so %t.ret32.o
+; RUN: obj2yaml %t2.so | FileCheck %s -check-prefix=SO2
+
+target triple = "wasm32-unknown-unknown"
+
+ at data = global i32 2, align 4
+
+define default void @foo() {
+entry:
+ ret void
+}
+
+; SO1: Sections:
+; SO1-NEXT: - Type: CUSTOM
+; SO1-NEXT: Name: dylink
+; SO1-NEXT: MemorySize: 4
+; SO1-NEXT: MemoryAlignment: 2
+; SO1-NEXT: TableSize: 0
+; SO1-NEXT: TableAlignment: 0
+; SO1-NEXT: Needed: []
+; SO1-NEXT: - Type: TYPE
+
+; SO2: Sections:
+; SO2-NEXT: - Type: CUSTOM
+; SO2-NEXT: Name: dylink
+; SO2-NEXT: MemorySize: 0
+; SO2-NEXT: MemoryAlignment: 0
+; SO2-NEXT: TableSize: 0
+; SO2-NEXT: TableAlignment: 0
+; SO2-NEXT: Needed:
+; SO2-NEXT: - shared-needed.ll.tmp1.so
+; SO2-NEXT: - Type: TYPE
Modified: lld/trunk/test/wasm/shared.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/shared.ll?rev=356102&r1=356101&r2=356102&view=diff
==============================================================================
--- lld/trunk/test/wasm/shared.ll (original)
+++ lld/trunk/test/wasm/shared.ll Wed Mar 13 14:29:20 2019
@@ -33,6 +33,8 @@ declare void @func_external()
; CHECK-NEXT: MemoryAlignment: 2
; CHECK-NEXT: TableSize: 2
; CHECK-NEXT: TableAlignment: 0
+; CHECK-NEXT: Needed: []
+; CHECK-NEXT: - Type: TYPE
; check for import of __table_base and __memory_base globals
Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=356102&r1=356101&r2=356102&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Wed Mar 13 14:29:20 2019
@@ -44,8 +44,13 @@ Optional<MemoryBufferRef> lld::wasm::rea
InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB) {
file_magic Magic = identify_magic(MB.getBuffer());
- if (Magic == file_magic::wasm_object)
+ if (Magic == file_magic::wasm_object) {
+ std::unique_ptr<Binary> Bin = check(createBinary(MB));
+ auto *Obj = cast<WasmObjectFile>(Bin.get());
+ if (Obj->isSharedObject())
+ return make<SharedFile>(MB);
return make<ObjFile>(MB);
+ }
if (Magic == file_magic::bitcode)
return make<BitcodeFile>(MB);
Modified: lld/trunk/wasm/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.h?rev=356102&r1=356101&r2=356102&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.h (original)
+++ lld/trunk/wasm/InputFiles.h Wed Mar 13 14:29:20 2019
@@ -33,6 +33,7 @@ class InputFile {
public:
enum Kind {
ObjectKind,
+ SharedKind,
ArchiveKind,
BitcodeKind,
};
@@ -129,6 +130,16 @@ private:
std::unique_ptr<WasmObjectFile> WasmObj;
};
+// .so file.
+class SharedFile : public InputFile {
+public:
+ explicit SharedFile(MemoryBufferRef M) : InputFile(SharedKind, M) {}
+ static bool classof(const InputFile *F) { return F->kind() == SharedKind; }
+
+ void parse() override {}
+};
+
+// .bc file
class BitcodeFile : public InputFile {
public:
explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {}
Modified: lld/trunk/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.cpp?rev=356102&r1=356101&r2=356102&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.cpp (original)
+++ lld/trunk/wasm/SymbolTable.cpp Wed Mar 13 14:29:20 2019
@@ -37,6 +37,8 @@ void SymbolTable::addFile(InputFile *Fil
BitcodeFiles.push_back(F);
else if (auto *F = dyn_cast<ObjFile>(File))
ObjectFiles.push_back(F);
+ else if (auto *F = dyn_cast<SharedFile>(File))
+ SharedFiles.push_back(F);
}
// This function is where all the optimizations of link-time
Modified: lld/trunk/wasm/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/SymbolTable.h?rev=356102&r1=356101&r2=356102&view=diff
==============================================================================
--- lld/trunk/wasm/SymbolTable.h (original)
+++ lld/trunk/wasm/SymbolTable.h Wed Mar 13 14:29:20 2019
@@ -39,6 +39,7 @@ public:
void addCombinedLTOObject();
std::vector<ObjFile *> ObjectFiles;
+ std::vector<InputFile *> SharedFiles;
std::vector<BitcodeFile *> BitcodeFiles;
std::vector<InputFunction *> SyntheticFunctions;
std::vector<InputGlobal *> SyntheticGlobals;
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=356102&r1=356101&r2=356102&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Wed Mar 13 14:29:20 2019
@@ -28,6 +28,7 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/LEB128.h"
+#include "llvm/Support/Path.h"
#include <cstdarg>
#include <map>
@@ -502,7 +503,9 @@ void Writer::createDylinkSection() {
writeUleb128(OS, MemAlign, "MemAlign");
writeUleb128(OS, IndirectFunctions.size(), "TableSize");
writeUleb128(OS, 0, "TableAlign");
- writeUleb128(OS, 0, "Needed"); // TODO: Support "needed" shared libraries
+ writeUleb128(OS, Symtab->SharedFiles.size(), "Needed");
+ for (auto *SO : Symtab->SharedFiles)
+ writeStr(OS, llvm::sys::path::filename(SO->getName()), "so name");
}
// Create the custom "linking" section containing linker metadata.
More information about the llvm-commits
mailing list