[PATCH] D59237: [WebAssembly] Improve support for "needed" list in dylink section

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 17:05:38 PDT 2019


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.

This change adds basic support for shared library dependencies
via the dylink section.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D59237

Files:
  test/wasm/shared-needed.ll
  wasm/InputFiles.cpp
  wasm/InputFiles.h
  wasm/SymbolTable.h


Index: wasm/SymbolTable.h
===================================================================
--- wasm/SymbolTable.h
+++ wasm/SymbolTable.h
@@ -39,6 +39,7 @@
   void addCombinedLTOObject();
 
   std::vector<ObjFile *> ObjectFiles;
+  std::vector<InputFile *> SharedFiles;
   std::vector<BitcodeFile *> BitcodeFiles;
   std::vector<InputFunction *> SyntheticFunctions;
   std::vector<InputGlobal *> SyntheticGlobals;
Index: wasm/InputFiles.h
===================================================================
--- wasm/InputFiles.h
+++ wasm/InputFiles.h
@@ -33,6 +33,7 @@
 public:
   enum Kind {
     ObjectKind,
+    SharedKind,
     ArchiveKind,
     BitcodeKind,
   };
@@ -129,6 +130,16 @@
   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) {}
Index: wasm/InputFiles.cpp
===================================================================
--- wasm/InputFiles.cpp
+++ wasm/InputFiles.cpp
@@ -44,8 +44,14 @@
 
 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 = dyn_cast<WasmObjectFile>(Bin.get());
+    assert(Obj);
+    if (Obj->isSharedObject())
+      return make<SharedFile>(MB);
     return make<ObjFile>(MB);
+  }
 
   if (Magic == file_magic::bitcode)
     return make<BitcodeFile>(MB);
Index: test/wasm/shared-needed.ll
===================================================================
--- /dev/null
+++ test/wasm/shared-needed.ll
@@ -0,0 +1,21 @@
+; RUN: llc -O0 -filetype=obj %s -o %t.o
+; RUN: wasm-ld -shared -o %t.so %t.o
+; RUN: obj2yaml %t.so | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+ at data = global i32 2, align 4
+
+define default void @foo() {
+entry:
+  ret void
+}
+
+; CHECK:      Sections:
+; CHECK-NEXT:   - Type:            CUSTOM
+; CHECK-NEXT:     Name:            dylink
+; CHECK-NEXT:     MemorySize:      4
+; CHECK-NEXT:     MemoryAlignment: 2
+; CHECK-NEXT:     TableSize:       0
+; CHECK-NEXT:     TableAlignment:  0
+; CHECK-NEXT:     Needed:          []


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59237.190187.patch
Type: text/x-patch
Size: 2518 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190312/0ecbb4c8/attachment.bin>


More information about the llvm-commits mailing list