[llvm-branch-commits] [lld] r353833 - [WebAssembly] Backport custom import name changes for lld to 8.0.

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 12 04:24:52 PST 2019


Author: hans
Date: Tue Feb 12 04:24:52 2019
New Revision: 353833

URL: http://llvm.org/viewvc/llvm-project?rev=353833&view=rev
Log:
[WebAssembly] Backport custom import name changes for lld to 8.0.

Specifically, this backports r352645, r352828, and r353473 to the
8.0 branch. The trunk patches don't apply cleanly to 8.0 due to
some contemporaneous mass-rename and mass-clang-tidy patches, so
this merges them to simplify rebasing.

r352645 [WebAssembly] Fix crash with LTO + relocatable + undefined symbols
r352828 [WebAssembly] Support imports from custom module names
r353473 [WebAssembly] Fix imported function symbol names that differ from their import names in the .o format

By Dan Gohman!

Added:
    lld/branches/release_80/test/wasm/import-module.ll
    lld/branches/release_80/test/wasm/import-names.ll
    lld/branches/release_80/test/wasm/lto/relocatable-undefined.ll
Modified:
    lld/branches/release_80/test/wasm/data-layout.ll
    lld/branches/release_80/test/wasm/init-fini.ll
    lld/branches/release_80/test/wasm/locals-duplicate.test
    lld/branches/release_80/test/wasm/weak-alias.ll
    lld/branches/release_80/wasm/Driver.cpp
    lld/branches/release_80/wasm/InputChunks.cpp
    lld/branches/release_80/wasm/InputFiles.cpp
    lld/branches/release_80/wasm/LTO.cpp
    lld/branches/release_80/wasm/LTO.h
    lld/branches/release_80/wasm/MarkLive.cpp
    lld/branches/release_80/wasm/SymbolTable.cpp
    lld/branches/release_80/wasm/SymbolTable.h
    lld/branches/release_80/wasm/Symbols.h
    lld/branches/release_80/wasm/Writer.cpp
    lld/branches/release_80/wasm/Writer.h

Modified: lld/branches/release_80/test/wasm/data-layout.ll
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/data-layout.ll?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/test/wasm/data-layout.ll (original)
+++ lld/branches/release_80/test/wasm/data-layout.ll Tue Feb 12 04:24:52 2019
@@ -85,10 +85,10 @@ target triple = "wasm32-unknown-unknown"
 ; RELOC:       - Type:            DATA
 ; RELOC-NEXT:     Relocations:
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_I32
-; RELOC-NEXT:         Index:           6
+; RELOC-NEXT:         Index:           3
 ; RELOC-NEXT:         Offset:          0x00000018
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_I32
-; RELOC-NEXT:         Index:           3
+; RELOC-NEXT:         Index:           4
 ; RELOC-NEXT:         Offset:          0x0000002E
 ; RELOC-NEXT:         Addend:          4
 ; RELOC-NEXT:     Segments:
@@ -148,7 +148,7 @@ target triple = "wasm32-unknown-unknown"
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Segment:         2
 ; RELOC-NEXT:         Size:            4
-; RELOC:            - Index:           6
+; RELOC-NEXT:       - Index:           3
 ; RELOC-NEXT:         Kind:            DATA
 ; RELOC-NEXT:         Name:            hello_str
 ; RELOC-NEXT:         Flags:           [  ]

Added: lld/branches/release_80/test/wasm/import-module.ll
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/import-module.ll?rev=353833&view=auto
==============================================================================
--- lld/branches/release_80/test/wasm/import-module.ll (added)
+++ lld/branches/release_80/test/wasm/import-module.ll Tue Feb 12 04:24:52 2019
@@ -0,0 +1,21 @@
+; RUN: llc -filetype=obj %s -o %t.o
+; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target triple = "wasm32-unknown-unknown-wasm"
+
+define void @_start() {
+  call void @foo();
+  ret void
+}
+
+declare void @foo() #0
+
+attributes #0 = { "wasm-import-module"="bar" }
+
+; CHECK:        - Type:            IMPORT
+; CHECK-NEXT:     Imports:         
+; CHECK-NEXT:       - Module:          bar
+; CHECK-NEXT:         Field:           foo
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         SigIndex:        0

Added: lld/branches/release_80/test/wasm/import-names.ll
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/import-names.ll?rev=353833&view=auto
==============================================================================
--- lld/branches/release_80/test/wasm/import-names.ll (added)
+++ lld/branches/release_80/test/wasm/import-names.ll Tue Feb 12 04:24:52 2019
@@ -0,0 +1,27 @@
+; RUN: llc -filetype=obj %s -o %t.o
+; RUN: wasm-ld --allow-undefined -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+declare void @f0() #0
+
+define void @_start() {
+    call void @f0()
+    ret void
+}
+
+attributes #0 = { "wasm-import-module"="somewhere" "wasm-import-name"="something" }
+
+; CHECK:        - Type:            IMPORT
+; CHECK-NEXT:     Imports:
+; CHECK-NEXT:       - Module:          somewhere
+; CHECK-NEXT:         Field:           something
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         SigIndex:        0
+
+; CHECK:        - Type:            CUSTOM
+; CHECK-NEXT:     Name:            name
+; CHECK-NEXT:     FunctionNames:
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         Name:            f0

Modified: lld/branches/release_80/test/wasm/init-fini.ll
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/init-fini.ll?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/test/wasm/init-fini.ll (original)
+++ lld/branches/release_80/test/wasm/init-fini.ll Tue Feb 12 04:24:52 2019
@@ -163,64 +163,64 @@ entry:
 ; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
 ; RELOC-NEXT:         Function:        7
 ; RELOC-NEXT:       - Index:           6
+; RELOC-NEXT:         Kind:            DATA
+; RELOC-NEXT:         Name:            __dso_handle
+; RELOC-NEXT:         Flags:           [ BINDING_WEAK, VISIBILITY_HIDDEN, UNDEFINED ]
+; RELOC-NEXT:       - Index:           7
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            externDtor
+; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN, UNDEFINED ]
+; RELOC-NEXT:         Function:        0
+; RELOC-NEXT:       - Index:           8
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            externCtor
+; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN, UNDEFINED ]
+; RELOC-NEXT:         Function:        1
+; RELOC-NEXT:       - Index:           9
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            myctor
+; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
+; RELOC-NEXT:         Function:        14
+; RELOC-NEXT:       - Index:           10
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            mydtor
+; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
+; RELOC-NEXT:         Function:        15
+; RELOC-NEXT:       - Index:           11
+; RELOC-NEXT:         Kind:            GLOBAL
+; RELOC-NEXT:         Name:            __stack_pointer
+; RELOC-NEXT:         Flags:           [ UNDEFINED ]
+; RELOC-NEXT:         Global:          0
+; RELOC-NEXT:       - Index:           12
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lcall_dtors.101
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        8
-; RELOC-NEXT:       - Index:           7
+; RELOC-NEXT:       - Index:           13
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lregister_call_dtors.101
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        9
-; RELOC-NEXT:       - Index:           8
-; RELOC-NEXT:         Kind:            DATA
-; RELOC-NEXT:         Name:            __dso_handle
-; RELOC-NEXT:         Flags:           [ BINDING_WEAK, VISIBILITY_HIDDEN, UNDEFINED ]
-; RELOC-NEXT:       - Index:           9
+; RELOC-NEXT:       - Index:           14
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lcall_dtors.1001
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        10
-; RELOC-NEXT:       - Index:           10
+; RELOC-NEXT:       - Index:           15
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lregister_call_dtors.1001
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        11
-; RELOC-NEXT:       - Index:           11
+; RELOC-NEXT:       - Index:           16
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lcall_dtors.4000
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        12
-; RELOC-NEXT:       - Index:           12
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            externDtor
-; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN, UNDEFINED ]
-; RELOC-NEXT:         Function:        0
-; RELOC-NEXT:       - Index:           13
+; RELOC-NEXT:       - Index:           17
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lregister_call_dtors.4000
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        13
-; RELOC-NEXT:       - Index:           14
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            externCtor
-; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN, UNDEFINED ]
-; RELOC-NEXT:         Function:        1
-; RELOC-NEXT:       - Index:           15
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            myctor
-; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
-; RELOC-NEXT:         Function:        14
-; RELOC-NEXT:       - Index:           16
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            mydtor
-; RELOC-NEXT:         Flags:           [ VISIBILITY_HIDDEN ]
-; RELOC-NEXT:         Function:        15
-; RELOC-NEXT:       - Index:           17
-; RELOC-NEXT:         Kind:            GLOBAL
-; RELOC-NEXT:         Name:            __stack_pointer
-; RELOC-NEXT:         Flags:           [ UNDEFINED ]
-; RELOC-NEXT:         Global:          0
 ; RELOC-NEXT:       - Index:           18
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            .Lcall_dtors.101
@@ -251,36 +251,36 @@ entry:
 ; RELOC-NEXT:         Name:            .Lregister_call_dtors.2002
 ; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
 ; RELOC-NEXT:         Function:        21
-; RELOC-NEXT:     InitFunctions:
+; RELOC-NEXT:     InitFunctions:   
 ; RELOC-NEXT:       - Priority:        101
 ; RELOC-NEXT:         Symbol:          0
 ; RELOC-NEXT:       - Priority:        101
 ; RELOC-NEXT:         Symbol:          1
 ; RELOC-NEXT:       - Priority:        101
-; RELOC-NEXT:         Symbol:          7
+; RELOC-NEXT:         Symbol:          13
 ; RELOC-NEXT:       - Priority:        101
-; RELOC-NEXT:         Symbol:          15
+; RELOC-NEXT:         Symbol:          9
 ; RELOC-NEXT:       - Priority:        101
 ; RELOC-NEXT:         Symbol:          19
 ; RELOC-NEXT:       - Priority:        202
-; RELOC-NEXT:         Symbol:          15
+; RELOC-NEXT:         Symbol:          9
 ; RELOC-NEXT:       - Priority:        202
 ; RELOC-NEXT:         Symbol:          21
 ; RELOC-NEXT:       - Priority:        1001
 ; RELOC-NEXT:         Symbol:          0
 ; RELOC-NEXT:       - Priority:        1001
-; RELOC-NEXT:         Symbol:          10
-; RELOC-NEXT:       - Priority:        2002
 ; RELOC-NEXT:         Symbol:          15
 ; RELOC-NEXT:       - Priority:        2002
+; RELOC-NEXT:         Symbol:          9
+; RELOC-NEXT:       - Priority:        2002
 ; RELOC-NEXT:         Symbol:          23
 ; RELOC-NEXT:       - Priority:        4000
-; RELOC-NEXT:         Symbol:          14
+; RELOC-NEXT:         Symbol:          8
 ; RELOC-NEXT:       - Priority:        4000
-; RELOC-NEXT:         Symbol:          13
+; RELOC-NEXT:         Symbol:          17
 ; RELOC-NEXT:   - Type:            CUSTOM
 ; RELOC-NEXT:     Name:            name
-; RELOC-NEXT:     FunctionNames:
+; RELOC-NEXT:     FunctionNames:   
 ; RELOC-NEXT:       - Index:           0
 ; RELOC-NEXT:         Name:            externDtor
 ; RELOC-NEXT:       - Index:           1

Modified: lld/branches/release_80/test/wasm/locals-duplicate.test
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/locals-duplicate.test?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/test/wasm/locals-duplicate.test (original)
+++ lld/branches/release_80/test/wasm/locals-duplicate.test Tue Feb 12 04:24:52 2019
@@ -270,40 +270,40 @@
 ; RELOC-NEXT:   - Type:            CODE
 ; RELOC-NEXT:     Relocations:
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_SLEB
-; RELOC-NEXT:         Index:           4
+; RELOC-NEXT:         Index:           18
 ; RELOC-NEXT:         Offset:          0x00000013
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_SLEB
-; RELOC-NEXT:         Index:           6
+; RELOC-NEXT:         Index:           3
 ; RELOC-NEXT:         Offset:          0x0000001C
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_SLEB
-; RELOC-NEXT:         Index:           8
+; RELOC-NEXT:         Index:           19
 ; RELOC-NEXT:         Offset:          0x00000025
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           0
+; RELOC-NEXT:         Index:           16
 ; RELOC-NEXT:         Offset:          0x0000002E
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           1
+; RELOC-NEXT:         Index:           0
 ; RELOC-NEXT:         Offset:          0x00000037
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           2
+; RELOC-NEXT:         Index:           17
 ; RELOC-NEXT:         Offset:          0x00000040
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_SLEB
-; RELOC-NEXT:         Index:           16
+; RELOC-NEXT:         Index:           10
 ; RELOC-NEXT:         Offset:          0x00000058
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_SLEB
-; RELOC-NEXT:         Index:           18
+; RELOC-NEXT:         Index:           22
 ; RELOC-NEXT:         Offset:          0x00000061
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_MEMORY_ADDR_SLEB
-; RELOC-NEXT:         Index:           20
+; RELOC-NEXT:         Index:           23
 ; RELOC-NEXT:         Offset:          0x0000006A
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           12
+; RELOC-NEXT:         Index:           8
 ; RELOC-NEXT:         Offset:          0x00000073
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           13
+; RELOC-NEXT:         Index:           20
 ; RELOC-NEXT:         Offset:          0x0000007C
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           14
+; RELOC-NEXT:         Index:           21
 ; RELOC-NEXT:         Offset:          0x00000085
 ; RELOC-NEXT:     Functions:
 ; RELOC-NEXT:       - Index:           0
@@ -386,133 +386,133 @@
 ; RELOC-NEXT:     SymbolTable:
 ; RELOC-NEXT:       - Index:           0
 ; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            colliding_func1
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Function:        0
-; RELOC-NEXT:       - Index:           1
-; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            colliding_func2
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        1
-; RELOC-NEXT:       - Index:           2
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            colliding_func3
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Function:        2
-; RELOC-NEXT:       - Index:           3
+; RELOC-NEXT:       - Index:           1
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_global1A
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        3
-; RELOC-NEXT:       - Index:           4
-; RELOC-NEXT:         Kind:            DATA
-; RELOC-NEXT:         Name:            colliding_global1
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Segment:         0
-; RELOC-NEXT:         Size:            4
-; RELOC-NEXT:       - Index:           5
+; RELOC-NEXT:       - Index:           2
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_global2A
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        4
-; RELOC-NEXT:       - Index:           6
+; RELOC-NEXT:       - Index:           3
 ; RELOC-NEXT:         Kind:            DATA
 ; RELOC-NEXT:         Name:            colliding_global2
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Segment:         1
 ; RELOC-NEXT:         Size:            4
-; RELOC-NEXT:       - Index:           7
+; RELOC-NEXT:       - Index:           4
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_global3A
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        5
-; RELOC-NEXT:       - Index:           8
-; RELOC-NEXT:         Kind:            DATA
-; RELOC-NEXT:         Name:            colliding_global3
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Segment:         2
-; RELOC-NEXT:         Size:            4
-; RELOC-NEXT:       - Index:           9
+; RELOC-NEXT:       - Index:           5
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_func1A
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        6
-; RELOC-NEXT:       - Index:           10
+; RELOC-NEXT:       - Index:           6
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_func2A
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        7
-; RELOC-NEXT:       - Index:           11
+; RELOC-NEXT:       - Index:           7
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_func3A
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        8
-; RELOC-NEXT:       - Index:           12
+; RELOC-NEXT:       - Index:           8
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            colliding_func1
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        9
-; RELOC-NEXT:       - Index:           13
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            colliding_func2
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Function:        10
-; RELOC-NEXT:       - Index:           14
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            colliding_func3
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Function:        11
-; RELOC-NEXT:       - Index:           15
+; RELOC-NEXT:       - Index:           9
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_global1B
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        12
-; RELOC-NEXT:       - Index:           16
+; RELOC-NEXT:       - Index:           10
 ; RELOC-NEXT:         Kind:            DATA
 ; RELOC-NEXT:         Name:            colliding_global1
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Segment:         0
 ; RELOC-NEXT:         Offset:          4
 ; RELOC-NEXT:         Size:            4
-; RELOC-NEXT:       - Index:           17
+; RELOC-NEXT:       - Index:           11
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_global2B
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        13
-; RELOC-NEXT:       - Index:           18
-; RELOC-NEXT:         Kind:            DATA
-; RELOC-NEXT:         Name:            colliding_global2
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Segment:         1
-; RELOC-NEXT:         Offset:          4
-; RELOC-NEXT:         Size:            4
-; RELOC-NEXT:       - Index:           19
+; RELOC-NEXT:       - Index:           12
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_global3B
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        14
-; RELOC-NEXT:       - Index:           20
-; RELOC-NEXT:         Kind:            DATA
-; RELOC-NEXT:         Name:            colliding_global3
-; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
-; RELOC-NEXT:         Segment:         2
-; RELOC-NEXT:         Offset:          4
-; RELOC-NEXT:         Size:            4
-; RELOC-NEXT:       - Index:           21
+; RELOC-NEXT:       - Index:           13
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_func1B
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        15
-; RELOC-NEXT:       - Index:           22
+; RELOC-NEXT:       - Index:           14
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_func2B
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        16
-; RELOC-NEXT:       - Index:           23
+; RELOC-NEXT:       - Index:           15
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            get_func3B
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        17
+; RELOC-NEXT:       - Index:           16
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            colliding_func1
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Function:        0
+; RELOC-NEXT:       - Index:           17
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            colliding_func3
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Function:        2
+; RELOC-NEXT:       - Index:           18
+; RELOC-NEXT:         Kind:            DATA
+; RELOC-NEXT:         Name:            colliding_global1
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Segment:         0
+; RELOC-NEXT:         Size:            4
+; RELOC-NEXT:       - Index:           19
+; RELOC-NEXT:         Kind:            DATA
+; RELOC-NEXT:         Name:            colliding_global3
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Segment:         2
+; RELOC-NEXT:         Size:            4
+; RELOC-NEXT:       - Index:           20
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            colliding_func2
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Function:        10
+; RELOC-NEXT:       - Index:           21
+; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            colliding_func3
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Function:        11
+; RELOC-NEXT:       - Index:           22
+; RELOC-NEXT:         Kind:            DATA
+; RELOC-NEXT:         Name:            colliding_global2
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Segment:         1
+; RELOC-NEXT:         Offset:          4
+; RELOC-NEXT:         Size:            4
+; RELOC-NEXT:       - Index:           23
+; RELOC-NEXT:         Kind:            DATA
+; RELOC-NEXT:         Name:            colliding_global3
+; RELOC-NEXT:         Flags:           [ BINDING_LOCAL ]
+; RELOC-NEXT:         Segment:         2
+; RELOC-NEXT:         Offset:          4
+; RELOC-NEXT:         Size:            4
 ; RELOC-NEXT:     SegmentInfo:
 ; RELOC-NEXT:       - Index:           0
 ; RELOC-NEXT:         Name:            .bss.colliding_global1

Added: lld/branches/release_80/test/wasm/lto/relocatable-undefined.ll
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/lto/relocatable-undefined.ll?rev=353833&view=auto
==============================================================================
--- lld/branches/release_80/test/wasm/lto/relocatable-undefined.ll (added)
+++ lld/branches/release_80/test/wasm/lto/relocatable-undefined.ll Tue Feb 12 04:24:52 2019
@@ -0,0 +1,36 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: wasm-ld -r -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+ at missing_data = external global i32
+declare i32 @missing_func() local_unnamed_addr
+
+define i32 @foo() {
+entry:
+  %0 = call i32 @missing_func()
+  %1 = load i32, i32* @missing_data, align 4
+  ret i32 %1
+}
+
+
+; CHECK:        - Type:            CUSTOM
+; CHECK-NEXT:     Name:            linking
+; CHECK-NEXT:     Version:         2
+; CHECK-NEXT:     SymbolTable:     
+; CHECK-NEXT:       - Index:           0
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         Name:            missing_func
+; CHECK-NEXT:         Flags:           [ UNDEFINED ]
+; CHECK-NEXT:         Function:        0
+; CHECK-NEXT:       - Index:           1
+; CHECK-NEXT:         Kind:            FUNCTION
+; CHECK-NEXT:         Name:            foo
+; CHECK-NEXT:         Flags:           [  ]
+; CHECK-NEXT:         Function:        1
+; CHECK-NEXT:       - Index:           2
+; CHECK-NEXT:         Kind:            DATA
+; CHECK-NEXT:         Name:            missing_data
+; CHECK-NEXT:         Flags:           [ UNDEFINED ]

Modified: lld/branches/release_80/test/wasm/weak-alias.ll
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/test/wasm/weak-alias.ll?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/test/wasm/weak-alias.ll (original)
+++ lld/branches/release_80/test/wasm/weak-alias.ll Tue Feb 12 04:24:52 2019
@@ -187,13 +187,13 @@ entry:
 ; RELOC-NEXT:   - Type:            CODE
 ; RELOC-NEXT:     Relocations:
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_FUNCTION_INDEX_LEB
-; RELOC-NEXT:         Index:           4
+; RELOC-NEXT:         Index:           1
 ; RELOC-NEXT:         Offset:          0x00000004
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_FUNCTION_INDEX_LEB
-; RELOC-NEXT:         Index:           1
+; RELOC-NEXT:         Index:           2
 ; RELOC-NEXT:         Offset:          0x00000013
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_FUNCTION_INDEX_LEB
-; RELOC-NEXT:         Index:           4
+; RELOC-NEXT:         Index:           1
 ; RELOC-NEXT:         Offset:          0x0000001C
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_GLOBAL_INDEX_LEB
 ; RELOC-NEXT:         Index:           6
@@ -202,10 +202,10 @@ entry:
 ; RELOC-NEXT:         Index:           6
 ; RELOC-NEXT:         Offset:          0x00000032
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           4
+; RELOC-NEXT:         Index:           1
 ; RELOC-NEXT:         Offset:          0x0000003A
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_FUNCTION_INDEX_LEB
-; RELOC-NEXT:         Index:           4
+; RELOC-NEXT:         Index:           1
 ; RELOC-NEXT:         Offset:          0x00000043
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_GLOBAL_INDEX_LEB
 ; RELOC-NEXT:         Index:           6
@@ -217,10 +217,10 @@ entry:
 ; RELOC-NEXT:         Index:           6
 ; RELOC-NEXT:         Offset:          0x00000068
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_TABLE_INDEX_SLEB
-; RELOC-NEXT:         Index:           1
+; RELOC-NEXT:         Index:           2
 ; RELOC-NEXT:         Offset:          0x00000070
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_FUNCTION_INDEX_LEB
-; RELOC-NEXT:         Index:           1
+; RELOC-NEXT:         Index:           2
 ; RELOC-NEXT:         Offset:          0x00000079
 ; RELOC-NEXT:       - Type:            R_WEBASSEMBLY_GLOBAL_INDEX_LEB
 ; RELOC-NEXT:         Index:           6
@@ -259,24 +259,24 @@ entry:
 ; RELOC-NEXT:         Function:        0
 ; RELOC-NEXT:       - Index:           1
 ; RELOC-NEXT:         Kind:            FUNCTION
+; RELOC-NEXT:         Name:            alias_fn
+; RELOC-NEXT:         Flags:           [ BINDING_WEAK ]
+; RELOC-NEXT:         Function:        1
+; RELOC-NEXT:       - Index:           2
+; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            direct_fn
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        1
-; RELOC-NEXT:       - Index:           2
+; RELOC-NEXT:       - Index:           3
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            call_direct
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        2
-; RELOC-NEXT:       - Index:           3
+; RELOC-NEXT:       - Index:           4
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            call_alias
 ; RELOC-NEXT:         Flags:           [  ]
 ; RELOC-NEXT:         Function:        3
-; RELOC-NEXT:       - Index:           4
-; RELOC-NEXT:         Kind:            FUNCTION
-; RELOC-NEXT:         Name:            alias_fn
-; RELOC-NEXT:         Flags:           [ BINDING_WEAK ]
-; RELOC-NEXT:         Function:        1
 ; RELOC-NEXT:       - Index:           5
 ; RELOC-NEXT:         Kind:            FUNCTION
 ; RELOC-NEXT:         Name:            call_alias_ptr

Modified: lld/branches/release_80/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/Driver.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/Driver.cpp (original)
+++ lld/branches/release_80/wasm/Driver.cpp Tue Feb 12 04:24:52 2019
@@ -434,7 +434,9 @@ static Symbol *handleUndefined(StringRef
 static UndefinedGlobal *
 createUndefinedGlobal(StringRef Name, llvm::wasm::WasmGlobalType *Type) {
   auto *Sym =
-      cast<UndefinedGlobal>(Symtab->addUndefinedGlobal(Name, 0, nullptr, Type));
+      cast<UndefinedGlobal>(Symtab->addUndefinedGlobal(Name, Name,
+                                                       DefaultModule, 0,
+                                                       nullptr, Type));
   Config->AllowUndefinedSymbols.insert(Sym->getName());
   Sym->IsUsedInRegularObj = true;
   return Sym;

Modified: lld/branches/release_80/wasm/InputChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/InputChunks.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/InputChunks.cpp (original)
+++ lld/branches/release_80/wasm/InputChunks.cpp Tue Feb 12 04:24:52 2019
@@ -23,7 +23,7 @@ using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::wasm;
 
-static StringRef ReloctTypeToString(uint8_t RelocType) {
+static StringRef reloctTypeToString(uint8_t RelocType) {
   switch (RelocType) {
 #define WASM_RELOC(NAME, REL)                                                  \
   case REL:                                                                    \
@@ -77,7 +77,7 @@ void InputChunk::verifyRelocTargets() co
       warn("expected LEB at relocation site be 5-byte padded");
     uint32_t ExpectedValue = File->calcExpectedValue(Rel);
     if (ExpectedValue != ExistingValue)
-      warn("unexpected existing value for " + ReloctTypeToString(Rel.Type) +
+      warn("unexpected existing value for " + reloctTypeToString(Rel.Type) +
            ": existing=" + Twine(ExistingValue) +
            " expected=" + Twine(ExpectedValue));
   }
@@ -103,7 +103,7 @@ void InputChunk::writeTo(uint8_t *Buf) c
   for (const WasmRelocation &Rel : Relocations) {
     uint8_t *Loc = Buf + Rel.Offset + Off;
     uint32_t Value = File->calcNewValue(Rel);
-    LLVM_DEBUG(dbgs() << "apply reloc: type=" << ReloctTypeToString(Rel.Type)
+    LLVM_DEBUG(dbgs() << "apply reloc: type=" << reloctTypeToString(Rel.Type)
                       << " addend=" << Rel.Addend << " index=" << Rel.Index
                       << " value=" << Value << " offset=" << Rel.Offset
                       << "\n");

Modified: lld/branches/release_80/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/InputFiles.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/InputFiles.cpp (original)
+++ lld/branches/release_80/wasm/InputFiles.cpp Tue Feb 12 04:24:52 2019
@@ -377,11 +377,15 @@ Symbol *ObjFile::createUndefined(const W
 
   switch (Sym.Info.Kind) {
   case WASM_SYMBOL_TYPE_FUNCTION:
-    return Symtab->addUndefinedFunction(Name, Flags, this, Sym.Signature);
+    return Symtab->addUndefinedFunction(Name, Sym.Info.ImportName,
+                                        Sym.Info.ImportModule, Flags, this,
+                                        Sym.Signature);
   case WASM_SYMBOL_TYPE_DATA:
     return Symtab->addUndefinedData(Name, Flags, this);
   case WASM_SYMBOL_TYPE_GLOBAL:
-    return Symtab->addUndefinedGlobal(Name, Flags, this, Sym.GlobalType);
+    return Symtab->addUndefinedGlobal(Name, Sym.Info.ImportName,
+                                      Sym.Info.ImportModule, Flags, this,
+                                      Sym.GlobalType);
   case WASM_SYMBOL_TYPE_SECTION:
     llvm_unreachable("section symbols cannot be undefined");
   }
@@ -445,7 +449,8 @@ static Symbol *createBitcodeSymbol(const
 
   if (ObjSym.isUndefined()) {
     if (ObjSym.isExecutable())
-      return Symtab->addUndefinedFunction(Name, Flags, &F, nullptr);
+      return Symtab->addUndefinedFunction(Name, Name, DefaultModule, Flags, &F,
+                                          nullptr);
     return Symtab->addUndefinedData(Name, Flags, &F);
   }
 

Modified: lld/branches/release_80/wasm/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/LTO.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/LTO.cpp (original)
+++ lld/branches/release_80/wasm/LTO.cpp Tue Feb 12 04:24:52 2019
@@ -79,8 +79,9 @@ BitcodeCompiler::~BitcodeCompiler() = de
 
 static void undefine(Symbol *S) {
   if (auto F = dyn_cast<DefinedFunction>(S))
-    replaceSymbol<UndefinedFunction>(F, F->getName(), 0, F->getFile(),
-                                     F->Signature);
+    replaceSymbol<UndefinedFunction>(F, F->getName(), F->getName(),
+                                     DefaultModule, 0,
+                                     F->getFile(), F->Signature);
   else if (isa<DefinedData>(S))
     replaceSymbol<UndefinedData>(S, S->getName(), 0, S->getFile());
   else

Modified: lld/branches/release_80/wasm/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/LTO.h?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/LTO.h (original)
+++ lld/branches/release_80/wasm/LTO.h Tue Feb 12 04:24:52 2019
@@ -23,6 +23,7 @@
 
 #include "lld/Common/LLVM.h"
 #include "llvm/ADT/SmallString.h"
+#include "Writer.h"
 #include <memory>
 #include <vector>
 

Modified: lld/branches/release_80/wasm/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/MarkLive.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/MarkLive.cpp (original)
+++ lld/branches/release_80/wasm/MarkLive.cpp Tue Feb 12 04:24:52 2019
@@ -85,7 +85,7 @@ void lld::wasm::markLive() {
       // equal to null pointer, only reachable via direct call).
       if (Reloc.Type == R_WEBASSEMBLY_TABLE_INDEX_SLEB ||
           Reloc.Type == R_WEBASSEMBLY_TABLE_INDEX_I32) {
-        FunctionSymbol *FuncSym = cast<FunctionSymbol>(Sym);
+        auto *FuncSym = cast<FunctionSymbol>(Sym);
         if (FuncSym->hasTableIndex() && FuncSym->getTableIndex() == 0)
           continue;
       }

Modified: lld/branches/release_80/wasm/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/SymbolTable.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/SymbolTable.cpp (original)
+++ lld/branches/release_80/wasm/SymbolTable.cpp Tue Feb 12 04:24:52 2019
@@ -314,8 +314,9 @@ Symbol *SymbolTable::addDefinedEvent(Str
   return S;
 }
 
-Symbol *SymbolTable::addUndefinedFunction(StringRef Name, uint32_t Flags,
-                                          InputFile *File,
+Symbol *SymbolTable::addUndefinedFunction(StringRef Name, StringRef ImportName,
+                                          StringRef ImportModule,
+                                          uint32_t Flags, InputFile *File,
                                           const WasmSignature *Sig) {
   LLVM_DEBUG(dbgs() << "addUndefinedFunction: " << Name <<
              " [" << (Sig ? toString(*Sig) : "none") << "]\n");
@@ -325,7 +326,8 @@ Symbol *SymbolTable::addUndefinedFunctio
   std::tie(S, WasInserted) = insert(Name, File);
 
   if (WasInserted)
-    replaceSymbol<UndefinedFunction>(S, Name, Flags, File, Sig);
+    replaceSymbol<UndefinedFunction>(S, Name, ImportName, ImportModule, Flags,
+                                     File, Sig);
   else if (auto *Lazy = dyn_cast<LazySymbol>(S))
     Lazy->fetch();
   else
@@ -351,7 +353,8 @@ Symbol *SymbolTable::addUndefinedData(St
   return S;
 }
 
-Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, uint32_t Flags,
+Symbol *SymbolTable::addUndefinedGlobal(StringRef Name, StringRef ImportName,
+                                        StringRef ImportModule, uint32_t Flags,
                                         InputFile *File,
                                         const WasmGlobalType *Type) {
   LLVM_DEBUG(dbgs() << "addUndefinedGlobal: " << Name << "\n");
@@ -361,7 +364,8 @@ Symbol *SymbolTable::addUndefinedGlobal(
   std::tie(S, WasInserted) = insert(Name, File);
 
   if (WasInserted)
-    replaceSymbol<UndefinedGlobal>(S, Name, Flags, File, Type);
+    replaceSymbol<UndefinedGlobal>(S, Name, ImportName, ImportModule, Flags,
+                                   File, Type);
   else if (auto *Lazy = dyn_cast<LazySymbol>(S))
     Lazy->fetch();
   else if (S->isDefined())

Modified: lld/branches/release_80/wasm/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/SymbolTable.h?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/SymbolTable.h (original)
+++ lld/branches/release_80/wasm/SymbolTable.h Tue Feb 12 04:24:52 2019
@@ -59,11 +59,13 @@ public:
   Symbol *addDefinedEvent(StringRef Name, uint32_t Flags, InputFile *File,
                           InputEvent *E);
 
-  Symbol *addUndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File,
-                               const WasmSignature *Signature);
+  Symbol *addUndefinedFunction(StringRef Name, StringRef ImportName,
+                               StringRef ImportModule, uint32_t Flags,
+                               InputFile *File, const WasmSignature *Signature);
   Symbol *addUndefinedData(StringRef Name, uint32_t Flags, InputFile *File);
-  Symbol *addUndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File,
-                             const WasmGlobalType *Type);
+  Symbol *addUndefinedGlobal(StringRef Name, StringRef ImportName,
+                             StringRef ImportModule,  uint32_t Flags,
+                             InputFile *File, const WasmGlobalType *Type);
 
   void addLazy(ArchiveFile *F, const llvm::object::Archive::Symbol *Sym);
 

Modified: lld/branches/release_80/wasm/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/Symbols.h?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/Symbols.h (original)
+++ lld/branches/release_80/wasm/Symbols.h Tue Feb 12 04:24:52 2019
@@ -149,13 +149,19 @@ public:
 
 class UndefinedFunction : public FunctionSymbol {
 public:
-  UndefinedFunction(StringRef Name, uint32_t Flags, InputFile *File = nullptr,
+  UndefinedFunction(StringRef Name, StringRef ImportName,
+                    StringRef ImportModule, uint32_t Flags,
+                    InputFile *File = nullptr,
                     const WasmSignature *Type = nullptr)
-      : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type) {}
+      : FunctionSymbol(Name, UndefinedFunctionKind, Flags, File, Type),
+        ImportName(ImportName), ImportModule(ImportModule) {}
 
   static bool classof(const Symbol *S) {
     return S->kind() == UndefinedFunctionKind;
   }
+
+  StringRef ImportName;
+  StringRef ImportModule;
 };
 
 class SectionSymbol : public Symbol {
@@ -261,13 +267,18 @@ public:
 
 class UndefinedGlobal : public GlobalSymbol {
 public:
-  UndefinedGlobal(StringRef Name, uint32_t Flags, InputFile *File = nullptr,
+  UndefinedGlobal(StringRef Name, StringRef ImportName, StringRef ImportModule,
+                  uint32_t Flags, InputFile *File = nullptr,
                   const WasmGlobalType *Type = nullptr)
-      : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, Type) {}
+      : GlobalSymbol(Name, UndefinedGlobalKind, Flags, File, Type),
+        ImportName(ImportName), ImportModule(ImportModule) {}
 
   static bool classof(const Symbol *S) {
     return S->kind() == UndefinedGlobalKind;
   }
+
+  StringRef ImportName;
+  StringRef ImportModule;
 };
 
 // Wasm events are features that suspend the current execution and transfer the

Modified: lld/branches/release_80/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/Writer.cpp?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/Writer.cpp (original)
+++ lld/branches/release_80/wasm/Writer.cpp Tue Feb 12 04:24:52 2019
@@ -39,8 +39,9 @@ using namespace llvm::wasm;
 using namespace lld;
 using namespace lld::wasm;
 
-static constexpr int kStackAlignment = 16;
-static constexpr const char *kFunctionTableName = "__indirect_function_table";
+static constexpr int StackAlignment = 16;
+static constexpr const char *FunctionTableName = "__indirect_function_table";
+const char *lld::wasm::DefaultModule = "env";
 
 namespace {
 
@@ -155,7 +156,7 @@ void Writer::createImportSection() {
 
   if (Config->ImportMemory) {
     WasmImport Import;
-    Import.Module = "env";
+    Import.Module = DefaultModule;
     Import.Field = "memory";
     Import.Kind = WASM_EXTERNAL_MEMORY;
     Import.Memory.Flags = 0;
@@ -172,8 +173,8 @@ void Writer::createImportSection() {
   if (Config->ImportTable) {
     uint32_t TableSize = TableBase + IndirectFunctions.size();
     WasmImport Import;
-    Import.Module = "env";
-    Import.Field = kFunctionTableName;
+    Import.Module = DefaultModule;
+    Import.Field = FunctionTableName;
     Import.Kind = WASM_EXTERNAL_TABLE;
     Import.Table.ElemType = WASM_TYPE_FUNCREF;
     Import.Table.Limits = {0, TableSize, 0};
@@ -182,8 +183,17 @@ void Writer::createImportSection() {
 
   for (const Symbol *Sym : ImportedSymbols) {
     WasmImport Import;
-    Import.Module = "env";
-    Import.Field = Sym->getName();
+    if (auto *F = dyn_cast<UndefinedFunction>(Sym)) {
+      Import.Field = F->ImportName;
+      Import.Module = F->ImportModule;
+    } else if (auto *G = dyn_cast<UndefinedGlobal>(Sym)) {
+      Import.Field = G->ImportName;
+      Import.Module = G->ImportModule;
+    } else {
+      Import.Field = Sym->getName();
+      Import.Module = DefaultModule;
+    }
+
     if (auto *FunctionSym = dyn_cast<FunctionSymbol>(Sym)) {
       Import.Kind = WASM_EXTERNAL_FUNCTION;
       Import.SigIndex = lookupType(*FunctionSym->Signature);
@@ -441,6 +451,13 @@ static uint32_t getWasmFlags(const Symbo
     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;
 }
 
@@ -506,15 +523,18 @@ void Writer::createLinkingSection() {
 
       if (auto *F = dyn_cast<FunctionSymbol>(Sym)) {
         writeUleb128(Sub.OS, F->getFunctionIndex(), "index");
-        if (Sym->isDefined())
+        if (Sym->isDefined() ||
+            (Flags & WASM_SYMBOL_EXPLICIT_NAME) != 0)
           writeStr(Sub.OS, Sym->getName(), "sym name");
       } else if (auto *G = dyn_cast<GlobalSymbol>(Sym)) {
         writeUleb128(Sub.OS, G->getGlobalIndex(), "index");
-        if (Sym->isDefined())
+        if (Sym->isDefined() ||
+            (Flags & WASM_SYMBOL_EXPLICIT_NAME) != 0)
           writeStr(Sub.OS, Sym->getName(), "sym name");
       } else if (auto *E = dyn_cast<EventSymbol>(Sym)) {
         writeUleb128(Sub.OS, E->getEventIndex(), "index");
-        if (Sym->isDefined())
+        if (Sym->isDefined() ||
+            (Flags & WASM_SYMBOL_EXPLICIT_NAME) != 0)
           writeStr(Sub.OS, Sym->getName(), "sym name");
       } else if (isa<DataSymbol>(Sym)) {
         writeStr(Sub.OS, Sym->getName(), "sym name");
@@ -663,9 +683,9 @@ void Writer::layoutMemory() {
   auto PlaceStack = [&]() {
     if (Config->Relocatable || Config->Shared)
       return;
-    MemoryPtr = alignTo(MemoryPtr, kStackAlignment);
-    if (Config->ZStackSize != alignTo(Config->ZStackSize, kStackAlignment))
-      error("stack size must be " + Twine(kStackAlignment) + "-byte aligned");
+    MemoryPtr = alignTo(MemoryPtr, StackAlignment);
+    if (Config->ZStackSize != alignTo(Config->ZStackSize, StackAlignment))
+      error("stack size must be " + Twine(StackAlignment) + "-byte aligned");
     log("mem: stack size  = " + Twine(Config->ZStackSize));
     log("mem: stack base  = " + Twine(MemoryPtr));
     MemoryPtr += Config->ZStackSize;
@@ -814,7 +834,7 @@ void Writer::calculateExports() {
     Exports.push_back(WasmExport{"memory", WASM_EXTERNAL_MEMORY, 0});
 
   if (!Config->Relocatable && Config->ExportTable)
-    Exports.push_back(WasmExport{kFunctionTableName, WASM_EXTERNAL_TABLE, 0});
+    Exports.push_back(WasmExport{FunctionTableName, WASM_EXTERNAL_TABLE, 0});
 
   unsigned FakeGlobalIndex = NumImportedGlobals + InputGlobals.size();
 
@@ -858,40 +878,42 @@ void Writer::assignSymtab() {
   StringMap<uint32_t> SectionSymbolIndices;
 
   unsigned SymbolIndex = SymtabEntries.size();
-  for (ObjFile *File : Symtab->ObjectFiles) {
-    LLVM_DEBUG(dbgs() << "Symtab entries: " << File->getName() << "\n");
-    for (Symbol *Sym : File->getSymbols()) {
-      if (Sym->getFile() != File)
-        continue;
-
-      if (auto *S = dyn_cast<SectionSymbol>(Sym)) {
-        StringRef Name = S->getName();
-        if (CustomSectionMapping.count(Name) == 0)
-          continue;
-
-        auto SSI = SectionSymbolIndices.find(Name);
-        if (SSI != SectionSymbolIndices.end()) {
-          Sym->setOutputSymbolIndex(SSI->second);
-          continue;
-        }
 
-        SectionSymbolIndices[Name] = SymbolIndex;
-        CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym);
-
-        Sym->markLive();
+  auto AddSymbol = [&](Symbol *Sym) {
+    if (auto *S = dyn_cast<SectionSymbol>(Sym)) {
+      StringRef Name = S->getName();
+      if (CustomSectionMapping.count(Name) == 0)
+        return;
+
+      auto SSI = SectionSymbolIndices.find(Name);
+      if (SSI != SectionSymbolIndices.end()) {
+        Sym->setOutputSymbolIndex(SSI->second);
+        return;
       }
 
-      // (Since this is relocatable output, GC is not performed so symbols must
-      // be live.)
-      assert(Sym->isLive());
-      Sym->setOutputSymbolIndex(SymbolIndex++);
-      SymtabEntries.emplace_back(Sym);
+      SectionSymbolIndices[Name] = SymbolIndex;
+      CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym);
+
+      Sym->markLive();
     }
-  }
 
-  // For the moment, relocatable output doesn't contain any synthetic functions,
-  // so no need to look through the Symtab for symbols not referenced by
-  // Symtab->ObjectFiles.
+    // (Since this is relocatable output, GC is not performed so symbols must
+    // be live.)
+    assert(Sym->isLive());
+    Sym->setOutputSymbolIndex(SymbolIndex++);
+    SymtabEntries.emplace_back(Sym);
+  };
+
+  for (Symbol *Sym : Symtab->getSymbols())
+    if (!Sym->isLazy())
+      AddSymbol(Sym);
+
+  for (ObjFile *File : Symtab->ObjectFiles) {
+    LLVM_DEBUG(dbgs() << "Local symtab entries: " << File->getName() << "\n");
+    for (Symbol *Sym : File->getSymbols())
+      if (Sym->isLocal())
+        AddSymbol(Sym);
+  }
 }
 
 uint32_t Writer::lookupType(const WasmSignature &Sig) {

Modified: lld/branches/release_80/wasm/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_80/wasm/Writer.h?rev=353833&r1=353832&r2=353833&view=diff
==============================================================================
--- lld/branches/release_80/wasm/Writer.h (original)
+++ lld/branches/release_80/wasm/Writer.h Tue Feb 12 04:24:52 2019
@@ -15,6 +15,8 @@ namespace wasm {
 
 void writeResult();
 
+extern const char *DefaultModule;
+
 } // namespace wasm
 } // namespace lld
 




More information about the llvm-branch-commits mailing list