Skip to content

Wrapping syscalls doesn't work with -sMAIN_MODULE -sEXPORT_ALL #26355

@hoodmane

Description

@hoodmane

Version of emscripten/emsdk:
Tip of tree

$ ./emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 5.0.1-git (d4c1c6e1d37bf38e84cca063753a462143b7af9a)

a.c:

#include "stdio.h"
#include <fcntl.h>

int syscall_openat_orig(int dirfd, intptr_t path, int flags, void* varags)
    __attribute__((__import_module__("env"),
                   __import_name__("__syscall_openat"), __warn_unused_result__));

int __syscall_openat(int dirfd, intptr_t path, int flags, void* varargs) {
    printf("__syscall_openat!\n");
    return syscall_openat_orig(dirfd, path, flags, varargs);
}

int main() {
    int fd = open("a.c", O_RDONLY);
    printf("fd: %d\n", fd);
}

compile, link, run

$ emcc a.c -sNODERAWFS -sEXPORT_ALL -sMAIN_MODULE -O2 && node a.out.js
RuntimeError: Aborted(LinkError: WebAssembly.instantiate(): Import #0 "env" "__syscall_openat": function import requires a callable).

Comments

Removing either -sEXPORT_ALL or -sMAIN_MODULE makes the error go away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions