Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Wasmリンカのつくりかた

Yuta Saito
December 09, 2020

 Wasmリンカのつくりかた

WebAssembly night #10
イベント: https://emsn.connpass.com/event/192221/
自作したWasmリンカ: https://github.com/kateinoigakukun/chibi-link

Yuta Saito

December 09, 2020
Tweet

More Decks by Yuta Saito

Other Decks in Technology

Transcript

  1. γϯϘϧͷղܾ // lib.c int add(int a, int b) { return

    a + b; } // main.c int add(int a, int b); int main(void) { return add(1, -1); } 14
  2. ࠶഑ஔ ࠶഑ஔϨίʔυͱγϯϘϧςʔϒϧΛݩʹϦϯΫޙͷγϯϘϧ ͷΞυϨεΛॻ͖ࠐΉ // main.c int add(int a, int b);

    int main(void) { return add(1, -1); // addؔ਺ͷϦϯΫޙͷΞυϨεΛ஌Γ͍ͨ } 15
  3. $ wasm-objdump --details --section=reloc.CODE main.o main.o: file format wasm 0x1

    Section Details: Custom: - name: "reloc.CODE" - relocations for section: 3 (Code) [5] - R_WASM_GLOBAL_INDEX_LEB offset=0x000006(file=0x00008f) symbol=1 <env.__stack_pointer> - R_WASM_GLOBAL_INDEX_LEB offset=0x00001b(file=0x0000a4) symbol=1 <env.__stack_pointer> - R_WASM_FUNCTION_INDEX_LEB offset=0x000038(file=0x0000c1) symbol=2 <env.add> - R_WASM_GLOBAL_INDEX_LEB offset=0x00004d(file=0x0000d6) symbol=1 <env.__stack_pointer> - R_WASM_FUNCTION_INDEX_LEB offset=0x00005b(file=0x0000e4) symbol=0 <__original_main> 16
  4. $ wasm-objdump --details --section=reloc.CODE main.o main.o: file format wasm 0x1

    Section Details: Custom: - name: "reloc.CODE" - relocations for section: 3 (Code) [5] - R_WASM_GLOBAL_INDEX_LEB offset=0x000006(file=0x00008f) symbol=1 <env.__stack_pointer> - R_WASM_GLOBAL_INDEX_LEB offset=0x00001b(file=0x0000a4) symbol=1 <env.__stack_pointer> - R_WASM_FUNCTION_INDEX_LEB offset=0x000038(file=0x0000c1) symbol=2 <env.add> - R_WASM_GLOBAL_INDEX_LEB offset=0x00004d(file=0x0000d6) symbol=1 <env.__stack_pointer> - R_WASM_FUNCTION_INDEX_LEB offset=0x00005b(file=0x0000e4) symbol=0 <__original_main> 16
  5. kateinoigakukun/chibi-link • ࠓճ࡞ͬͨSwift੡WasmϦϯΧ • SwiftΛϦϯΫ͢Δͷʹ࠷খݶͳػೳ • ϦϯΧຊମ͸3000ߦ͘Β͍Ͱখ͞Ί $ wasmtime run

    --mapdir=/var/tmp::$(pwd) chibi-link.wasm -- \ /var/tmp/lib.o /var/tmp/main.o -o /var/tmp/output.wasm 17