Cannot create delay load imports Section when Rebuild Native Modules on Windows
I follow the steps in https://www.caoccao.com/Javet/reference/resource_management/modularization.html to rebuild sqlite3. The build process is successful, but the created file .node not contains delay load imports Section
Dump of file node_modules\sqlite3\lib\binding\napi-v3-win32-x64\node_sqlite3.node File Type: DLL
Section contains the following imports:
KERNEL32.dll
180147000 Import Address Table
18017D168 Import Name Table
...
libjavet-node-windows-x86_64.v.1.1.6.dll
1801473C8 Import Address Table
18017D530 Import Name Table
0 time date stamp
0 Index of first forwarder reference
...
process information: gyp info it worked if it ends with ok gyp info using [email protected] gyp info using [email protected] | win32 | x64 gyp info ok gyp info it worked if it ends with ok gyp info using [email protected] gyp info using [email protected] | win32 | x64 gyp info find Python using Python version 3.10.6 found at "C:\Users\XXX\AppData\Local\Programs\Python\Python310\python.exe" gyp info find VS using VS2019 (16.11.32126.315) found at: gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" gyp info find VS run with --verbose for detailed information gyp info spawn C:\Users\XXX\AppData\Local\Programs\Python\Python310\python.exe gyp info spawn args [ gyp info spawn args 'C:\Users\XXX\AppData\Roaming\nvm\v16.16.0\node_modules\node-gyp\gyp\gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'msvs', gyp info spawn args '-I', gyp info spawn args 'E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\config.gypi', gyp info spawn args '-I', gyp info spawn args 'C:\Users\XXX\AppData\Roaming\nvm\v16.16.0\node_modules\node-gyp\addon.gypi', gyp info spawn args '-I', gyp info spawn args 'C:\Users\XXX\AppData\Local\node-gyp\Cache\16.16.0\include\node\common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=C:\Users\XXX\AppData\Local\node-gyp\Cache\16.16.0', gyp info spawn args '-Dnode_gyp_dir=C:\Users\XXX\AppData\Roaming\nvm\v16.16.0\node_modules\node-gyp', gyp info spawn args '-Dnode_lib_file=C:\\Users\\XXX\\AppData\\Local\\node-gyp\\Cache\\16.16.0\\<(target_arch)\\node.lib', gyp info spawn args '-Dmodule_root_dir=E:\javet\build\Javet\scripts\node\node_modules\sqlite3', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] [37;40mgyp[0m [0m[32minfo[0m [0m[35mok[0m [0m
ROBOCOPY :: Windows 的可靠文件复制
开始时间: 2022年10月8日 11:07:13
源: E:\javet\build\Javet\scripts\node\node_modules\sqlite3\deps
目标: E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\deps\
文件: *.*
选项: *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30
4 E:\javet\build\Javet\scripts\node\node_modules\sqlite3\deps\
*多余文件 11425 action_before_build.vcxproj
*多余文件 3084 action_before_build.vcxproj.filters
*多余文件 1466 sqlite3.sln
*多余文件 12469 sqlite3.vcxproj
*多余文件 3220 sqlite3.vcxproj.filters
100% 新文件 1322 common-sqlite.gypi 100% 新文件 224 extract.js 100% 新文件 2.9 m sqlite-autoconf-3390400.tar.gz 100% 新文件 3021 sqlite3.gyp
总数 复制 跳过 不匹配 失败 其他
目录: 1 0 1 0 0 0
文件: 4 4 0 0 0 5
字节: 2.92 m 2.92 m 0 0 0 30.9 k
时间: 0:00:00 0:00:00 0:00:00 0:00:00
速度: 7952800 字节/秒。
速度: 455.062 MB/分钟。
结束时间: 2022年10月8日 11:07:13
gyp info it worked if it ends with ok gyp info using [email protected] gyp info using [email protected] | win32 | x64 gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe gyp info spawn args [ gyp info spawn args 'build/binding.sln', gyp info spawn args '/clp:Verbosity=minimal', gyp info spawn args '/nologo', gyp info spawn args '/p:Configuration=Release;Platform=x64' gyp info spawn args ] 在此解决方案中一次生成一个项目。若要启用并行生成,请添加“-m”开关。 win_delay_load_hook.cc nothing.vcxproj -> E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\Release\nothing.lib unpack_sqlite_dep sqlite3.c win_delay_load_hook.cc sqlite3.vcxproj -> E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\Release\sqlite3.lib backup.cc database.cc node_sqlite3.cc statement.cc win_delay_load_hook.cc 正在创建库 E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\Release\node_sqlite3.lib 和对象 E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\Release\node_sqlite3.exp 正在生成代码 Previous IPDB not found, fall back to full compilation. All 4978 functions were compiled because no usable IPDB/IOBJ from previous compilation was found. 已完成代码的生成 node_sqlite3.vcxproj -> E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\Release\node_sqlite3.node Copying E:\javet\build\Javet\scripts\node\node_modules\sqlite3\build\Release/node_sqlite3.node to ..\lib\binding\napi-v3-win32-x64 已复制 1 个文件。 gyp info ok
Any suggestion, thanks in advance!
You may try the section Manual Patch in the same doc. It's a more reliable solution.
Thanks caoccao, Using Manual Patch, dll name set to libjavet-node-windows-x86_64.v.1.1.6.dll, com.caoccao.javet.exceptions.JavetExecutionException: Error: A dynamic link library (DLL) initialization routine failed. \?\E:\javet\build\Javet\scripts\node\node_modules\sqlite3\lib\binding\napi-v6-win32-unknown-x64\node_sqlite3.node at com.caoccao.javet.interop.V8Native.execute(Native Method) at com.caoccao.javet.interop.V8Runtime.execute(V8Runtime.java:802) V8Runtime.java:802 at com.caoccao.javet.interop.executors.V8StringExecutor.execute(V8StringExecutor.java:76) V8StringExecutor.java:76 at com.caoccao.javet.interop.IV8Executable.executeVoid(IV8Executable.java:170) IV8Executable.java:170 at com.mainsoft.ap2.Ap2Application.runServer(Ap2Application.java:83) Ap2Application.java:83 at com.mainsoft.ap2.Ap2Application.lambda$0(Ap2Application.java:27) Ap2Application.java:27 at java.base/java.lang.Thread.run(Thread.java:833)
Which one did you patch? It needs to be the original one.
Yes, it's original one. Before patch test is ok.
node test-node\test-node-module-sqlite3-sync.js Connected to the in-memory sqlite3 database. Closed the database connection.
New versions of Node.js somehow break embedders' reusing the process. The current solution is to downgrade to an early version of Javet.
Here are 2 similar issues for your reference. I'm not sure if the fix would be patching Node.js which I don't want to do.
- https://github.com/TryGhost/node-sqlite3/issues/1370
- https://github.com/electron/electron/issues/18397
Which version of Javet to downgrade?
Which version of Javet to downgrade?
I'm not sure. Could you try them respectively? In the meanwhile, I'll look into it once I have time.
downgrade to Javet v0.9.14 env: node v14.17.6 node-gyp v9.2.0 Result:
- Manual Patch works successfully.
- as for rebuild, no delay load imports Section in the created file. Open the property of vs project, modify C/C++, Linker Section, replace node.exe/node.lib to libjavet-node-windows-x86_64.v.0.9.14.lib/libjavet-node-windows-x86_64.v.0.9.14.dll, rebuild the project. The node-sqlite3.node created and it contains Delay Import Section. Run the test in Javet, the same error : A dynamic link library (DLL) initialization routine failed.
SQLite version needs to be a little bit lower.