Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nothing much from zig #75

Open
codefromthecrypt opened this issue May 18, 2023 · 2 comments
Open

nothing much from zig #75

codefromthecrypt opened this issue May 18, 2023 · 2 comments
Assignees
Labels
good first issue Good for newcomers question Further information is requested zig

Comments

@codefromthecrypt
Copy link

codefromthecrypt commented May 18, 2023

I can compile this with zig cc --target=wasm32-wasi -o math.wasm math.c, and run it with wzprof -sample 1 -memprofile /tmp/profile math.wasm and end up an image like this on go tool pprof -http :4000 /tmp/profile:

Screenshot 2023-05-18 at 09 08 45
#include <stdio.h>

int main(int argc, char** argv)
{
  fprintf(stderr, "%d\n", 1+2);
}

Ironically, if I do the same in zig build-exe math.zig -target wasm32-wasi, I don't get anything.

const std = @import("std");

pub fn main() !void {
    std.debug.print("{}\n", .{1 + 2});
}
$ wasm-tools objdump math.wasm
  types                                  |        0xa -       0x4b |        65 bytes | 11 count
  imports                                |       0x4d -       0x93 |        70 bytes | 2 count
  functions                              |       0x95 -       0xe5 |        80 bytes | 79 count
  memories                               |       0xe7 -       0xea |         3 bytes | 1 count
  globals                                |       0xec -       0xf5 |         9 bytes | 1 count
  exports                                |       0xf7 -      0x10a |        19 bytes | 2 count
  code                                   |      0x10e -     0xa50f |     41985 bytes | 79 count
  data                                   |     0xa512 -     0xaac0 |      1454 bytes | 1 count
  custom ".debug_info"                   |     0xaacf -     0xdfa8 |     13529 bytes | 1 count
  custom ".debug_pubtypes"               |     0xdfbb -     0xe8b5 |      2298 bytes | 1 count
  custom ".debug_loc"                    |     0xe8c3 -     0xecf4 |      1073 bytes | 1 count
  custom ".debug_ranges"                 |     0xed05 -     0xf07d |       888 bytes | 1 count
  custom ".debug_abbrev"                 |     0xf08e -     0xf2d6 |       584 bytes | 1 count
  custom ".debug_line"                   |     0xf2e5 -    0x11e9d |     11192 bytes | 1 count
  custom ".debug_str"                    |    0x11eab -    0x14b7c |     11473 bytes | 1 count
  custom ".debug_pubnames"               |    0x14b8f -    0x15f57 |      5064 bytes | 1 count
  custom "name"                          |    0x15f5f -    0x16ed1 |      3954 bytes | 1 count
  custom "producers"                     |    0x16edd -    0x16eed |        16 bytes | 1 count

Let me know if you have any ideas on why!

@achille-roussel
Copy link
Contributor

Two possibilities I can think of:

@achille-roussel achille-roussel self-assigned this May 18, 2023
@achille-roussel achille-roussel added question Further information is requested zig labels May 18, 2023
@codefromthecrypt
Copy link
Author

I suppose yeah it isn't using the typical malloc/free stuff

$ wasm2wat math.wasm|grep mem.
    call $memset
      call $mem.copy__anon_2526
            call $mem.readIntNative__anon_2363
    call $memset
    call $mem.set__anon_2390
  (func $mem.readIntNative__anon_2363 (type 5) (param i32) (result i32)
  (func $mem.set__anon_2390 (type 9) (param i32 i32 i32)
  (func $mem.copy__anon_2526 (type 6) (param i32 i32 i32 i32)
    call $mem.span__anon_2680
  (func $mem.span__anon_2680 (type 9) (param i32 i32 i32)
    call $mem.len__anon_2706
  (func $mem.len__anon_2706 (type 8) (param i32 i32) (result i32)
    call $mem.copy__anon_2526
    call $memset
    call $mem.set__anon_2390
  (func $memset (type 7) (param i32 i32 i32) (result i32)
  (memory (;0;) 17)
  (export "memory" (memory 0))

@achille-roussel achille-roussel added the good first issue Good for newcomers label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested zig
Projects
None yet
Development

No branches or pull requests

2 participants