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

add 'linkerArgs' config option #1103

Merged
merged 2 commits into from
Feb 3, 2022

Conversation

kristofdho
Copy link
Contributor

@kristofdho kristofdho commented Feb 1, 2022

This adds a configuration option to externally configure additional linker flags

Issue

Fixes #1101

Progress

@johanvos
Copy link
Contributor

johanvos commented Feb 3, 2022

@kristofdho This looks a good feature, making it more flexible to link in other libraries. Do you have a particular usecase in mind you want to share?

@abhinayagarwal abhinayagarwal added the enhancement New feature or request label Feb 3, 2022
@jperedadnr jperedadnr merged commit a42b3d2 into gluonhq:master Feb 3, 2022
@kristofdho
Copy link
Contributor Author

We were having trouble using the fontmanager library, as described in #945
The root cause being that to use it, we had to copy java.dll, jvm.dll, awt.dll, fontmanager.dll and freetype.dll next to the executable, which native-image normally does automatically with java.dll and jvm.dll being a shim dll.
Since we didn't have the shims, that crashes on the documented error on that issue.

We worked around that by having a dummy project to compile with native-image which generates the shim dlls but for that to work we needed these extra linker flags.

Sidenote, statically linking fontmanager & freetype also worked in standard native-image, provided we added fontmanager.lib, freetype.lib, awt.lib and gdi32.lib as -H:NativeLinkerOption args. But that didn't do the trick for substrate. Besides also additionally needing comctl32.lib and shlwapi.lib, it ended up with a whole lot of duplicate symbols which, when ignored, created a non functioning executable.

duplicate symbols
[2022-02-01T10:56:35.821Z]      [exec] [Tue Feb 01 10:56:35 UTC 2022][INFO] [SUB] glass.lib(GlassResources.res) : warning LNK4078: multiple '.rsrc' sections found with different attributes (40000040)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(awt_Toolkit.obj) : error LNK2005: DllMain already defined in net.lib(net_util_md.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "void __cdecl D3DUtils_SetIdentityMatrix(struct _D3DMATRIX *)" (?D3DUtils_SetIdentityMatrix@@YAXPEAU_D3DMATRIX@@@Z) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "public: long __cdecl D3DContext::EndScene(void)" (?EndScene@D3DContext@@QEAAJXZ) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "private: long __cdecl D3DContext::InitContextCaps(void)" (?InitContextCaps@D3DContext@@AEAAJXZ) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "private: long __cdecl D3DContext::InitDevice(struct IDirect3DDevice9 *)" (?InitDevice@D3DContext@@AEAAJPEAUIDirect3DDevice9@@@Z) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "public: long __cdecl D3DContext::ResetClip(void)" (?ResetClip@D3DContext@@QEAAJXZ) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "public: long __cdecl D3DContext::ResetContext(void)" (?ResetContext@D3DContext@@QEAAJXZ) already defined in prism_d3d.lib(D3DContextInit.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "public: long __cdecl D3DContext::ResetTransform(void)" (?ResetTransform@D3DContext@@QEAAJXZ) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DContext.obj) : error LNK2005: "public: long __cdecl D3DContext::SetRectClip(int,int,int,int)" (?SetRectClip@D3DContext@@QEAAJHHHH@Z) already defined in prism_d3d.lib(D3DContext.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "private: long __cdecl D3DPipelineManager::CheckDeviceCaps(unsigned int)" (?CheckDeviceCaps@D3DPipelineManager@@AEAAJI@Z) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:36.419Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "private: long __cdecl D3DPipelineManager::D3DEnabledOnAdapter(unsigned int)" (?D3DEnabledOnAdapter@D3DPipelineManager@@AEAAJI@Z) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "int __cdecl D3DPPLM_OsVersionMatches(unsigned short)" (?D3DPPLM_OsVersionMatches@@YAHG@Z) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "public: long __cdecl D3DPipelineManager::GetD3DContext(unsigned int,class D3DContext * *)" (?GetD3DContext@D3DPipelineManager@@QEAAJIPEAPEAVD3DContext@@@Z) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "public: static class D3DPipelineManager * __cdecl D3DPipelineManager::GetInstance(void)" (?GetInstance@D3DPipelineManager@@SAPEAV1@XZ) already defined in prism_d3d.lib(D3DResourceFactory.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "public: enum _D3DFORMAT __cdecl D3DPipelineManager::GetMatchingDepthStencilFormat(unsigned int,enum _D3DFORMAT,enum _D3DFORMAT)" (?GetMatchingDepthStencilFormat@D3DPipelineManager@@QEAA?AW4_D3DFORMAT@@IW42@0@Z) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "private: long __cdecl D3DPipelineManager::ReleaseAdapters(void)" (?ReleaseAdapters@D3DPipelineManager@@AEAAJXZ) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "private: long __cdecl D3DPipelineManager::ReleaseD3D(void)" (?ReleaseD3D@D3DPipelineManager@@AEAAJXZ) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "private: enum _D3DDEVTYPE __cdecl D3DPipelineManager::SelectDeviceType(void)" (?SelectDeviceType@D3DPipelineManager@@AEAA?AW4_D3DDEVTYPE@@XZ) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DPipelineManager.obj) : error LNK2005: "private: static class D3DPipelineManager * D3DPipelineManager::pMgr" (?pMgr@D3DPipelineManager@@0PEAV1@EA) already defined in prism_d3d.lib(D3DPipelineManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "protected: virtual __cdecl D3DResource::~D3DResource(void)" (??1D3DResource@@MEAA@XZ) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: __cdecl D3DResourceManager::~D3DResourceManager(void)" (??1D3DResourceManager@@QEAA@XZ) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: long __cdecl D3DResourceManager::AddResource(class IManagedResource *)" (?AddResource@D3DResourceManager@@QEAAJPEAVIManagedResource@@@Z) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "private: long __cdecl D3DResourceManager::CreateOSPSurface(unsigned int,unsigned int,enum _D3DFORMAT,class D3DResource * *)" (?CreateOSPSurface@D3DResourceManager@@AEAAJIIW4_D3DFORMAT@@PEAPEAVD3DResource@@@Z) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: long __cdecl D3DResourceManager::CreateSwapChain(struct HWND__ *,unsigned int,unsigned int,unsigned int,enum _D3DSWAPEFFECT,unsigned int,class D3DResource * *)" (?CreateSwapChain@D3DResourceManager@@QEAAJPEAUHWND__@@IIIW4_D3DSWAPEFFECT@@IPEAPEAVD3DResource@@@Z) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: long __cdecl D3DResourceManager::GetBlitOSPSurface(unsigned int,unsigned int,enum _D3DFORMAT,class D3DResource * *)" (?GetBlitOSPSurface@D3DResourceManager@@QEAAJIIW4_D3DFORMAT@@PEAPEAVD3DResource@@@Z) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "protected: void __cdecl D3DResource::Init(struct IDirect3DResource9 *,struct IDirect3DSwapChain9 *)" (?Init@D3DResource@@IEAAXPEAUIDirect3DResource9@@PEAUIDirect3DSwapChain9@@@Z) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: virtual int __cdecl D3DResource::IsDefaultPool(void)" (?IsDefaultPool@D3DResource@@UEAAHXZ) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "protected: virtual void __cdecl D3DResource::Release(void)" (?Release@D3DResource@@MEAAXXZ) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: void __cdecl D3DResourceManager::ReleaseAll(void)" (?ReleaseAll@D3DResourceManager@@QEAAXXZ) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: void __cdecl D3DResourceManager::ReleaseDefPoolResources(void)" (?ReleaseDefPoolResources@D3DResourceManager@@QEAAXXZ) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(D3DResourceManager.obj) : error LNK2005: "public: long __cdecl D3DResourceManager::ReleaseResource(class IManagedResource *)" (?ReleaseResource@D3DResourceManager@@QEAAJPEAVIManagedResource@@@Z) already defined in prism_d3d.lib(D3DResourceManager.obj)
[2022-02-01T10:56:37.130Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(awt_DnDDS.obj) : error LNK2005: "bool __cdecl operator<(struct tagFORMATETC const &,struct tagFORMATETC const &)" (??M@YA_NAEBUtagFORMATETC@@0@Z) already defined in glass.lib(GlassClipboard.obj)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] comsupp.lib(comutil.obj) : error LNK2005: "class _variant_t vtMissing" (?vtMissing@@3V_variant_t@@A) already defined in comsuppw.lib(comutil.obj)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB]    Creating library C:\jenkins\workspace\Build PlanIT Designer v21.1+\PlanIT.Build\build\native-image\target\gluonfx\x86_64-windows\native-image.lib and object C:\jenkins\workspace\Build PlanIT Designer v21.1+\PlanIT.Build\build\native-image\target\gluonfx\x86_64-windows\native-image.exp
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(awt_Toolkit.obj) : error LNK2019: unresolved external symbol __imp_StrTrimW referenced in function "private: void __cdecl AwtToolkit::InitTouchKeyboardExeFilePath(void)" (?InitTouchKeyboardExeFilePath@AwtToolkit@@AEAAXXZ)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(ComCtl32Util.obj) : error LNK2019: unresolved external symbol __imp_InitCommonControlsEx referenced in function "public: void __cdecl ComCtl32Util::InitLibraries(void)" (?InitLibraries@ComCtl32Util@@QEAAXXZ)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(ComCtl32Util.obj) : error LNK2019: unresolved external symbol SetWindowSubclass referenced in function "public: __int64 (__cdecl*__cdecl ComCtl32Util::SubclassHWND(struct HWND__ *,__int64 (__cdecl*)(struct HWND__ *,unsigned int,unsigned __int64,__int64)))(struct HWND__ *,unsigned int,unsigned __int64,__int64)" (?SubclassHWND@ComCtl32Util@@QEAAP6A_JPEAUHWND__@@I_K_J@Z0P6A_J0I12@Z@Z)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(ComCtl32Util.obj) : error LNK2019: unresolved external symbol RemoveWindowSubclass referenced in function "public: void __cdecl ComCtl32Util::UnsubclassHWND(struct HWND__ *,__int64 (__cdecl*)(struct HWND__ *,unsigned int,unsigned __int64,__int64),__int64 (__cdecl*)(struct HWND__ *,unsigned int,unsigned __int64,__int64))" (?UnsubclassHWND@ComCtl32Util@@QEAAXPEAUHWND__@@P6A_J0I_K_J@Z3@Z)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(ComCtl32Util.obj) : error LNK2019: unresolved external symbol DefSubclassProc referenced in function "public: __int64 __cdecl ComCtl32Util::DefWindowProcW(__int64 (__cdecl*)(struct HWND__ *,unsigned int,unsigned __int64,__int64),struct HWND__ *,unsigned int,unsigned __int64,__int64)" (?DefWindowProcW@ComCtl32Util@@QEAA_JP6A_JPEAUHWND__@@I_K_J@Z0I12@Z)
[2022-02-01T10:56:37.405Z]      [exec] [Tue Feb 01 10:56:36 UTC 2022][INFO] [SUB] awt.lib(awt_DnDDT.obj) : error LNK2019: unresolved external symbol __imp_SHCreateStreamOnFileW referenced in function "protected: virtual long __cdecl AwtDropTarget::SaveIndexToFile(unsigned short const *,unsigned int)" (?SaveIndexToFile@AwtDropTarget@@MEAAJPEBGI@Z)

That first one still persists, although the exe seems to work fine now: glass.lib(GlassResources.res) : warning LNK4078: multiple '.rsrc' sections found with different attributes (40000040)

@credmond
Copy link

Would suggest some documentation & examples on the purpose and usage of this configuration. Piecing the puzzle together from dozens of Github tickets is sub-optimal.

@kristofdho kristofdho deleted the add-linkerArgs-config-option branch June 23, 2023 13:06
@Ggbr-TaoLi
Copy link

We were having trouble using the fontmanager library, as described in #945 The root cause being that to use it, we had to copy java.dll, jvm.dll, awt.dll, fontmanager.dll and freetype.dll next to the executable, which native-image normally does automatically with java.dll and jvm.dll being a shim dll. Since we didn't have the shims, that crashes on the documented error on that issue.

We worked around that by having a dummy project to compile with native-image which generates the shim dlls but for that to work we needed these extra linker flags.

Sidenote, statically linking fontmanager & freetype also worked in standard native-image, provided we added fontmanager.lib, freetype.lib, awt.lib and gdi32.lib as -H:NativeLinkerOption args. But that didn't do the trick for substrate. Besides also additionally needing comctl32.lib and shlwapi.lib, it ended up with a whole lot of duplicate symbols which, when ignored, created a non functioning executable.

duplicate symbols
That first one still persists, although the exe seems to work fine now: glass.lib(GlassResources.res) : warning LNK4078: multiple '.rsrc' sections found with different attributes (40000040)

Excuse me, I'm struggling with this question, is there a good solution for Fontmanager on javafx?
Tried adding awt.lib and had the same repetitive definition problem you had.

@kristofdho
Copy link
Contributor Author

@Ggbr-TaoLi you can ignore everything about static linking in what you quoted. So adding awt.lib is not an option. Plain native-image has moved to dynamic linking for awt entirely.

I wouldn't say there is a good solution for fontmanager on javafx, but it does work.
You'll need to generate the shim dlls as I said, and copy those next to the native-image produced by substrate. just copying awt.dll from the java home dir has issues of it's own, so the shim dlls are definitely desired.
You'll also need to add <linkerArgs> for these symbols, in order to make the shim dlls work: https://github.com/oracle/graal/blob/vm-ce-23.0.1/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/JNIRegistrationAWTSupport.java

I still have the multiple '.rsrc sections` warning, which we're ignoring and haven't caused any issues so far.

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

Successfully merging this pull request may close these issues.

Provide a way to specify additional linker flags
6 participants