Commit Graph

282 Commits

Author SHA1 Message Date
Nikolay Nikolov
eaf9a9f1b9 * fixed bug in the application of RELOC_GLOBAL_INDEX_LEB fixups in the wasm internal exe writer 2024-01-01 22:14:39 +02:00
Nikolay Nikolov
ec206cf490 + wasm internal linker: write the exported functions to the export section in the exe writer 2024-01-01 22:05:03 +02:00
Nikolay Nikolov
c4a77a832f + write export section in the wasm internal linker exe writer, only the memory is exported for now 2024-01-01 21:20:37 +02:00
Nikolay Nikolov
d03963afe9 + generate the global section in the wasm internal linker exe writer 2024-01-01 21:11:56 +02:00
Nikolay Nikolov
f48282d7b3 + implemented R_WASM_GLOBAL_INDEX_LEB relocations in the wasm internal linker 2024-01-01 20:09:04 +02:00
Nikolay Nikolov
bbeb98aeef + wasm internal linker: put all wasm global symbols in separate sections,
called .wasm_globals.n_XXX. This allows section-based smartlinking to work on
  global symbols.
2024-01-01 19:06:24 +02:00
Nikolay Nikolov
cd93050d7e * set the size of AT_WASM_GLOBAL symbols to 1 2024-01-01 18:10:20 +02:00
Nikolay Nikolov
ef796906e9 + wasm internal obj reader: add globals to a '.wasm_globals' object section 2024-01-01 18:03:02 +02:00
Nikolay Nikolov
2eae62a6e8 * define the __stack_pointer symbol in a different way, so it doesn't crash during linking 2024-01-01 17:54:59 +02:00
Nikolay Nikolov
167c7bc565 + create relocations for R_WASM_GLOBAL_INDEX_LEB entires in the wasm object reader 2024-01-01 17:46:51 +02:00
Nikolay Nikolov
9ee13f2937 + also define non-imported SYMTAB_GLOBAL symbols in the wasm internal object reader 2024-01-01 17:40:31 +02:00
Nikolay Nikolov
408e388af3 + wasm internal linker: internally define the '__stack_pointer' global symbol 2024-01-01 17:36:52 +02:00
Nikolay Nikolov
880d0333b0 + wasm internal object reader: process SYMTAB_GLOBAL import entries 2024-01-01 17:25:56 +02:00
Nikolay Nikolov
e6a68b28b6 * wasm internal linker: produce an error if an R_WASM_SECTION_OFFSET_I32 or an
R_WASM_TAG_INDEX_LEB relocations is encountered - these aren't implemented,
  and are not required for 'hello, world', so will be done later.
2024-01-01 17:12:07 +02:00
Nikolay Nikolov
4208fc79c7 + implemented R_WASM_MEMORY_ADDR_SLEB and R_WASM_TABLE_INDEX_SLEB relocations in the wasm internal linker 2024-01-01 17:08:36 +02:00
Nikolay Nikolov
b440f57739 + implemented R_WASM_MEMORY_ADDR_LEB relocations in the wasm internal linker 2024-01-01 17:04:35 +02:00
Nikolay Nikolov
5771245d74 + create the Table and Elem sections in the wasm exe writer 2024-01-01 16:56:53 +02:00
Nikolay Nikolov
7a228bccfc + implement R_WASM_TABLE_INDEX_I32 relocations in the wasm internal linker 2024-01-01 16:41:03 +02:00
Nikolay Nikolov
1b2d29ea1a + implemented R_WASM_MEMORY_ADDR_I32 relocations in the wasm internal linker 2024-01-01 16:13:11 +02:00
Nikolay Nikolov
12d7d271d6 + write the data section in the wasm internal linker exe writer 2024-01-01 15:58:17 +02:00
Nikolay Nikolov
b361b41a86 + webassembly internal linker: create separate exe sections for .rodata and .bss 2024-01-01 14:56:33 +02:00
Nikolay Nikolov
dc4689ba1b * wasm internal linker: start the data section at offset 0, as WebAssembly is a Harvard architecture. 2024-01-01 14:44:44 +02:00
Nikolay Nikolov
69ce966691 + implemented RELOC_TYPE_INDEX_LEB relocations in the wasm internal linker 2024-01-01 14:35:10 +02:00
Nikolay Nikolov
0b3238bcd3 * refactor: invert if condition and else statement (reducing the nesting level), because then terminates the function. No functional changes. 2024-01-01 14:04:29 +02:00
Nikolay Nikolov
5845bb9095 * produce an internal error, instead of a warning in case of RELOC_FUNCTION_INDEX_LEB pointing to a function with missing ExeFunctionIndex 2024-01-01 14:03:03 +02:00
Nikolay Nikolov
50986967f5 + wasm internal linker: fill ExeFunctionIndex of alias code symbols as well 2024-01-01 14:01:43 +02:00
Nikolay Nikolov
cf79ca16b4 * only set MainFuncSymbol of code sections to the main (non-alias) symbol 2024-01-01 13:44:36 +02:00
Nikolay Nikolov
c453bac7ad + report an error in case a wasm object file has a code section, without a main symbol 2024-01-01 13:42:24 +02:00
Nikolay Nikolov
e1d56a9944 * wasm internal linker: use the main symbol (without WASM_SYM_EXPLICIT_NAME,
i.e. not an alias) to define code section names in the wasm object reader.
  For example, the section for the INITHEAP function is now called:
    .text.n_SYSTEM_$$_INITHEAP
  instead of
    .text.n__FPC_InitHeap
  (which is based on an explicit alias for the function - '_FPC_InitHeap')
2024-01-01 13:35:23 +02:00
Nikolay Nikolov
7747e1f6c8 + wasm internal linker: write the functions, defined in the current module in the linker map file 2024-01-01 13:20:28 +02:00
Nikolay Nikolov
409de5ac96 + write the import function indexes in the linker map file 2024-01-01 13:13:48 +02:00
Nikolay Nikolov
1c1dbaf776 + partial implementation of RELOC_FUNCTION_INDEX_LEB relocations in the wasm internal linker 2024-01-01 01:05:49 +02:00
Nikolay Nikolov
f4f6a16796 + fill the memory section in the wasm exe writer 2024-01-01 00:39:14 +02:00
Nikolay Nikolov
507e9eb20a + added check for the ExeFunctionIndex inside WriteCodeSegments 2024-01-01 00:15:27 +02:00
Nikolay Nikolov
88a42c3ee0 + write the type indexes correctly 2023-12-31 23:50:53 +02:00
Nikolay Nikolov
f5dbd38b7e * extracted the import preparation to a separate method TWasmExeOutput.PrepareImports 2023-12-31 23:39:26 +02:00
Nikolay Nikolov
946fc370e9 * set TWasmObjSection.MainFuncSymbol in the wasm object reader 2023-12-31 23:32:51 +02:00
Nikolay Nikolov
ac0c187b56 + WebAssembly exe writer: write the code section 2023-12-31 23:29:33 +02:00
Nikolay Nikolov
d9a67bb16d + generate the import section in the wasm exe writer 2023-12-31 22:52:03 +02:00
Nikolay Nikolov
2c72b62a0e + generate and write the Type section in the WebAssembly internal exe writer 2023-12-31 22:47:07 +02:00
Nikolay Nikolov
3c4a1087f3 * writing of the type wasm object section extracted to a method TWasmFuncTypeTable.WriteTo, so it can be reused in the exe writer 2023-12-31 22:43:44 +02:00
Nikolay Nikolov
a387accf81 * WriteWasmBasicType and WriteWasmResultType converted to global functions to allow reuse in the exe writer 2023-12-31 22:39:35 +02:00
Nikolay Nikolov
5583781f47 + initialize TWasmExeOutput.FWasmSections 2023-12-31 22:36:45 +02:00
Nikolay Nikolov
7d6158d5f4 + added and implemented TWasmExeOutput.WriteWasmSection 2023-12-31 22:35:44 +02:00
Nikolay Nikolov
c342a5f473 * converted some helper methods from TWasmObjOutput to global functions, so they can be reused in the exe writer 2023-12-31 22:28:53 +02:00
Nikolay Nikolov
b2f31c4112 + added a section array to the wasm exe writer 2023-12-31 22:27:05 +02:00
Nikolay Nikolov
16c4e0300c + WebAssembly internal linker, exe writer: keep track of exe import functions. Add and fill TWasmObjSymbolLinkingData.ExeFunctionIndex 2023-12-31 22:17:51 +02:00
Nikolay Nikolov
da8ccd64ef + also write the functype of imported functions in the linker map file 2023-12-31 21:50:18 +02:00
Nikolay Nikolov
4f4beb6225 + store the functype in TWasmObjSymbolLinkingData 2023-12-31 21:40:34 +02:00
Nikolay Nikolov
880eb3658a + process the module imports and write them to the map file in TWasmExeOutput.AfterUnusedSectionRemoval 2023-12-31 21:27:21 +02:00
Nikolay Nikolov
541bd66a6c + implemented TWasmExeOutput.GenerateLibraryImports 2023-12-31 21:04:04 +02:00
Nikolay Nikolov
b88b8efbce + WebAssembly object reader: create symbols for imports that have the
WASM_SYM_EXPLICIT_NAME flag set. Save the import module and name info inside
  a new field TWasmObjSymbol.LinkingData.
2023-12-31 20:39:01 +02:00
Nikolay Nikolov
f83223c8b2 * SymbolTable.ObjSym type changed from TObjSymbol to TWasmObjSymbol 2023-12-31 20:28:44 +02:00
Nikolay Nikolov
f30a41359d + added a TWasmFuncTypeTable instance to TWasmExeOutput 2023-12-31 16:50:00 +02:00
Nikolay Nikolov
e695edff98 + initialize TWasmObjData.FFuncTypes in TWasmObjData's constructor 2023-12-31 15:54:52 +02:00
Nikolay Nikolov
0be3fe9ab4 - removed TWasmObjData.AddFuncType, instead call directly [F]FuncTypes.AddOrGetFuncType 2023-12-31 15:52:27 +02:00
Nikolay Nikolov
eb046b07d0 * TWasmFuncTypeTable.AddFuncType renamed .AddOrGetFuncType 2023-12-31 15:49:26 +02:00
Nikolay Nikolov
7266981c6c + Extracted the func list maintenance functionality from the WebAssembly object
writer to a new TWasmFuncTypeTable class. This will allow for it to be reused
  in the WebAssembly exe writer as well.
2023-12-31 15:39:54 +02:00
Nikolay Nikolov
d6c3c74b46 + create relocation objects for R_WASM_FUNCTION_OFFSET_I32 relocations in the wasm object reader 2023-12-28 21:26:12 +02:00
Nikolay Nikolov
73895d3cbc + create relocation objects for R_WASM_TYPE_INDEX_LEB relocations in the wasm object reader 2023-12-28 21:23:08 +02:00
Nikolay Nikolov
ae93f8de91 + create relocation objects for R_WASM_MEMORY_ADDR_I32 relocations in the wasm object reader 2023-12-28 21:15:59 +02:00
Nikolay Nikolov
35f2fb1e8d * fix warning 2023-12-28 21:11:26 +02:00
Nikolay Nikolov
bd606c6b77 + create relocation objects for R_WASM_MEMORY_ADDR_SLEB relocations in the wasm object reader 2023-12-28 21:07:41 +02:00
Nikolay Nikolov
3e14d47b92 + create relocation objects for R_WASM_MEMORY_ADDR_LEB relocations in the wasm object reader 2023-12-28 21:04:13 +02:00
Nikolay Nikolov
118e093c97 + create relocation objects for R_WASM_TABLE_INDEX_I32 relocations in the wasm object reader 2023-12-28 20:59:32 +02:00
Nikolay Nikolov
c605da6ab3 + create relocation objects for R_WASM_TABLE_INDEX_SLEB relocations in the wasm object reader 2023-12-28 20:57:04 +02:00
Nikolay Nikolov
aa296af787 + create relocation objects for R_WASM_FUNCTION_INDEX_LEB relocations in the wasm object reader 2023-12-28 20:52:17 +02:00
Nikolay Nikolov
bc798695fe + find the code and data segment of each relocation 2023-12-28 20:07:24 +02:00
Nikolay Nikolov
268a148d3a + store the parsed relocation table in an array 2023-12-28 16:47:00 +02:00
Nikolay Nikolov
82c52ed127 * disallow (for now) relocations for sections other than the code and data sections 2023-12-28 16:37:58 +02:00
Nikolay Nikolov
649438efa6 + keep track of section indexes. Save the code and data section indexes. 2023-12-28 16:35:11 +02:00
Nikolay Nikolov
a1bdf11d99 + check for supported relocation types, report an error if an unsupported type is found 2023-12-28 16:09:03 +02:00
Nikolay Nikolov
881ca2c52f + implemented parsing of the relocation section 2023-12-28 16:02:27 +02:00
Nikolay Nikolov
7f30a87651 + started implementing the reading of relocation sections in the wasm object reader 2023-12-28 15:53:45 +02:00
Nikolay Nikolov
026781b9a3 * set MaxMemPos in the wasm internal linker 2023-12-28 15:27:53 +02:00
Nikolay Nikolov
eeae32669e + add oso_keep flag to the code sections that contain an export 2023-12-28 14:54:06 +02:00
Nikolay Nikolov
24972d9861 + parse the export table in the wasm internal object reader 2023-12-28 14:50:51 +02:00
Nikolay Nikolov
4b9e1ab30a + wasm object reader: create code sections and symbols 2023-12-28 14:29:59 +02:00
Nikolay Nikolov
4b179ce4fa + check the code entries count in the wasm object reader 2023-12-28 14:14:30 +02:00
Nikolay Nikolov
87a3bfe99d + fully implemented reading the code section 2023-12-28 13:25:44 +02:00
Nikolay Nikolov
3d5a100f79 + wasm object reader: implemented parsing of the global section 2023-12-28 12:42:48 +02:00
Nikolay Nikolov
4ba064d894 + include mod name in symbols 2023-12-27 15:15:54 +02:00
Nikolay Nikolov
c293d0b729 + partially implemented the creation of symbols for SYMTAB_FUNCTION entries 2023-12-27 15:14:21 +02:00
Nikolay Nikolov
a6d4374f10 + wasm object reader: range check the symbol indices of SYMTAB_FUNCTION entries 2023-12-27 14:52:37 +02:00
Nikolay Nikolov
efc4ab7928 + store in the FuncTypes array the func types, parsed in the function section 2023-12-27 14:47:45 +02:00
Nikolay Nikolov
a0df7c27af + wasm obj reader: store the parsed import data from the import section in local arrays and structures 2023-12-27 14:42:01 +02:00
Nikolay Nikolov
ced7e40c43 + support local binding when reading data symbols in the internal wasm object reader 2023-12-27 13:36:18 +02:00
Nikolay Nikolov
ee4d77b119 + create data symbols in the wasm object reader 2023-12-27 13:14:27 +02:00
Nikolay Nikolov
e569863a1a + check bounds for SymIndex of SYMTAB_DATA symbols 2023-12-27 13:01:49 +02:00
Nikolay Nikolov
121e793c37 + wasm object reader: store the symbol table in a dynamic array, so it can be processed later 2023-12-27 11:52:17 +02:00
Nikolay Nikolov
c6e054dbb9 + implemented parsing of the symbol table in the wasm object reader 2023-12-27 10:59:02 +02:00
Nikolay Nikolov
272db1b872 + symbol table subsection duplicate check 2023-12-27 10:31:24 +02:00
Nikolay Nikolov
b641687da2 * attempt to avoid warning, treated as error, causing CI failure 2023-12-26 20:46:25 +02:00
Nikolay Nikolov
fc7ed302e7 + check and report an error if a passive data segment is encountered by the wasm object reader 2023-12-26 20:42:46 +02:00
Nikolay Nikolov
8606f13b24 + check for memory index other than 0 in the wasm object reader and report an error, since that is not supported 2023-12-26 20:41:40 +02:00
Nikolay Nikolov
23fa8c80b6 + read the section content in the wasm object reader 2023-12-26 20:38:58 +02:00
Nikolay Nikolov
56fe6cadc8 * fill the data in the DataSegments array when parsing the WASM_SEGMENT_INFO subsection 2023-12-26 20:24:52 +02:00
Nikolay Nikolov
50f76a2ffb * moved another local var to avoid bug 2023-12-26 20:22:47 +02:00
Nikolay Nikolov
2ab16a5a8f - removed debug writeln 2023-12-26 20:21:25 +02:00
Nikolay Nikolov
e754937ad3 + verify the segment count when parsing the WASM_SEGMENT_INFO subsection
* moved local vars to avoid bug
2023-12-26 20:19:58 +02:00