Index | Thread | Search

From:
Landry Breuil <landry@openbsd.org>
Subject:
add webassembly definition to file/magdir
To:
tech@openbsd.org, nicm@openbsd.org
Date:
Sun, 2 Mar 2025 08:55:45 +0100

Download raw body.

Thread
  • Landry Breuil:

    add webassembly definition to file/magdir

hi tech@,

updating the lang/wasi-sdk stack, i wanted to check if it produced valid
wasm bytecode.

clang-19 --sysroot=/usr/local/share/wasi-sysroot/ -target wasm32-unknown-wasi -o printf printf.c

devel/libmagic on the resulting binary says:
$efile printf
printf: WebAssembly (wasm) binary module version 0x1 (MVP)

while our file says 'data'.
with the attached webassembly definition (coming from
https://github.com/file/file/blob/master/magic/Magdir/webassembly,
amended to use '1' instead of '=1', as i havent found that construct in
other magfiles) in /usr/src/usr.bin/file/, our file now says:

$file printf
printf: WebAssembly (wasm) binary module

i dunno why the module version detection doesnt work, as hexdump on the
header correctly shows 01 as long:

$hexdump -C printf |head -1
00000000  00 61 73 6d 01 00 00 00  01 52 0d 60 03 7f 7f 7f |.asm.....R.`....|

ok to add to our file(1) ?
#------------------------------------------------------------------------------
# $File: webassembly,v 1.4 2022/08/16 11:16:39 christos Exp $
# webassembly:  file(1) magic for WebAssembly modules
#
# WebAssembly is a virtual architecture developed by a W3C Community
# Group at https://webassembly.org/. The file extension is .wasm, and
# the MIME type is application/wasm.
#
# https://webassembly.org/docs/binary-encoding/ is the main
# document describing the binary format.
# From: Pip Cet <pipcet@gmail.com> and Joel Martin

0	string	\0asm	WebAssembly (wasm) binary module
>4	lelong	1	version %#x (MVP)
!:mime  application/wasm
!:ext   wasm
>4	lelong	>1	version %#x