[llvm-branch-commits] [llvm] e9f1ed2 - [WebAssembly] MC layer writes table symbols to object files

Andy Wingo via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Jan 15 06:01:03 PST 2021


Author: Andy Wingo
Date: 2021-01-15T14:55:55+01:00
New Revision: e9f1ed2306b1b3aedcb1acef2b50e252a77a04b9

URL: https://github.com/llvm/llvm-project/commit/e9f1ed2306b1b3aedcb1acef2b50e252a77a04b9
DIFF: https://github.com/llvm/llvm-project/commit/e9f1ed2306b1b3aedcb1acef2b50e252a77a04b9.diff

LOG: [WebAssembly] MC layer writes table symbols to object files

Now that the linker handles table symbols, we can allow the frontend to
produce them.

Depends on D91870.

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

Added: 
    

Modified: 
    llvm/lib/MC/WasmObjectWriter.cpp
    llvm/test/MC/WebAssembly/debug-info.ll
    llvm/test/MC/WebAssembly/debug-info64.ll
    llvm/test/MC/WebAssembly/function-alias.ll
    llvm/test/MC/WebAssembly/global-ctor-dtor.ll
    llvm/test/MC/WebAssembly/reloc-pic.s
    llvm/test/MC/WebAssembly/type-index.s
    llvm/test/MC/WebAssembly/weak-alias.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index fb41c3763c15..b2d94dcadd81 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -519,6 +519,13 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
       Sym->setUndefined();
     }
     Sym->setUsedInReloc();
+    // Any time we have a TABLE_INDEX relocation against a function symbol, we
+    // need to ensure that table itself is part of the final output too.  In the
+    // future we may want to define a new kind of reloc against both the
+    // function and the table, so that the linker can see that the function
+    // symbol keeps the table alive, but for now manually mark the table as
+    // live.
+    Sym->setNoStrip();
     Asm.registerSymbol(*Sym);
   }
 
@@ -1670,10 +1677,6 @@ uint64_t WasmObjectWriter::writeOneObject(MCAssembler &Asm,
       WS.setIndex(InvalidIndex);
       continue;
     }
-    if (WS.isTable() && WS.getName() == "__indirect_function_table") {
-      // For the moment, don't emit table symbols -- wasm-ld can't handle them.
-      continue;
-    }
     LLVM_DEBUG(dbgs() << "adding to symtab: " << WS << "\n");
 
     uint32_t Flags = 0;

diff  --git a/llvm/test/MC/WebAssembly/debug-info.ll b/llvm/test/MC/WebAssembly/debug-info.ll
index 167d912c84a2..88d19d9191a9 100644
--- a/llvm/test/MC/WebAssembly/debug-info.ll
+++ b/llvm/test/MC/WebAssembly/debug-info.ll
@@ -89,44 +89,44 @@
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
-; CHECK-NEXT:    Size: 91
+; CHECK-NEXT:    Size: 95
 ; CHECK-NEXT:    Offset: 731
 ; CHECK-NEXT:    Name: linking
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
 ; CHECK-NEXT:    Size: 9
-; CHECK-NEXT:    Offset: 836
+; CHECK-NEXT:    Offset: 840
 ; CHECK-NEXT:    Name: reloc.DATA
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
 ; CHECK-NEXT:    Size: 61
-; CHECK-NEXT:    Offset: 862
+; CHECK-NEXT:    Offset: 866
 ; CHECK-NEXT:    Name: reloc..debug_info
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
 ; CHECK-NEXT:    Size: 6
-; CHECK-NEXT:    Offset: 947
+; CHECK-NEXT:    Offset: 951
 ; CHECK-NEXT:    Name: reloc..debug_pubnames
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
 ; CHECK-NEXT:    Size: 6
-; CHECK-NEXT:    Offset: 981
+; CHECK-NEXT:    Offset: 985
 ; CHECK-NEXT:    Name: reloc..debug_pubtypes
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
 ; CHECK-NEXT:    Size: 6
-; CHECK-NEXT:    Offset: 1015
+; CHECK-NEXT:    Offset: 1019
 ; CHECK-NEXT:    Name: reloc..debug_line
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:  Section {
 ; CHECK-NEXT:    Type: CUSTOM (0x0)
 ; CHECK-NEXT:    Size: 77
-; CHECK-NEXT:    Offset: 1045
+; CHECK-NEXT:    Offset: 1049
 ; CHECK-NEXT:    Name: producers
 ; CHECK-NEXT:  }
 ; CHECK-NEXT:]
@@ -238,6 +238,16 @@
 ; CHECK-NEXT:    ]
 ; CHECK-NEXT:    ElementIndex: 0xC
 ; CHECK-NEXT:  }
+; CHECK-NEXT:  Symbol {
+; CHECK-NEXT:    Name: __indirect_function_table
+; CHECK-NEXT:    Type: TABLE (0x5)
+; CHECK-NEXT:    Flags [ (0x90)
+; CHECK-NEXT:      NO_STRIP (0x80)
+; CHECK-NEXT:      UNDEFINED (0x10)
+; CHECK-NEXT:    ]
+; CHECK-NEXT:    ImportModule: env
+; CHECK-NEXT:    ElementIndex: 0x0
+; CHECK-NEXT:  }
 ; CHECK-NEXT:]
 
 ; generated from the following C code using: clang --target=wasm32 -g -O0 -S -emit-llvm test.c

diff  --git a/llvm/test/MC/WebAssembly/debug-info64.ll b/llvm/test/MC/WebAssembly/debug-info64.ll
index acba8aa27360..1755f2b7ef5c 100644
--- a/llvm/test/MC/WebAssembly/debug-info64.ll
+++ b/llvm/test/MC/WebAssembly/debug-info64.ll
@@ -89,44 +89,44 @@
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
-; CHECK-NEXT:     Size: 91
+; CHECK-NEXT:     Size: 95
 ; CHECK-NEXT:     Offset: 759
 ; CHECK-NEXT:     Name: linking
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
 ; CHECK-NEXT:     Size: 9
-; CHECK-NEXT:     Offset: 864
+; CHECK-NEXT:     Offset: 868
 ; CHECK-NEXT:     Name: reloc.DATA
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
 ; CHECK-NEXT:     Size: 61
-; CHECK-NEXT:     Offset: 890
+; CHECK-NEXT:     Offset: 894
 ; CHECK-NEXT:     Name: reloc..debug_info
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
 ; CHECK-NEXT:     Size: 6
-; CHECK-NEXT:     Offset: 975
+; CHECK-NEXT:     Offset: 979
 ; CHECK-NEXT:     Name: reloc..debug_pubnames
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
 ; CHECK-NEXT:     Size: 6
-; CHECK-NEXT:     Offset: 1009
+; CHECK-NEXT:     Offset: 1013
 ; CHECK-NEXT:     Name: reloc..debug_pubtypes
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
 ; CHECK-NEXT:     Size: 6
-; CHECK-NEXT:     Offset: 1043
+; CHECK-NEXT:     Offset: 1047
 ; CHECK-NEXT:     Name: reloc..debug_line
 ; CHECK-NEXT:   }
 ; CHECK-NEXT:   Section {
 ; CHECK-NEXT:     Type: CUSTOM (0x0)
 ; CHECK-NEXT:     Size: 77
-; CHECK-NEXT:     Offset: 1073
+; CHECK-NEXT:     Offset: 1077
 ; CHECK-NEXT:     Name: producers
 ; CHECK-NEXT:   }
 ; CHECK-NEXT: ]
@@ -238,6 +238,16 @@
 ; CHECK-NEXT:     ]
 ; CHECK-NEXT:     ElementIndex: 0xC
 ; CHECK-NEXT:   }
+; CHECK-NEXT:   Symbol {
+; CHECK-NEXT:     Name: __indirect_function_table
+; CHECK-NEXT:     Type: TABLE (0x5)
+; CHECK-NEXT:     Flags [ (0x90)
+; CHECK-NEXT:       NO_STRIP (0x80)
+; CHECK-NEXT:       UNDEFINED (0x10)
+; CHECK-NEXT:     ]
+; CHECK-NEXT:     ImportModule: env
+; CHECK-NEXT:     ElementIndex: 0x0
+; CHECK-NEXT:   }
 ; CHECK-NEXT: ]
 
 ; generated from the following C code using: clang --target=wasm64 -g -O0 -S -emit-llvm test.c

diff  --git a/llvm/test/MC/WebAssembly/function-alias.ll b/llvm/test/MC/WebAssembly/function-alias.ll
index ec571083344b..8cd42523e4cd 100644
--- a/llvm/test/MC/WebAssembly/function-alias.ll
+++ b/llvm/test/MC/WebAssembly/function-alias.ll
@@ -41,4 +41,14 @@ define i8* @func() {
 ; CHECK-NEXT:     ]
 ; CHECK-NEXT:     ElementIndex: 0x0
 ; CHECK-NEXT:   }
+; CHECK-NEXT:   Symbol {
+; CHECK-NEXT:     Name: __indirect_function_table
+; CHECK-NEXT:     Type: TABLE (0x5)
+; CHECK-NEXT:     Flags [ (0x90)
+; CHECK-NEXT:       NO_STRIP (0x80)
+; CHECK-NEXT:       UNDEFINED (0x10)
+; CHECK-NEXT:     ]
+; CHECK-NEXT:     ImportModule: env
+; CHECK-NEXT:     ElementIndex: 0x0
+; CHECK-NEXT:   }
 ; CHECK-NEXT: ]

diff  --git a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll
index 5f56cb6e280d..0de7cfc82c42 100644
--- a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll
+++ b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll
@@ -170,6 +170,11 @@ declare void @func3()
 ; CHECK-NEXT:         Name:            func0
 ; CHECK-NEXT:         Flags:           [ UNDEFINED ]
 ; CHECK-NEXT:         Function:        4
+; CHECK-NEXT:       - Index:           11
+; CHECK-NEXT:         Kind:            TABLE
+; CHECK-NEXT:         Name:            __indirect_function_table
+; CHECK-NEXT:         Flags:           [ UNDEFINED, NO_STRIP ]
+; CHECK-NEXT:         Table:           0
 ; CHECK-NEXT:     SegmentInfo:
 ; CHECK-NEXT:       - Index:           0
 ; CHECK-NEXT:         Name:            .data.global1

diff  --git a/llvm/test/MC/WebAssembly/reloc-pic.s b/llvm/test/MC/WebAssembly/reloc-pic.s
index b7995ebf97fa..1842e9234df0 100644
--- a/llvm/test/MC/WebAssembly/reloc-pic.s
+++ b/llvm/test/MC/WebAssembly/reloc-pic.s
@@ -190,6 +190,11 @@ hidden_func:
 # CHECK-NEXT:         Name:            hidden_func
 # CHECK-NEXT:         Flags:           [ BINDING_LOCAL ]
 # CHECK-NEXT:         Function:        5
+# CHECK-NEXT:       - Index:           10
+# CHECK-NEXT:         Kind:            TABLE
+# CHECK-NEXT:         Name:            __indirect_function_table
+# CHECK-NEXT:         Flags:           [ UNDEFINED, NO_STRIP ]
+# CHECK-NEXT:         Table:           0
 # CHECK-NEXT:     SegmentInfo:
 # CHECK-NEXT:       - Index:           0
 # CHECK-NEXT:         Name:            .rodata.hidden_data

diff  --git a/llvm/test/MC/WebAssembly/type-index.s b/llvm/test/MC/WebAssembly/type-index.s
index 298e5e2f9de3..dfaaad53506b 100644
--- a/llvm/test/MC/WebAssembly/type-index.s
+++ b/llvm/test/MC/WebAssembly/type-index.s
@@ -66,4 +66,9 @@ test0:
 # BIN-NEXT:         Name:            test0
 # BIN-NEXT:         Flags:           [ BINDING_LOCAL ]
 # BIN-NEXT:         Function:        0
+# BIN-NEXT:       - Index:           1
+# BIN-NEXT:         Kind:            TABLE
+# BIN-NEXT:         Name:            __indirect_function_table
+# BIN-NEXT:         Flags:           [ UNDEFINED, NO_STRIP ]
+# BIN-NEXT:         Table:           0
 # BIN-NEXT: ...

diff  --git a/llvm/test/MC/WebAssembly/weak-alias.s b/llvm/test/MC/WebAssembly/weak-alias.s
index 4590e0020382..139a681eeea0 100644
--- a/llvm/test/MC/WebAssembly/weak-alias.s
+++ b/llvm/test/MC/WebAssembly/weak-alias.s
@@ -227,6 +227,11 @@ alias_address:
 # CHECK-NEXT:         Flags:           [ BINDING_WEAK, VISIBILITY_HIDDEN, NO_STRIP ]
 # CHECK-NEXT:         Segment:         0
 # CHECK-NEXT:         Size:            4
+# CHECK-NEXT:       - Index:           10
+# CHECK-NEXT:         Kind:            TABLE
+# CHECK-NEXT:         Name:            __indirect_function_table
+# CHECK-NEXT:         Flags:           [ UNDEFINED, NO_STRIP ]
+# CHECK-NEXT:         Table:           0
 # CHECK-NEXT:     SegmentInfo:
 # CHECK-NEXT:       - Index:           0
 # CHECK-NEXT:         Name:            .data.bar


        


More information about the llvm-branch-commits mailing list