llvm.org GIT mirror llvm / 44818a3
[WebAssembly] Disallow weak undefined globals in the object format This implements https://github.com/WebAssembly/tool-conventions/pull/47 Differential Revision: https://reviews.llvm.org/D44201 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327146 91177308-0d34-0410-b5e6-96231b3b80d8 Nicholas Wilson 1 year, 5 months ago
4 changed file(s) with 35 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
10231023 Imports.push_back(Import);
10241024 WasmIndices[&WS] = NumFunctionImports++;
10251025 } else if (WS.isGlobal()) {
1026 if (WS.isWeak())
1027 report_fatal_error("undefined global symbol cannot be weak");
1028
10261029 wasm::WasmImport Import;
10271030 Import.Module = WS.getModuleName();
10281031 Import.Field = WS.getName();
421421 IsDefined != isDefinedGlobalIndex(Info.ElementIndex))
422422 return make_error("invalid global symbol index",
423423 object_error::parse_failed);
424 if (!IsDefined &&
425 (Info.Flags & wasm::WASM_SYMBOL_BINDING_MASK) ==
426 wasm::WASM_SYMBOL_BINDING_WEAK)
427 return make_error("undefined weak global symbol",
428 object_error::parse_failed);
424429 if (IsDefined) {
425430 Info.Name = readString(Ptr);
426431 unsigned GlobalIndex = Info.ElementIndex - NumImportedGlobals;
0 # RUN: yaml2obj < %s | not obj2yaml 2>&1 | FileCheck %s
1
2 --- !WASM
3 FileHeader:
4 Version: 0x00000001
5 Sections:
6 - Type: IMPORT
7 Imports:
8 - Module: fiz
9 Field: imported_global
10 Kind: GLOBAL
11 GlobalType: I32
12 GlobalMutable: false
13 - Type: CUSTOM
14 Name: linking
15 SymbolTable:
16 - Index: 0
17 Kind: GLOBAL
18 Name: imported_global
19 Flags: [ BINDING_WEAK, UNDEFINED ]
20 Global: 0
21 ...
22
23 # CHECK: Error reading file: : undefined weak global symbol
1717 Field: weak_import_func
1818 Kind: FUNCTION
1919 SigIndex: 0
20 - Module: env
21 Field: weak_import_global
22 Kind: GLOBAL
23 GlobalType: I32
24 GlobalMutable: false
2520 - Type: FUNCTION
2621 FunctionTypes: [ 0 ]
2722 - Type: GLOBAL
2823 Globals:
29 - Index: 1
24 - Index: 0
3025 Type: I32
3126 Mutable: false
3227 InitExpr:
6358 Kind: GLOBAL
6459 Name: weak_defined_global
6560 Flags: [ BINDING_WEAK ]
66 Global: 1
61 Global: 0
6762 - Index: 3
6863 Kind: DATA
6964 Name: weak_import_data
7368 Name: weak_import_func
7469 Flags: [ BINDING_WEAK, UNDEFINED ]
7570 Function: 0
76 - Index: 5
77 Kind: GLOBAL
78 Name: weak_import_global
79 Flags: [ BINDING_WEAK, UNDEFINED ]
80 Global: 0
8171 SegmentInfo:
8272 - Index: 0
8373 Name: .rodata.constantData
8777
8878 # CHECK: 00000000 W weak_defined_data
8979 # CHECK-NEXT: 00000001 W weak_defined_func
90 # CHECK-NEXT: 00000001 W weak_defined_global
80 # CHECK-NEXT: 00000000 W weak_defined_global
9181 # CHECK-NEXT: w weak_import_data
9282 # CHECK-NEXT: w weak_import_func
93 # CHECK-NEXT: w weak_import_global