Index: test/wasm/alias.ll =================================================================== --- test/wasm/alias.ll +++ test/wasm/alias.ll @@ -55,10 +55,10 @@ ; CHECK-NEXT: - Name: memory ; CHECK-NEXT: Kind: MEMORY ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: start_alias +; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: _start +; CHECK-NEXT: - Name: start_alias ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 ; CHECK-NEXT: - Name: __heap_base Index: test/wasm/archive.ll =================================================================== --- test/wasm/archive.ll +++ test/wasm/archive.ll @@ -31,6 +31,7 @@ ; CHECK: 00000003 T _start ; CHECK-NEXT: 00000001 T bar ; CHECK-NEXT: 00000002 T foo +; CHECK-NEXT: U missing_func ; Verify that symbols from unused objects don't appear in the symbol table ; CHECK-NOT: hello Index: test/wasm/data-layout.ll =================================================================== --- test/wasm/data-layout.ll +++ test/wasm/data-layout.ll @@ -64,7 +64,7 @@ ; RELOC: - Type: DATA ; RELOC-NEXT: Relocations: ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 -; RELOC-NEXT: Index: 3 +; RELOC-NEXT: Index: 5 ; RELOC-NEXT: Offset: 0x00000018 ; RELOC-NEXT: Segments: ; RELOC-NEXT: - SectionOffset: 6 Index: test/wasm/init-fini.ll =================================================================== --- test/wasm/init-fini.ll +++ test/wasm/init-fini.ll @@ -150,27 +150,27 @@ ; RELOC-NEXT: Flags: [ BINDING_LOCAL ] ; RELOC-NEXT: InitFunctions: ; RELOC-NEXT: - Priority: 101 -; RELOC-NEXT: FunctionIndex: 0 +; RELOC-NEXT: FunctionIndex: 2 ; RELOC-NEXT: - Priority: 101 -; RELOC-NEXT: FunctionIndex: 1 +; RELOC-NEXT: FunctionIndex: 3 ; RELOC-NEXT: - Priority: 101 -; RELOC-NEXT: FunctionIndex: 7 +; RELOC-NEXT: FunctionIndex: 9 ; RELOC-NEXT: - Priority: 101 -; RELOC-NEXT: FunctionIndex: 11 +; RELOC-NEXT: FunctionIndex: 13 ; RELOC-NEXT: - Priority: 101 -; RELOC-NEXT: FunctionIndex: 14 -; RELOC-NEXT: - Priority: 202 -; RELOC-NEXT: FunctionIndex: 11 -; RELOC-NEXT: - Priority: 202 ; RELOC-NEXT: FunctionIndex: 16 -; RELOC-NEXT: - Priority: 1001 -; RELOC-NEXT: FunctionIndex: 0 -; RELOC-NEXT: - Priority: 1001 -; RELOC-NEXT: FunctionIndex: 10 -; RELOC-NEXT: - Priority: 2002 -; RELOC-NEXT: FunctionIndex: 11 -; RELOC-NEXT: - Priority: 2002 +; RELOC-NEXT: - Priority: 202 +; RELOC-NEXT: FunctionIndex: 13 +; RELOC-NEXT: - Priority: 202 ; RELOC-NEXT: FunctionIndex: 18 +; RELOC-NEXT: - Priority: 1001 +; RELOC-NEXT: FunctionIndex: 2 +; RELOC-NEXT: - Priority: 1001 +; RELOC-NEXT: FunctionIndex: 12 +; RELOC-NEXT: - Priority: 2002 +; RELOC-NEXT: FunctionIndex: 13 +; RELOC-NEXT: - Priority: 2002 +; RELOC-NEXT: FunctionIndex: 20 ; RELOC-NEXT: - Type: CUSTOM ; RELOC-NEXT: Name: name ; RELOC-NEXT: FunctionNames: Index: test/wasm/locals-duplicate.test =================================================================== --- test/wasm/locals-duplicate.test +++ test/wasm/locals-duplicate.test @@ -358,13 +358,13 @@ ; RELOC-NEXT: - Type: CODE ; RELOC-NEXT: Relocations: ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; RELOC-NEXT: Index: 0 +; RELOC-NEXT: Index: 18 ; RELOC-NEXT: Offset: 0x00000013 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 19 ; RELOC-NEXT: Offset: 0x0000001C ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; RELOC-NEXT: Index: 2 +; RELOC-NEXT: Index: 20 ; RELOC-NEXT: Offset: 0x00000025 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB ; RELOC-NEXT: Index: 0 @@ -376,13 +376,13 @@ ; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Offset: 0x00000040 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; RELOC-NEXT: Index: 3 +; RELOC-NEXT: Index: 21 ; RELOC-NEXT: Offset: 0x00000058 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; RELOC-NEXT: Index: 4 +; RELOC-NEXT: Index: 22 ; RELOC-NEXT: Offset: 0x00000061 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; RELOC-NEXT: Index: 5 +; RELOC-NEXT: Index: 23 ; RELOC-NEXT: Offset: 0x0000006A ; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB ; RELOC-NEXT: Index: 9 Index: test/wasm/many-functions.ll =================================================================== --- test/wasm/many-functions.ll +++ test/wasm/many-functions.ll @@ -19,385 +19,385 @@ ; CHECK: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000008 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000014 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000020 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000002C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000038 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000044 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000050 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000005C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000068 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000074 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000080 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000008C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000098 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000A4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000B0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000BC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000C8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000D4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000E0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000EC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000000F8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000104 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000110 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000011C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000128 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000134 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000140 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000014C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000158 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000164 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000170 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000017C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000188 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000194 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001A0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001AC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001B8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001C4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001D0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001DC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001E8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000001F4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000200 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000020C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000218 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000224 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000230 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000023C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000248 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000254 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000260 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000026C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000278 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000284 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000290 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000029C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002A8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002B4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002C0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002CC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002D8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002E4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002F0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000002FC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000308 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000314 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000320 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000032C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000338 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000344 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000350 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000035C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000368 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000374 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000380 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000038C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000398 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003A4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003B0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003BC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003C8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003D4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003E0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003EC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000003F8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000404 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000410 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000041C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000428 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000434 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000440 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000044C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000458 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000464 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000470 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000047C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000488 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000494 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004A0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004AC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004B8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004C4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004D0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004DC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004E8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000004F4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000500 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000050C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000518 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000524 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000530 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000053C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000548 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000554 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000560 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000056C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000578 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000584 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x00000590 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x0000059C ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005A8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005B4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005C0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005CC ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005D8 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005E4 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 130 ; CHECK-NEXT: Offset: 0x000005F0 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_LEB ; CHECK-NEXT: Index: 1 Index: test/wasm/relocatable.ll =================================================================== --- test/wasm/relocatable.ll +++ test/wasm/relocatable.ll @@ -152,7 +152,7 @@ ; CHECK-NEXT: - Type: CODE ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; CHECK-NEXT: Index: 1 +; CHECK-NEXT: Index: 7 ; CHECK-NEXT: Offset: 0x00000004 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB ; CHECK-NEXT: Index: 0 @@ -164,7 +164,7 @@ ; CHECK-NEXT: Index: 2 ; CHECK-NEXT: Offset: 0x0000001A ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_SLEB -; CHECK-NEXT: Index: 2 +; CHECK-NEXT: Index: 8 ; CHECK-NEXT: Offset: 0x00000026 ; CHECK-NEXT: Functions: ; CHECK-NEXT: - Index: 3 @@ -179,7 +179,7 @@ ; CHECK-NEXT: - Type: DATA ; CHECK-NEXT: Relocations: ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32 -; CHECK-NEXT: Index: 4 +; CHECK-NEXT: Index: 5 ; CHECK-NEXT: Offset: 0x00000012 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_I32 ; CHECK-NEXT: Index: 1 @@ -188,7 +188,7 @@ ; CHECK-NEXT: Index: 2 ; CHECK-NEXT: Offset: 0x00000024 ; CHECK-NEXT: - Type: R_WEBASSEMBLY_MEMORY_ADDR_I32 -; CHECK-NEXT: Index: 0 +; CHECK-NEXT: Index: 3 ; CHECK-NEXT: Offset: 0x0000002D ; CHECK-NEXT: Segments: ; CHECK-NEXT: - SectionOffset: 6 Index: test/wasm/weak-alias.ll =================================================================== --- test/wasm/weak-alias.ll +++ test/wasm/weak-alias.ll @@ -62,9 +62,6 @@ ; CHECK-NEXT: - Name: _start ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: - Name: alias_fn -; CHECK-NEXT: Kind: FUNCTION -; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: direct_fn ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 1 @@ -80,6 +77,9 @@ ; CHECK-NEXT: - Name: call_direct_ptr ; CHECK-NEXT: Kind: FUNCTION ; CHECK-NEXT: Index: 5 +; CHECK-NEXT: - Name: alias_fn +; CHECK-NEXT: Kind: FUNCTION +; CHECK-NEXT: Index: 1 ; CHECK-NEXT: - Name: __heap_base ; CHECK-NEXT: Kind: GLOBAL ; CHECK-NEXT: Index: 1 @@ -174,9 +174,6 @@ ; RELOC-NEXT: - Name: _start ; RELOC-NEXT: Kind: FUNCTION ; RELOC-NEXT: Index: 0 -; RELOC-NEXT: - Name: alias_fn -; RELOC-NEXT: Kind: FUNCTION -; RELOC-NEXT: Index: 1 ; RELOC-NEXT: - Name: direct_fn ; RELOC-NEXT: Kind: FUNCTION ; RELOC-NEXT: Index: 1 @@ -192,6 +189,9 @@ ; RELOC-NEXT: - Name: call_direct_ptr ; RELOC-NEXT: Kind: FUNCTION ; RELOC-NEXT: Index: 5 +; RELOC-NEXT: - Name: alias_fn +; RELOC-NEXT: Kind: FUNCTION +; RELOC-NEXT: Index: 1 ; RELOC-NEXT: - Type: ELEM ; RELOC-NEXT: Segments: ; RELOC-NEXT: - Offset: @@ -201,13 +201,13 @@ ; RELOC-NEXT: - Type: CODE ; RELOC-NEXT: Relocations: ; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 7 ; RELOC-NEXT: Offset: 0x00000004 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Offset: 0x00000012 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 7 ; RELOC-NEXT: Offset: 0x0000001B ; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB ; RELOC-NEXT: Index: 0 @@ -216,10 +216,10 @@ ; RELOC-NEXT: Index: 0 ; RELOC-NEXT: Offset: 0x00000031 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 7 ; RELOC-NEXT: Offset: 0x00000039 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 7 ; RELOC-NEXT: Offset: 0x00000042 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB ; RELOC-NEXT: Index: 0 @@ -231,10 +231,10 @@ ; RELOC-NEXT: Index: 0 ; RELOC-NEXT: Offset: 0x00000067 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_TABLE_INDEX_SLEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Offset: 0x0000006F ; RELOC-NEXT: - Type: R_WEBASSEMBLY_FUNCTION_INDEX_LEB -; RELOC-NEXT: Index: 1 +; RELOC-NEXT: Index: 2 ; RELOC-NEXT: Offset: 0x00000078 ; RELOC-NEXT: - Type: R_WEBASSEMBLY_GLOBAL_INDEX_LEB ; RELOC-NEXT: Index: 0 Index: wasm/InputFiles.h =================================================================== --- wasm/InputFiles.h +++ wasm/InputFiles.h @@ -93,7 +93,6 @@ void dumpInfo() const; - uint32_t relocateFunctionIndex(uint32_t Original) const; uint32_t calcNewIndex(const WasmRelocation &Reloc) const; uint32_t calcNewValue(const WasmRelocation &Reloc) const; @@ -105,15 +104,16 @@ std::vector Functions; ArrayRef getSymbols() const { return Symbols; } - - Symbol *getFunctionSymbol(uint32_t Index) const { - return FunctionSymbols[Index]; - } + Symbol *getFunctionSymbol(uint32_t Index) const; + Symbol *getGlobalSymbol(uint32_t Index) const; private: uint32_t relocateVirtualAddress(uint32_t Index) const; uint32_t relocateTypeIndex(uint32_t Original) const; + uint32_t relocateFunctionIndex(uint32_t Original) const; uint32_t relocateGlobalIndex(uint32_t Original) const; + uint32_t relocateFunctionSymbolIndex(uint32_t Original) const; + uint32_t relocateGlobalSymbolIndex(uint32_t Original) const; uint32_t relocateTableIndex(uint32_t Original) const; Symbol *createDefined(const WasmSymbol &Sym, Symbol::Kind Kind, @@ -132,12 +132,6 @@ // List of all symbols referenced or defined by this file. std::vector Symbols; - // List of all function symbols indexed by the function index space - std::vector FunctionSymbols; - - // List of all global symbols indexed by the global index space - std::vector GlobalSymbols; - uint32_t NumGlobalImports = 0; uint32_t NumFunctionImports = 0; std::unique_ptr WasmObj; Index: wasm/InputFiles.cpp =================================================================== --- wasm/InputFiles.cpp +++ wasm/InputFiles.cpp @@ -44,40 +44,55 @@ void ObjFile::dumpInfo() const { log("info for: " + getName() + "\n" + - " Total Functions : " + Twine(FunctionSymbols.size()) + "\n" + - " Total Globals : " + Twine(GlobalSymbols.size()) + "\n" + - " Function Imports : " + Twine(NumFunctionImports) + "\n" + - " Global Imports : " + Twine(NumGlobalImports) + "\n"); + " Symbols : " + Twine(Symbols.size()) + "\n"); } -uint32_t ObjFile::relocateVirtualAddress(uint32_t GlobalIndex) const { - return GlobalSymbols[GlobalIndex]->getVirtualAddress(); -} - -uint32_t ObjFile::relocateFunctionIndex(uint32_t Original) const { - Symbol *Sym = FunctionSymbols[Original]; - uint32_t Index = Sym->getOutputIndex(); - DEBUG(dbgs() << "relocateFunctionIndex: " << toString(*Sym) << ": " - << Original << " -> " << Index << "\n"); - return Index; +uint32_t ObjFile::relocateVirtualAddress(uint32_t Index) const { + return getGlobalSymbol(Index)->getVirtualAddress(); } uint32_t ObjFile::relocateTypeIndex(uint32_t Original) const { return TypeMap[Original]; } -uint32_t ObjFile::relocateTableIndex(uint32_t Original) const { - Symbol *Sym = FunctionSymbols[Original]; - uint32_t Index = Sym->hasTableIndex() ? Sym->getTableIndex() : 0; - DEBUG(dbgs() << "relocateTableIndex: " << toString(*Sym) << ": " << Original - << " -> " << Index << "\n"); +uint32_t ObjFile::relocateFunctionIndex(uint32_t Original) const { + Symbol *Sym = getFunctionSymbol(Original); + uint32_t Index = Sym->hasOutputIndex() ? Sym->getOutputIndex() : 0; + DEBUG(dbgs() << "relocateFunctionWasmIndex: " << toString(*Sym) << ": " + << Original << " -> " << Index << "\n"); return Index; } uint32_t ObjFile::relocateGlobalIndex(uint32_t Original) const { - Symbol *Sym = GlobalSymbols[Original]; - uint32_t Index = Sym->hasOutputIndex() ? Sym->getOutputIndex() : 0; - DEBUG(dbgs() << "relocateGlobalIndex: " << toString(*Sym) << ": " << Original + Symbol *Sym = getGlobalSymbol(Original); + uint32_t Index = Sym->hasTableIndex() ? Sym->getOutputIndex() : 0; + DEBUG(dbgs() << "relocateGlobalWasmIndex: " << toString(*Sym) << ": " << Original + << " -> " << Index << "\n"); + return Index; +} + +uint32_t ObjFile::relocateFunctionSymbolIndex(uint32_t Original) const { + Symbol *Sym = getFunctionSymbol(Original); + uint32_t Index = Sym->getOutputSymbolIndex(); + DEBUG(dbgs() << "relocateFunctionSymbolIndex: " << toString(*Sym) << ": " + << Original << " -> " << Index << "\n"); + return Index; +} + +uint32_t ObjFile::relocateGlobalSymbolIndex(uint32_t Original) const { + Symbol *Sym = getGlobalSymbol(Original); + uint32_t Index = Sym->getOutputSymbolIndex(); + DEBUG(dbgs() << "relocateGlobalSymbolIndex: " << toString(*Sym) << ": " << Original + << " -> " << Index << "\n"); + return Index; +} + +uint32_t ObjFile::relocateTableIndex(uint32_t Original) const { + Symbol *Sym = getFunctionSymbol(Original); + // The null case is possible, if you take the address of a weak function + // that's simply not supplied. + uint32_t Index = Sym->hasTableIndex() ? Sym->getTableIndex() : 0; + DEBUG(dbgs() << "relocateTableIndex: " << toString(*Sym) << ": " << Original << " -> " << Index << "\n"); return Index; } @@ -93,12 +108,12 @@ case R_WEBASSEMBLY_FUNCTION_INDEX_LEB: case R_WEBASSEMBLY_TABLE_INDEX_I32: case R_WEBASSEMBLY_TABLE_INDEX_SLEB: - return relocateFunctionIndex(Reloc.Index); + return relocateFunctionSymbolIndex(Reloc.Index); case R_WEBASSEMBLY_GLOBAL_INDEX_LEB: case R_WEBASSEMBLY_MEMORY_ADDR_LEB: case R_WEBASSEMBLY_MEMORY_ADDR_SLEB: case R_WEBASSEMBLY_MEMORY_ADDR_I32: - return relocateGlobalIndex(Reloc.Index); + return relocateGlobalSymbolIndex(Reloc.Index); default: llvm_unreachable("unknown relocation type"); } @@ -170,8 +185,9 @@ // Get the value stored in the wasm global represented by this symbol. // This represents the virtual address of the symbol in the input file. uint32_t ObjFile::getGlobalValue(const WasmSymbol &Sym) const { + assert(Sym.WasmIndex >= NumGlobalImports); const WasmGlobal &Global = - getWasmObj()->globals()[Sym.ElementIndex - NumGlobalImports]; + getWasmObj()->globals()[Sym.WasmIndex - NumGlobalImports]; assert(Global.Type == llvm::wasm::WASM_TYPE_I32); return Global.InitExpr.Value.Int32; } @@ -185,7 +201,8 @@ } InputFunction *ObjFile::getFunction(const WasmSymbol &Sym) const { - uint32_t FunctionIndex = Sym.ElementIndex - NumFunctionImports; + assert(Sym.WasmIndex >= NumFunctionImports); + uint32_t FunctionIndex = Sym.WasmIndex - NumFunctionImports; return Functions[FunctionIndex]; } @@ -194,34 +211,31 @@ return !Comdat.empty() && Symtab->findComdat(Comdat) != this; } +Symbol *ObjFile::getFunctionSymbol(uint32_t Index) const { + Symbol *Sym = Symbols[Index]; + assert(Sym->isFunction()); + return Sym; +} + +Symbol *ObjFile::getGlobalSymbol(uint32_t Index) const { + Symbol *Sym = Symbols[Index]; + assert(Sym->isGlobal()); + return Sym; +} + void ObjFile::initializeSymbols() { Symbols.reserve(WasmObj->getNumberOfSymbols()); - for (const WasmImport &Import : WasmObj->imports()) { - switch (Import.Kind) { - case WASM_EXTERNAL_FUNCTION: - ++NumFunctionImports; - break; - case WASM_EXTERNAL_GLOBAL: - ++NumGlobalImports; - break; - } - } - - FunctionSymbols.resize(NumFunctionImports + WasmObj->functions().size()); - GlobalSymbols.resize(NumGlobalImports + WasmObj->globals().size()); + NumFunctionImports = WasmObj->getNumImportedFunctions(); + NumGlobalImports = WasmObj->getNumImportedGlobals(); ArrayRef Funcs = WasmObj->functions(); ArrayRef FuncTypes = WasmObj->functionTypes(); ArrayRef Types = WasmObj->types(); - ArrayRef Globals = WasmObj->globals(); for (const auto &C : WasmObj->comdats()) Symtab->addComdat(C, this); - FunctionSymbols.resize(NumFunctionImports + Funcs.size()); - GlobalSymbols.resize(NumGlobalImports + Globals.size()); - for (const WasmSegment &S : WasmObj->dataSegments()) { InputSegment *Seg = make(S, this); Seg->copyRelocations(*DataSection); @@ -274,24 +288,7 @@ } Symbols.push_back(S); - if (WasmSym.isFunction()) { - FunctionSymbols[WasmSym.ElementIndex] = S; - if (WasmSym.HasAltIndex) - FunctionSymbols[WasmSym.AltIndex] = S; - } else { - GlobalSymbols[WasmSym.ElementIndex] = S; - if (WasmSym.HasAltIndex) - GlobalSymbols[WasmSym.AltIndex] = S; - } } - - DEBUG(for (size_t I = 0; I < FunctionSymbols.size(); ++I) - assert(FunctionSymbols[I] != nullptr); - for (size_t I = 0; I < GlobalSymbols.size(); ++I) - assert(GlobalSymbols[I] != nullptr);); - - DEBUG(dbgs() << "Functions : " << FunctionSymbols.size() << "\n"); - DEBUG(dbgs() << "Globals : " << GlobalSymbols.size() << "\n"); } Symbol *ObjFile::createUndefined(const WasmSymbol &Sym, Symbol::Kind Kind, Index: wasm/Symbols.h =================================================================== --- wasm/Symbols.h +++ wasm/Symbols.h @@ -73,10 +73,17 @@ // Returns true if an output index has been set for this symbol bool hasOutputIndex() const; - // Set the output index of the symbol (in the function or global index - // space of the output object. + // Set the output index of the symbol, in the function or global Wasm + // index space of the output object - that is, for defined symbols only, + // its position in the list of defined function bodies / global decls. void setOutputIndex(uint32_t Index); + // Get/set the output symbol index, in the function or global Symbol index + // space - that is, the position in the list of imports+exports. This is + // only used for relocatable output. + uint32_t getOutputSymbolIndex() const; + void setOutputSymbolIndex(uint32_t Index); + uint32_t getTableIndex() const; // Returns true if a table index has been set for this symbol @@ -110,6 +117,7 @@ const InputSegment *Segment = nullptr; InputFunction *Function = nullptr; llvm::Optional OutputIndex; + llvm::Optional OutputSymbolIndex; llvm::Optional TableIndex; const WasmSignature *FunctionType = nullptr; }; Index: wasm/Symbols.cpp =================================================================== --- wasm/Symbols.cpp +++ wasm/Symbols.cpp @@ -54,6 +54,10 @@ return OutputIndex.getValue(); } +uint32_t Symbol::getOutputSymbolIndex() const { + return OutputSymbolIndex.getValue(); +} + void Symbol::setVirtualAddress(uint32_t Value) { DEBUG(dbgs() << "setVirtualAddress " << Name << " -> " << Value << "\n"); assert(isGlobal()); @@ -67,6 +71,12 @@ OutputIndex = Index; } +void Symbol::setOutputSymbolIndex(uint32_t Index) { + DEBUG(dbgs() << "setOutputSymbolIndex " << Name << " -> " << Index << "\n"); + assert(!OutputSymbolIndex.hasValue()); + OutputSymbolIndex = Index; +} + uint32_t Symbol::getTableIndex() const { if (Function) return Function->getTableIndex(); Index: wasm/Writer.cpp =================================================================== --- wasm/Writer.cpp +++ wasm/Writer.cpp @@ -69,6 +69,13 @@ StringRef FieldName; // may not match the Symbol name }; +// An init entry to be written to either the synthentic init func or the +// linking metadata. +struct WasmInitEntry { + const Symbol *Sym; + uint32_t Priority; +}; + // The writer writes a SymbolTable result to a file. class Writer { public: @@ -119,13 +126,14 @@ std::vector Types; DenseMap TypeIndices; - std::vector ImportedFunctions; - std::vector ImportedGlobals; + std::vector ImportedSymbols; + unsigned NumImportedFunctions = 0; + unsigned NumImportedGlobals = 0; std::vector ExportedSymbols; - std::vector DefinedGlobals; + std::vector DefinedGlobals; std::vector DefinedFunctions; std::vector IndirectFunctions; - std::vector InitFunctions; + std::vector InitFunctions; // Elements that are used to construct the final output std::string Header; @@ -152,7 +160,7 @@ } void Writer::createImportSection() { - uint32_t NumImports = ImportedFunctions.size() + ImportedGlobals.size(); + uint32_t NumImports = ImportedSymbols.size(); if (Config->ImportMemory) ++NumImports; @@ -164,15 +172,6 @@ writeUleb128(OS, NumImports, "import count"); - for (const Symbol *Sym : ImportedFunctions) { - WasmImport Import; - Import.Module = "env"; - Import.Field = Sym->getName(); - Import.Kind = WASM_EXTERNAL_FUNCTION; - Import.SigIndex = lookupType(Sym->getFunctionType()); - writeImport(OS, Import); - } - if (Config->ImportMemory) { WasmImport Import; Import.Module = "env"; @@ -183,13 +182,18 @@ writeImport(OS, Import); } - for (const Symbol *Sym : ImportedGlobals) { + for (const Symbol *Sym : ImportedSymbols) { WasmImport Import; Import.Module = "env"; Import.Field = Sym->getName(); - Import.Kind = WASM_EXTERNAL_GLOBAL; - Import.Global.Mutable = false; - Import.Global.Type = WASM_TYPE_I32; + if (Sym->isFunction()) { + Import.Kind = WASM_EXTERNAL_FUNCTION; + Import.SigIndex = lookupType(Sym->getFunctionType()); + } else { + Import.Kind = WASM_EXTERNAL_GLOBAL; + Import.Global.Mutable = false; + Import.Global.Type = WASM_TYPE_I32; + } writeImport(OS, Import); } } @@ -395,9 +399,7 @@ SymbolInfo.emplace_back(ExternalName, Flags); }; // (Imports can't have internal linkage, their names don't need to be budged.) - for (const Symbol *Sym : ImportedFunctions) - addSymInfo(Sym, Sym->getName()); - for (const Symbol *Sym : ImportedGlobals) + for (const Symbol *Sym : ImportedSymbols) addSymInfo(Sym, Sym->getName()); for (const WasmExportEntry &E : ExportedSymbols) addSymInfo(E.Sym, E.FieldName); @@ -428,9 +430,10 @@ SubSection SubSection(WASM_INIT_FUNCS); writeUleb128(SubSection.getStream(), InitFunctions.size(), "num init functions"); - for (const WasmInitFunc &F : InitFunctions) { + for (const WasmInitEntry &F : InitFunctions) { writeUleb128(SubSection.getStream(), F.Priority, "priority"); - writeUleb128(SubSection.getStream(), F.FunctionIndex, "function index"); + writeUleb128(SubSection.getStream(), F.Sym->getOutputSymbolIndex(), + "function index"); } SubSection.finalizeContents(); SubSection.writeToStream(OS); @@ -477,7 +480,7 @@ // Create the custom "name" section containing debug symbol names. void Writer::createNameSection() { - unsigned NumNames = ImportedFunctions.size(); + unsigned NumNames = NumImportedFunctions; for (const InputFunction *F : DefinedFunctions) if (!F->getName().empty()) ++NumNames; @@ -491,10 +494,12 @@ raw_ostream &OS = FunctionSubsection.getStream(); writeUleb128(OS, NumNames, "name count"); - // Names must appear in function index order. As it happens ImportedFunctions - // and DefinedFunctions are numbers in order with imported functions coming + // Names must appear in function index order. As it happens ImportedSymbols + // and DefinedFunctions are numbered in order with imported functions coming // first. - for (const Symbol *S : ImportedFunctions) { + for (const Symbol *S : ImportedSymbols) { + if (!S->isFunction()) + continue; writeUleb128(OS, S->getOutputIndex(), "import index"); writeStr(OS, S->getName(), "symbol name"); } @@ -606,13 +611,13 @@ if (!Sym->isUndefined() || (Sym->isWeak() && !Config->Relocatable)) continue; - if (Sym->isFunction()) { - Sym->setOutputIndex(ImportedFunctions.size()); - ImportedFunctions.push_back(Sym); - } else { - Sym->setOutputIndex(ImportedGlobals.size()); - ImportedGlobals.push_back(Sym); - } + Sym->setOutputIndex(ImportedSymbols.size()); + Sym->setOutputSymbolIndex(ImportedSymbols.size()); + ImportedSymbols.emplace_back(Sym); + if (Sym->isFunction()) + ++NumImportedFunctions; + else + ++NumImportedGlobals; } } @@ -638,9 +643,12 @@ } }; - if (Config->CtorSymbol && (!Config->CtorSymbol->isHidden() || ExportHidden)) + unsigned SymbolIndex = ImportedSymbols.size(); + if (Config->CtorSymbol && (!Config->CtorSymbol->isHidden() || ExportHidden)) { + Config->CtorSymbol->setOutputSymbolIndex(SymbolIndex++); ExportedSymbols.emplace_back( WasmExportEntry{Config->CtorSymbol, Config->CtorSymbol->getName()}); + } for (ObjFile *File : Symtab->ObjectFiles) { for (Symbol *Sym : File->getSymbols()) { @@ -653,16 +661,18 @@ if ((Sym->isHidden() || Sym->isLocal()) && !ExportHidden) continue; + Sym->setOutputSymbolIndex(SymbolIndex++); ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)}); } } - for (const Symbol *Sym : DefinedGlobals) { + for (Symbol *Sym : DefinedGlobals) { // Can't export the SP right now because its mutable, and mutuable globals // are yet supported in the official binary format. // TODO(sbc): Remove this if/when the "mutable global" proposal is accepted. if (Sym == Config->StackPointerSymbol) continue; + Sym->setOutputSymbolIndex(SymbolIndex++); ExportedSymbols.emplace_back(WasmExportEntry{Sym, BudgeLocalName(Sym)}); } } @@ -698,8 +708,8 @@ } void Writer::assignIndexes() { - uint32_t GlobalIndex = ImportedGlobals.size() + DefinedGlobals.size(); - uint32_t FunctionIndex = ImportedFunctions.size() + DefinedFunctions.size(); + uint32_t GlobalIndex = NumImportedGlobals + DefinedGlobals.size(); + uint32_t FunctionIndex = NumImportedFunctions + DefinedFunctions.size(); if (Config->StackPointerSymbol) { DefinedGlobals.emplace_back(Config->StackPointerSymbol); @@ -805,7 +815,7 @@ // Create synthetic "__wasm_call_ctors" function based on ctor functions // in input object. void Writer::createCtorFunction() { - uint32_t FunctionIndex = ImportedFunctions.size() + DefinedFunctions.size(); + uint32_t FunctionIndex = NumImportedFunctions + DefinedFunctions.size(); Config->CtorSymbol->setOutputIndex(FunctionIndex); // First write the body bytes to a string. @@ -814,9 +824,9 @@ { raw_string_ostream OS(FunctionBody); writeUleb128(OS, 0, "num locals"); - for (const WasmInitFunc &F : InitFunctions) { + for (const WasmInitEntry &F : InitFunctions) { writeU8(OS, OPCODE_CALL, "CALL"); - writeUleb128(OS, F.FunctionIndex, "function index"); + writeUleb128(OS, F.Sym->getOutputIndex(), "function index"); } writeU8(OS, OPCODE_END, "END"); } @@ -843,15 +853,15 @@ const WasmLinkingData &L = File->getWasmObj()->linkingData(); InitFunctions.reserve(InitFunctions.size() + L.InitFunctions.size()); for (const WasmInitFunc &F : L.InitFunctions) - InitFunctions.emplace_back(WasmInitFunc{ - F.Priority, File->relocateFunctionIndex(F.FunctionIndex)}); + InitFunctions.emplace_back(WasmInitEntry{ + File->getFunctionSymbol(F.FunctionIndex), F.Priority}); } // Sort in order of priority (lowest first) so that they are called // in the correct order. - std::sort(InitFunctions.begin(), InitFunctions.end(), - [](const WasmInitFunc &L, const WasmInitFunc &R) { - return L.Priority < R.Priority; - }); + std::stable_sort(InitFunctions.begin(), InitFunctions.end(), + [](const WasmInitEntry &L, const WasmInitEntry &R) { + return L.Priority < R.Priority; + }); } void Writer::run() { @@ -871,10 +881,8 @@ if (errorHandler().Verbose) { log("Defined Functions: " + Twine(DefinedFunctions.size())); log("Defined Globals : " + Twine(DefinedGlobals.size())); - log("Function Imports : " + Twine(ImportedFunctions.size())); - log("Global Imports : " + Twine(ImportedGlobals.size())); - log("Total Imports : " + - Twine(ImportedFunctions.size() + ImportedGlobals.size())); + log("Function Imports : " + Twine(NumImportedFunctions)); + log("Global Imports : " + Twine(NumImportedGlobals)); for (ObjFile *File : Symtab->ObjectFiles) File->dumpInfo(); }