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

gethostname linkage fails, even though present in wasi-libc #196

Open
marmistrz opened this issue Apr 27, 2020 · 4 comments
Open

gethostname linkage fails, even though present in wasi-libc #196

marmistrz opened this issue Apr 27, 2020 · 4 comments

Comments

@marmistrz
Copy link

I tried to compile the following code using wasi-sdk

clang hostname.c --target=wasm32-wasi --sysroot=/opt/wasi-sdk/wasi-sysroot
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void) {

    char hostname[1024];
    gethostname(hostname, 1024);

    puts(hostname);

    return EXIT_SUCCESS;
}

This fails during the linking phase:

wasm-ld: error: /tmp/hostname-bd4ad1.o: undefined symbol: gethostname
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

even though gethostname is implemented by wasi-libc.

@sunfishcode
Copy link
Member

While the musl netdb.h and gethostbyname implemenation are present in the tree, they are disabled in the WASI libc build. WASI does not yet have API support needed to implement gethostbyname.

@marmistrz
Copy link
Author

That's what I expected because I wasn't aware of such API either. In such case, we should mention it in gethostbyname.c et al.

@sbc100
Copy link
Member

sbc100 commented Apr 27, 2020

Isn't the solution to remove the functions/headers so this becomes a compile error rather than a link error?

@sunfishcode
Copy link
Member

Agreed, we should do that. This would also be a good function to add as an optional "emulated" function, and have it return some fixed string like "wasihost" or something for compatibility with code that doesn't actually need it to mean anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants