Emscripten: unresolved symbol: __errno_location with NO_FILESYSTEM=1

Created on 28 Mar 2018  Â·  11Comments  Â·  Source: emscripten-core/emscripten

Compiling anything (even an empty main() function) with -s NO_FILESYSTEM=1 results in

warning: unresolved symbol: __errno_location

Version: emcc (Emscripten gcc/clang-like replacement) 1.37.36 (commit ea710429be2953863614b4433937c4b7a5da1209)

This is on Ubuntu 17.10.

help wanted wontfix

All 11 comments

I can't reproduce this (1.37.36, also linux),

$ ./emcc tests/hello_world.c -s NO_FILESYSTEM=1
$

Any local changes? Does emcc -v report any problems?

No local changes, compiled using emsdk.

emcc -v doesn't seem to find anything suspicious

INFO:root:(Emscripten: Running sanity checks)
clang version 5.0.0  (emscripten 1.37.36 : 1.37.36)
Target: asmjs-unknown-emscripten
Thread model: posix
InstalledDir: /home/j/src/emsdk/clang/e1.37.36_64bit
 "/home/j/src/emsdk/clang/e1.37.36_64bit/clang" -cc1 -triple asmjs-unknown-emscripten -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name a.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -no-integrated-as -mconstructor-aliases -v -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /tmp/tmpue1DNt/a_0.gcno -nostdsysteminc -nobuiltininc -resource-dir /home/j/src/emsdk/clang/lib/clang/5.0.0 -D __EMSCRIPTEN_major__=1 -D __EMSCRIPTEN_minor__=37 -D __EMSCRIPTEN_tiny__=36 -D _LIBCPP_ABI_VERSION=2 -Werror=implicit-function-declaration -fno-dwarf-directory-asm -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length 103 -fobjc-runtime=gnustep -fdiagnostics-show-option -nobuiltininc -nostdsysteminc -isystem/home/j/src/emsdk/emscripten/1.37.36/system/include/libcxx -isystem/home/j/src/emsdk/emscripten/1.37.36/system/lib/libcxxabi/include -isystem/home/j/src/emsdk/emscripten/1.37.36/system/include/compat -isystem/home/j/src/emsdk/emscripten/1.37.36/system/include -isystem/home/j/src/emsdk/emscripten/1.37.36/system/include/SSE -isystem/home/j/src/emsdk/emscripten/1.37.36/system/include/libc -isystem/home/j/src/emsdk/emscripten/1.37.36/system/lib/libc/musl/arch/emscripten -isystem/home/j/src/emsdk/emscripten/1.37.36/system/local/include -disable-O0-optnone -isystem/home/j/src/emsdk/emscripten/1.37.36/system/include/SDL -o /tmp/tmpue1DNt/a_0.o -x c a.c
clang -cc1 version 5.0.0 based upon LLVM 5.0.0 default target x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /home/j/src/emsdk/emscripten/1.37.36/system/include/libcxx
 /home/j/src/emsdk/emscripten/1.37.36/system/lib/libcxxabi/include
 /home/j/src/emsdk/emscripten/1.37.36/system/include/compat
 /home/j/src/emsdk/emscripten/1.37.36/system/include
 /home/j/src/emsdk/emscripten/1.37.36/system/include/SSE
 /home/j/src/emsdk/emscripten/1.37.36/system/include/libc
 /home/j/src/emsdk/emscripten/1.37.36/system/lib/libc/musl/arch/emscripten
 /home/j/src/emsdk/emscripten/1.37.36/system/local/include
 /home/j/src/emsdk/emscripten/1.37.36/system/include/SDL
End of search list.
warning: unresolved symbol: __errno_location

Very strange. No idea why we'd be seeing different results.

I can reproduce the libsodium build failure, but building hello_world.c works fine for me.

config.log

emcc code.c \
    -std=c11 \
    --pedantic \
    -O3 \
    -s STRICT=1 \
    -s WASM=1 \
    -s NO_EXIT_RUNTIME=1 \
    -s DISABLE_EXCEPTION_CATCHING=1 \
    -s NO_FILESYSTEM=1 \
    -s MODULARIZE=1 \
    -s EXPORT_NAME="'instantiate_module'" \
    -g3 \
    -o module.js

My _C_ code gives this error with the -s NO_FILESYSTEM=1 option, too.

I don't know the reason why this happens, either (-s DISABLE_EXCEPTION_CATCHING=1 is suspicious, though.); but I've found a temporary expedient for this issue.
Define your __errno_location in this way:

int * __errno_location(void)
{
    // Emscripten issue #6387
    //
    // https://github.com/kripken/emscripten/issues/6387
    //
    //  The `-s NO_FILESYSTEM=1` option seems to be causing an error:
    // `unresolved symbol: __errno_location`.
    // The actual cause has not confirmed yet.
    // This is a temporary expedient for this problem.
    static int dummy_errno;
    return &dummy_errno;
}

Well, I've just found something new. Symbol __errno_location got resolved when I included stdio.h, so I didn't have to manually define it. I still have no idea what's going on, though.

Does it ring a bell with you guys?

#include <stddef.h> // size_t, NULL.
#include <stdlib.h> // malloc, realloc, free.
#include <emscripten/emscripten.h> // EMSCRIPTEN_KEEPALIVE

int * __errno_location(void)
{
    // Emscripten issue #6387
    //
    // https://github.com/kripken/emscripten/issues/6387
    //
    //  The `-s NO_FILESYSTEM=1` option seems to be causing an error:
    // `unresolved symbol: __errno_location`.
    // The actual cause has not confirmed yet.
    // This is a temporary expedient for this problem.
    static int dummy_errno;
    return &dummy_errno;
}

↓

#include <stddef.h> // size_t, NULL.
#include <stdlib.h> // malloc, realloc, free.
#include <stdio.h> // printf
#include <emscripten/emscripten.h> // EMSCRIPTEN_KEEPALIVE

/*
int * __errno_location(void)
{
    // Emscripten issue #6387
    //
    // https://github.com/kripken/emscripten/issues/6387
    //
    //  The `-s NO_FILESYSTEM=1` option seems to be causing an error:
    // `unresolved symbol: __errno_location`.
    // The actual cause has not confirmed yet.
    // This is a temporary expedient for this problem.
    static int dummy_errno;
    return &dummy_errno;
}
*/

That would explain why the hello_world test passed. libsodium doesn't include stdio.h.

Yeah, turns out this is related to linking in of stdio and libc code. Specifically, malloc writes to errno, but without filesystem code we may not link in libc. So this works ok:

#include <errno.h>

int main() {
  return errno; // bring in errno manually
}

while commenting out the return (so we don't bring in errno) will lead to an unresolved symbol.

One option is to make malloc force linking in of all of libc, say by adding

diff --git a/tools/system_libs.py b/tools/system_libs.py
index c5651ec..38f42c6 100755
--- a/tools/system_libs.py
+++ b/tools/system_libs.py
@@ -499,6 +499,7 @@ def calculate(temp_files, in_temp, stdout_, stderr_, forced=[]):
     system_libs += [('libc', 'bc', create_libc, libc_symbols, [], False)]

   force.add(malloc_name())
+  force.add('libc')

   # if building to wasm, we need more math code, since we have less builtins
   if shared.Settings.WASM:

but that would make compiling small programs slower. Alternatively we could add a hack somewhere, as in this case we don't actually need errno, nothing will read it.

any updates on this?

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShawZG picture ShawZG  Â·  4Comments

HolgerStrauss picture HolgerStrauss  Â·  4Comments

nerddan picture nerddan  Â·  4Comments

kripken picture kripken  Â·  4Comments

rpellerin picture rpellerin  Â·  3Comments