You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
error: undefined symbol: htons / ntohs / rand due to deps_info.json not seeing files from .a's #9566
The issue is that we use deps_info.json to handle linking in C code that JS will need, and we do implement the sockets code in JS, which ends up wanting htons etc. This normally works, but I bisected to #9436, and from that point on we are broken. I didn't look into that PR's code but looking on incoming, the issue is that for deps_info.json purposes we only look at the immediately compiled files... and not files in a library that is linked in. So we fail to see we will need things. My guess is that that PR changed which files get looked at there.
changed the title [-]error: undefined symbol: htons / ntohs / rand[/-][+]error: undefined symbol: htons / ntohs / rand due to deps_info.json not seeing files from .a's[/+]on Oct 2, 2019
@sbc100 I'm not looking into it, no - was hoping you'd have an idea from the investigation I did + your better understanding of the PR where this broke? Would be great if you can take a look!
I believe I'm having the same issue in 3.0.0 with Unreal Engine 4.24. I'm attempting to upgrade from emscripten 1.39.0 and get the following output:
UATHelper: Packaging (HTML5): warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
UATHelper: Packaging (HTML5): warning: _htons may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
UATHelper: Packaging (HTML5): error: undefined symbol: ntohs (referenced by $inetNtop6__deps: ['$inetNtop4','ntohs'], referenced by $readSockaddr__deps: ['$Sockets','$inetNtop4','$inetNtop6','ntohs'], referenced by $getSocketAddress__deps: ['$readSockaddr','$FS','$DNS'], referenced by __syscall_bind__deps: ['$getSocketFromFD','$getSocketAddress','$SYSCALLS'], referenced by top-level compiled C/C++ code)
UATHelper: Packaging (HTML5): warning: _ntohs may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
UATHelper: Packaging (HTML5): error: undefined symbol: _get_daylight (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by top-level compiled C/C++ code)
UATHelper: Packaging (HTML5): warning: __get_daylight may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
UATHelper: Packaging (HTML5): error: undefined symbol: _get_timezone (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by top-level compiled C/C++ code)
UATHelper: Packaging (HTML5): warning: __get_timezone may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
UATHelper: Packaging (HTML5): error: undefined symbol: _get_tzname (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by top-level compiled C/C++ code)
UATHelper: Packaging (HTML5): warning: __get_tzname may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
UATHelper: Packaging (HTML5): Error: Aborting compilation due to previous errors
UATHelper: Packaging (HTML5): emcc: error: 'I:/_repos/unreal_html5/Engine/Platforms/HTML5/Build/emsdk/emsdk-3.0.0/node/14.15.5_64bit/bin/node.exe I:\_repos\unreal_html5\Engine\Platforms\HTML5\Build\emsdk\emsdk-3.0.0\upstream\emscripten\src\compiler.js I:\_repos\unreal_html5\Engine\Intermediate\Build\HTML5\EmscriptenTemp\tmpthj1ixne.txt' failed (returned
1)
The build is successful if I pass -s ERROR_ON_UNDEFINED_SYMBOLS=0 but I get ReferenceError: __get_timezone is immediately after loading in the browser.
Here is how UE's "Package Project" calls the linker:
Where "*.o" is there are about 500 engine/project files. I know UE needs functions like ntohs() and gettimezone(), but is there something else that needs to be done to link properly? I thought such things would get pulled in automatically if a function call like bind() exists somewhere? I can see bind() is called from UE's SocketsBSD.cpp which is being included in the build.
This could be an issue with the parsing of the output of nm and the handling of reverse dependencies.
You might need to help us out by adding some debugging to tools/system_libs.py in and around the handle_reverse_deps function. If bind is being referenced by any of your input files then ntohs would be pulled in. Perhaps you can figure out why handle_reverse_deps doesn't seem be finding the bind reference?
@sbc100 Thank you for the quick response, I had found other posts suggesting to use -s EMCC_FORCE_STDLIBS=1 but this gave me an error for unknown option, I'm guessing it was removed? However, after looking through src/settings.js I found the following options:
Enabling these allowed me to build and load in the browser so I can start working on updating outdated emscripten calls in UE but linking seems to take a really long time now (as compared to 1.39.0). Would you recommend I avoid using some or all of the above options?
Now, looking at handle_reverse_deps I see that the behavior will have changed significantly by using -s REVERSE_DEPS=all.
What debugging information would be helpful from handle_reverse_deps? Logging the contents of symbolses = building.llvm_nm_multiple([os.path.abspath(t) for t in input_files]) or something?
-s AUTO_JS_LIBRARIES=1 and -s AUTO_NATIVE_LIBRARIES=1 are both the default so I don't think they are relevant here.
Using -s REVERSE_DEPS=all is basically saying that all reverse deps should be included and not just the ones that are needed by your program (according the the results of running nm on your inputs).
You need to find out which of your .a libraryies contains the references the bind C library call... this is the one that appears to not be detected by handle_reverse_deps. I would look at the llvm_nm_multiple function in building.py which is called from handle_reverse_deps. I would log that names of each of the input files.. then when you see the name matches the one you expect to find the reference to bind in, log the results and see why bind is not part of the results.
You can find out which library has the bind reference either by running llvm-nm on all your libraries or by linking with -Wl,--trace-symbol=bind.
I:\\_repos\\unreal_html5_examples\\CP_TPP\\Intermediate\\Build\\HTML5\\CP_TPPClient\\Development\\Sockets\\Module.Sockets.cpp.o: reference to bind
I:\\_repos\\unreal_html5\\Engine\\Platforms\\HTML5\\Source\\ThirdParty\\PhysX3\\PhysX_3.4\\lib-3.0.0-up\\PxFoundation_O2.a(PsUnixSocket.cpp.o): reference to bind
I:\\_repos\\unreal_html5\\Engine\\Platforms\\HTML5\\Build\\emsdk\\emsdk-3.0.0\\upstream\\emscripten\\cache\\sysroot\\lib\\wasm32-emscripten\libsockets.a(bind.o): definition of bind
error: undefined symbol: htons (referenced by $inetPton6__deps: ['htons','$jstoi_q'], referenced by $writeSockaddr__deps: ['$Sockets','$inetPton4','$inetPton6','$zeroMemory'], referenced by __syscall_accept4__deps: ['$getSocketFromFD','$writeSockaddr','$DNS','$SYSCALLS'], referenced by top-level compiled C/C++ code)
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: _htons may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: ntohs (referenced by $inetNtop6__deps: ['$inetNtop4','ntohs'], referenced by $readSockaddr__deps: ['$Sockets','$inetNtop4','$inetNtop6','ntohs'], referenced by $getSocketAddress__deps: ['$readSockaddr','$FS','$DNS'], referenced by __syscall_bind__deps: ['$getSocketFromFD','$getSocketAddress','$SYSCALLS'], referenced by top-level compiled C/C++ code)
warning: _ntohs may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _get_daylight (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by top-level compiled C/C++ code)
warning: __get_daylight may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _get_timezone (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by top-level compiled C/C++ code)
warning: __get_timezone may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
error: undefined symbol: _get_tzname (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by top-level compiled C/C++ code)
warning: __get_tzname may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
For Module.Sockets.cpp.o I can see the following from handle_reverse_deps:
I'm not sure if I'm interpreting the output correctly but so far each of the undefs lists the missing function so shouldn't they get picked up automatically since each of these functions appear in deps_info.py?
Indeed. The next step would be to add -v to your link command so it prints out the underlying wasm-ld command.. you should see all the required symbols listed as --export or --export-if-defined, included htons.
You can also check if htons was correct pulled out of deps_info.py by logging each of the symbols that gets added to EXPORTED_FUNCTIONS in tools/system_libs.py line 1617. If bind is indeed found in your libraries then ntons should be added here.
But nothing is ever added in this loop.
Actually I don't see any of the UE functions found in llvm_nm_multiple in this output.
Before I had printed the output of results.stdout here is what I get if I print out what is parsed:
for key, value in parse_llvm_nm_symbols(results.stdout).items():
nm_cache[key] = value
print(f'cmd:{cmd};\n\tresults:{parse_llvm_nm_symbols(results.stdout).items()}')
return [nm_cache[f] if f in nm_cache else {'defs': set(), 'undefs': set(), 'parse_error': True} for f in files]
cmd:['I:/_repos/unreal_html5/Engine/Platforms/HTML5/Build/emsdk/emsdk-3.0.0/upstream/bin\\llvm-nm.exe', '@C:\\Users\\<>\\AppData\\Local\\Temp\\emscripten_t1cthm09.rsp.utf-8'];
results:dict_items([('I:\\\\_repos\\\\unreal_html5_examples\\\\CP_TPP\\\\Intermediate\\\\Build\\\\HTML5\\\\CP_TPPClient\\\\Development\\\\Launch\\\\Module.Launch.cpp.o', {'defs': ...
It looks like the return loop isn't iterating over the results correctly because the only input file is emscripten_t1cthm09.rsp.utf-8?
I'm not sure I understand the problem here. Why do you think the use of the rsp (response file) is an issue?
Perhaps you could try running pprint.print(results.stdout) and pprint.print(nm_cache) and then attaching the resulting (huge) output to this bug? (you will need to import pprint too).
return [nm_cache[f] if f in nm_cache else {'defs': set(), 'undefs': set(), 'parse_error': True} for f in files]
It is only going to return the items in nm_cache that are also listed in files but the only entry is emscripten_t1cthm09.rsp.utf-8 so it ends up adding nothing.
The files I previously uploaded (*.reverse_deps.txt) were the key and value variables from the loop. nm_cache does contain all the correct data from llvm_nm, it's just that each entry gets filtered out because it doesn't appear in files.
Activity
Beuc commentedon Oct 2, 2019
In addition, passing
-s ERROR_ON_UNDEFINED_SYMBOLS=0triggersReferenceError: __get_timezone is not definedat runtime (not sure it's related).kripken commentedon Oct 2, 2019
If it's hard to reduce this, if you can provide the final emcc link command + input files, that should be enough for us to debug it.
Beuc commentedon Oct 2, 2019
Here's another simpler one (Python web prompt) which seems related:
Do you want a tar archive?
kripken commentedon Oct 2, 2019
Sure, a tar is ok.
Beuc commentedon Oct 2, 2019
There it is (lighter than my full ~2GB RenPyWeb build environment...)
https://www.beuc.net/tmp/link.tgz
There's a difference though, the OP is reported in compiler.js, this one in wasm-ld.
kripken commentedon Oct 2, 2019
Thanks!
Ok, I think I understand the underlying problem. Here is a reduced testcase:
The issue is that we use
deps_info.jsonto handle linking in C code that JS will need, and we do implement the sockets code in JS, which ends up wantinghtonsetc. This normally works, but I bisected to #9436, and from that point on we are broken. I didn't look into that PR's code but looking on incoming, the issue is that fordeps_info.jsonpurposes we only look at the immediately compiled files... and not files in a library that is linked in. So we fail to see we will need things. My guess is that that PR changed which files get looked at there.[-]error: undefined symbol: htons / ntohs / rand[/-][+]error: undefined symbol: htons / ntohs / rand due to deps_info.json not seeing files from .a's[/+]sbc100 commentedon Oct 8, 2019
@kripken are you looking into this already? Want me to take a look?
kripken commentedon Oct 8, 2019
@sbc100 I'm not looking into it, no - was hoping you'd have an idea from the investigation I did + your better understanding of the PR where this broke? Would be great if you can take a look!
simulacrumgames commentedon Dec 7, 2021
@kripken
I believe I'm having the same issue in 3.0.0 with Unreal Engine 4.24. I'm attempting to upgrade from emscripten 1.39.0 and get the following output:
The build is successful if I pass
-s ERROR_ON_UNDEFINED_SYMBOLS=0but I get ReferenceError: __get_timezone is immediately after loading in the browser.Here is how UE's "Package Project" calls the linker:
UE4Game.js.response contains:
Where "*.o" is there are about 500 engine/project files. I know UE needs functions like ntohs() and gettimezone(), but is there something else that needs to be done to link properly? I thought such things would get pulled in automatically if a function call like bind() exists somewhere? I can see bind() is called from UE's SocketsBSD.cpp which is being included in the build.
sbc100 commentedon Dec 7, 2021
This could be an issue with the parsing of the output of nm and the handling of reverse dependencies.
You might need to help us out by adding some debugging to
tools/system_libs.pyin and around thehandle_reverse_depsfunction. Ifbindis being referenced by any of your input files thenntohswould be pulled in. Perhaps you can figure out whyhandle_reverse_depsdoesn't seem be finding thebindreference?@juj might be able to help?
simulacrumgames commentedon Dec 8, 2021
@sbc100 Thank you for the quick response, I had found other posts suggesting to use
-s EMCC_FORCE_STDLIBS=1but this gave me an error for unknown option, I'm guessing it was removed? However, after looking throughsrc/settings.jsI found the following options:-s AUTO_JS_LIBRARIES=1-s AUTO_NATIVE_LIBRARIES=1-s REVERSE_DEPS=allEnabling these allowed me to build and load in the browser so I can start working on updating outdated emscripten calls in UE but linking seems to take a really long time now (as compared to 1.39.0). Would you recommend I avoid using some or all of the above options?
Now, looking at
handle_reverse_depsI see that the behavior will have changed significantly by using-s REVERSE_DEPS=all.What debugging information would be helpful from
handle_reverse_deps? Logging the contents ofsymbolses = building.llvm_nm_multiple([os.path.abspath(t) for t in input_files])or something?sbc100 commentedon Dec 8, 2021
-s AUTO_JS_LIBRARIES=1and-s AUTO_NATIVE_LIBRARIES=1are both the default so I don't think they are relevant here.Using
-s REVERSE_DEPS=allis basically saying that all reverse deps should be included and not just the ones that are needed by your program (according the the results of runningnmon your inputs).You need to find out which of your
.alibraryies contains the references thebindC library call... this is the one that appears to not be detected byhandle_reverse_deps. I would look at thellvm_nm_multiplefunction inbuilding.pywhich is called fromhandle_reverse_deps. I would log that names of each of the input files.. then when you see the name matches the one you expect to find the reference tobindin, log the results and see whybindis not part of the results.You can find out which library has the
bindreference either by runningllvm-nmon all your libraries or by linking with-Wl,--trace-symbol=bind.simulacrumgames commentedon Dec 9, 2021
I got the following output:
For
Module.Sockets.cpp.oI can see the following fromhandle_reverse_deps:Module.Sockets.cpp.o_reverse_deps.txt
bindPxFoundation_O2.a_reverse_deps.txt
localtime_rModule.Core.2_of_11.cpp.o_reverse_deps.txt
localtime_rtzsetlibicu_O2.a_reverse_deps.txt
I'm not sure if I'm interpreting the output correctly but so far each of the
undefslists the missing function so shouldn't they get picked up automatically since each of these functions appear in deps_info.py?sbc100 commentedon Dec 9, 2021
Indeed. The next step would be to add
-vto your link command so it prints out the underlyingwasm-ldcommand.. you should see all the required symbols listed as--exportor--export-if-defined, includedhtons.You can also check if
htonswas correct pulled out of deps_info.py by logging each of the symbols that gets added toEXPORTED_FUNCTIONSintools/system_libs.pyline 1617. If bind is indeed found in your libraries then ntons should be added here.simulacrumgames commentedon Dec 14, 2021
It seems this test is never passed in
system_libs.py:I can see bind is checked:
But nothing is ever added in this loop.
Actually I don't see any of the UE functions found in
llvm_nm_multiplein this output.Before I had printed the output of
results.stdouthere is what I get if I print out what is parsed:It looks like the return loop isn't iterating over the results correctly because the only input file is
emscripten_t1cthm09.rsp.utf-8?sbc100 commentedon Dec 14, 2021
I'm not sure I understand the problem here. Why do you think the use of the rsp (response file) is an issue?
Perhaps you could try running
pprint.print(results.stdout)andpprint.print(nm_cache)and then attaching the resulting (huge) output to this bug? (you will need toimport pprinttoo).simulacrumgames commentedon Dec 17, 2021
If I understand correctly, for this line:
It is only going to return the items in
nm_cachethat are also listed infilesbut the only entry isemscripten_t1cthm09.rsp.utf-8so it ends up adding nothing.The files I previously uploaded (*.reverse_deps.txt) were the
keyandvaluevariables from the loop.nm_cachedoes contain all the correct data from llvm_nm, it's just that each entry gets filtered out because it doesn't appear infiles.sbc100 commentedon Dec 17, 2021
Are you sure files doesn't contain the actual filenames?
IIUC the
emscripten_t1cthm09.rsp.utf-8is generated by this line:cmd = get_command_with_possible_response_file(cmd)Can you confirm that files contains the response file? IIUC it should not