[lld] r357737 - [WebAssembly] Include function in wasm table when used in R_WASM_TABLE_INDEX_REL_SLEB

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 4 17:35:12 PDT 2019


Author: sbc
Date: Thu Apr  4 17:35:12 2019
New Revision: 357737

URL: http://llvm.org/viewvc/llvm-project?rev=357737&view=rev
Log:
[WebAssembly] Include function in wasm table when used in R_WASM_TABLE_INDEX_REL_SLEB

This should have been part of rL357710 but was overlooked because
in our test code the function in question was also used in other
relocations that caused it to be added to the table anyway.

Differential Revision: https://reviews.llvm.org/D60296

Modified:
    lld/trunk/test/wasm/shared.ll
    lld/trunk/wasm/Writer.cpp

Modified: lld/trunk/test/wasm/shared.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/shared.ll?rev=357737&r1=357736&r2=357737&view=diff
==============================================================================
--- lld/trunk/test/wasm/shared.ll (original)
+++ lld/trunk/test/wasm/shared.ll Thu Apr  4 17:35:12 2019
@@ -32,6 +32,13 @@ entry:
   ret i8* bitcast (void ()* @func_external to i8*)
 }
 
+define default i8* @get_local_func_address() {
+entry:
+  ; Verify that a function which is otherwise not address taken *is* added to
+  ; the wasm table with referenced via R_WASM_TABLE_INDEX_REL_SLEB
+  ret i8* bitcast (i8* ()* @get_func_address to i8*)
+}
+
 declare void @func_external()
 
 ; check for dylink section at start
@@ -41,7 +48,7 @@ declare void @func_external()
 ; CHECK-NEXT:     Name:            dylink
 ; CHECK-NEXT:     MemorySize:      20
 ; CHECK-NEXT:     MemoryAlignment: 2
-; CHECK-NEXT:     TableSize:       2
+; CHECK-NEXT:     TableSize:       3
 ; CHECK-NEXT:     TableAlignment:  0
 ; CHECK-NEXT:     Needed:          []
 ; CHECK-NEXT:   - Type:            TYPE
@@ -61,7 +68,7 @@ declare void @func_external()
 ; CHECK-NEXT:         Table:
 ; CHECK-NEXT:           ElemType:        FUNCREF
 ; CHECK-NEXT:           Limits:
-; CHECK-NEXT:             Initial:         0x00000002
+; CHECK-NEXT:             Initial:         0x00000003
 ; CHECK-NEXT:       - Module:          env
 ; CHECK-NEXT:         Field:           __stack_pointer
 ; CHECK-NEXT:         Kind:            GLOBAL
@@ -106,7 +113,7 @@ declare void @func_external()
 ; CHECK-NEXT:       - Offset:
 ; CHECK-NEXT:           Opcode:          GLOBAL_GET
 ; CHECK-NEXT:           Index:           2
-; CHECK-NEXT:         Functions:       [ 3, 0 ]
+; CHECK-NEXT:         Functions:       [ 5, 3, 0 ]
 
 ; check the generated code in __wasm_call_ctors and __wasm_apply_relocs functions
 ; TODO(sbc): Disassemble and verify instructions.
@@ -118,7 +125,7 @@ declare void @func_external()
 ; CHECK-NEXT:         Body:            10020B
 ; CHECK-NEXT:       - Index:           2
 ; CHECK-NEXT:         Locals:          []
-; CHECK-NEXT:         Body:            230141046A230241006A360200230141086A230241016A3602002301410C6A230141006A360200230141106A23033602000B
+; CHECK-NEXT:         Body:            230141046A230241016A360200230141086A230241026A3602002301410C6A230141006A360200230141106A23033602000B
 
 ; check the data segment initialized with __memory_base global as offset
 
@@ -129,4 +136,4 @@ declare void @func_external()
 ; CHECK-NEXT:         Offset:
 ; CHECK-NEXT:           Opcode:          GLOBAL_GET
 ; CHECK-NEXT:           Index:           1
-; CHECK-NEXT:         Content:         '0200000000000000010000000000000000000000'
+; CHECK-NEXT:         Content:         '0200000001000000020000000000000000000000'

Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=357737&r1=357736&r2=357737&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Thu Apr  4 17:35:12 2019
@@ -1138,7 +1138,8 @@ void Writer::processRelocations(InputChu
   for (const WasmRelocation &Reloc : Chunk->getRelocations()) {
     switch (Reloc.Type) {
     case R_WASM_TABLE_INDEX_I32:
-    case R_WASM_TABLE_INDEX_SLEB: {
+    case R_WASM_TABLE_INDEX_SLEB:
+    case R_WASM_TABLE_INDEX_REL_SLEB: {
       FunctionSymbol *Sym = File->getFunctionSymbol(Reloc.Index);
       if (Sym->hasTableIndex() || !Sym->hasFunctionIndex())
         continue;




More information about the llvm-commits mailing list