mingw-w64 gcc 9.3 built executable ends up with overlapping import tables:
Import Table size: 00001fc8
offset 00240a00 libcurl.dll
Hint/Name Table: 0043712C
TimeDateStamp: 00000000 (Thu Jan 1 01:00:00 1970)
ForwarderChain: 00000000
First thunk RVA: 00437598
Thunk Ordn Name
00437598 345 curl_easy_cleanup
0043759c 347 curl_easy_escape
004375a0 349 curl_easy_init
004375a4 351 curl_easy_perform
004375a8 355 curl_easy_setopt
004375ac 363 curl_free
004375b0 367 curl_global_init
004375b4 411 curl_share_init
004375b8 412 curl_share_setopt
004375bc 414 curl_slist_append
004375c0 425 curl_version_info
offset 00240a14 libfreetype.dll
Hint/Name Table: 0043715C
TimeDateStamp: 00000000 (Thu Jan 1 01:00:00 1970)
ForwarderChain: 00000000
First thunk RVA: 004375C8
Thunk Ordn Name
004375c8 35 FT_Done_Face
004375cc 36 FT_Done_FreeType
004375d0 60 FT_Get_Char_Index
004375d4 69 FT_Get_Kerning
004375d8 108 FT_Init_FreeType
004375dc 112 FT_Library_Version
004375e0 120 FT_Load_Char
004375e4 121 FT_Load_Glyph
004375e8 127 FT_New_Face
004375ec 173 FT_Set_Pixel_Sizes
offset 00240a28 libopusfile.dll
Hint/Name Table: 00437188
TimeDateStamp: 00000000 (Thu Jan 1 01:00:00 1970)
ForwarderChain: 00000000
First thunk RVA: 004375F4
Thunk Ordn Name
004375f4 3 op_channel_count
004375f8 14 op_open_memory
004375fc 18 op_pcm_total
00437600 22 op_read
offset 00240a3c SDL2.dll
Hint/Name Table: 004371A0
TimeDateStamp: 00000000 (Thu Jan 1 01:00:00 1970)
ForwarderChain: 00000000
First thunk RVA: 0043760C
Thunk Ordn Name
0043760c 94 SDL_GL_DeleteContext
00437610 107 SDL_GL_SwapWindow
00437614 106 SDL_GL_SetSwapInterval
00437618 99 SDL_GL_GetDrawableSize
0043761c 103 SDL_GL_MakeCurrent
00437620 93 SDL_GL_CreateContext
00437624 96 SDL_GL_GetAttribute
00437628 105 SDL_GL_SetAttribute
0043762c 71 SDL_DestroyWindow
00437630 539 SDL_SetWindowGrab
00437634 537 SDL_SetWindowFullscreen
00437638 389 SDL_MinimizeWindow
0043763c 557 SDL_ShowWindow
00437640 533 SDL_SetWindowBordered
00437644 550 SDL_SetWindowSize
00437648 547 SDL_SetWindowPosition
0043764c 238 SDL_GetWindowFlags
00437650 57 SDL_CreateWindow
00437654 236 SDL_GetWindowDisplayIndex
00437658 157 SDL_GetCurrentDisplayMode
0043765c 162 SDL_GetDesktopDisplayMode
00437660 165 SDL_GetDisplayMode
00437664 187 SDL_GetNumDisplayModes
00437668 163 SDL_GetDisplayBounds
0043766c 191 SDL_GetNumVideoDisplays
00437670 231 SDL_GetVersion
00437674 251 SDL_GetWindowWMInfo
00437678 628 SDL_free
0043767c 518 SDL_SetRelativeMouseMode
00437680 203 SDL_GetRelativeMouseState
00437684 183 SDL_GetMouseState
00437688 560 SDL_StopTextInput
0043768c 559 SDL_StartTextInput
00437690 179 SDL_GetKeyboardState
00437694 312 SDL_JoystickClose
00437698 318 SDL_JoystickGetAxis
0043769c 314 SDL_JoystickEventState
004376a0 342 SDL_JoystickNumAxes
004376a4 346 SDL_JoystickOpen
004376a8 511 SDL_SetHint
004376ac 409 SDL_PollEvent
004376b0 26 SDL_ClearError
004376b4 169 SDL_GetError
004376b8 153 SDL_GetClipboardText
004376bc 506 SDL_SetClipboardText
004376c0 30 SDL_CloseAudioDevice
004376c4 406 SDL_PauseAudioDevice
004376c8 404 SDL_OpenAudioDevice
004376cc 156 SDL_GetCurrentAudioDriver
004376d0 414 SDL_Quit
004376d4 594 SDL_WasInit
004376d8 415 SDL_QuitSubSystem
004376dc 303 SDL_InitSubSystem
004376e0 302 SDL_Init
004376e4 1177 CryptAcquireContextA
004376e8 1194 CryptGenRandom
offset 00240a50 ADVAPI32.dll
Hint/Name Table: 00437278
TimeDateStamp: 00000000 (Thu Jan 1 01:00:00 1970)
ForwarderChain: 00000000
First thunk RVA: 004376E4
Thunk Ordn Name
004376e4 1177 CryptAcquireContextA
004376e8 1194 CryptGenRandom
CryptAcquireContextA & CryptGenRandom are looked for in ADVAPI32.dll & SDL2.dll. They should only come from ADVAPI32.dll. The thunks have the same address. With GCC 9.2 this recently worked fine, will try to verify if a downgrade helps.
Affected executable is contained in https://ddnet.tw/downloads/DDNet-13.0-win64.zip
Source code that was built is https://github.com/ddnet/ddnet
Best regards
Dennis
It seems like the overlapping import table parts are caused by strip. But without strip the resulting executable also imports CryptAcquireContextA & CryptGenRandom from SDL2.dll, which fails.
Best regards
Dennis
This seems to stem from the fact that the SDL2.dll was compiled with a different compiler. When I build all with the same, it works fine. Bug can be closed I guess.
In my opinion this is a real and important bug. It makes it impossible to use many third-party libraries with mingw-w64-gcc 9.3.
I have attached a minimal test case that tries to link against Ximea's xiapi32.dll. When compiled with i686-w64-mingw32-gcc (GCC) 7.3-win32 20180312, the import table is as follows and executable works fine:
DLL Name: xiapi32.dll
vma: Hint/Ord Member-Name Bound-To
64f4 368 xiStopAcquisition
When compiled with i686-w64-mingw32-gcc (GCC) 9.3-win32 20200320, the import table is as follows and the executable silently fails to execute on Windows 10 and crashes on wine:
DLL Name: xiapi32.dll
vma: Hint/Ord Member-Name Bound-To
64c4 368 xiStopAcquisition
61ec 2 AcquireSRWLockExclusive
6206 277 DeleteCriticalSection
621e 310 EnterCriticalSection
6236 543 GetCurrentProcess
624a 544 GetCurrentProcessId
6260 548 GetCurrentThreadId
6276 617 GetLastError
6286 729 GetStartupInfoA
6298 755 GetSystemTimeAsFileTime
62b2 786 GetTickCount
62c2 877 InitializeCriticalSection
62de 973 LeaveCriticalSection
62f6 1118 QueryPerformanceCounter
6310 1370 SetUnhandledExceptionFilter
632e 1386 Sleep
6336 1401 TerminateProcess
634a 1421 TlsGetValue
6358 1435 UnhandledExceptionFilter
6374 1469 VirtualProtect
6386 1472 VirtualQuery
The imports from KERNEL32.dll are leaking into the import table for other DLLs.
With more complex executables, in addition to silent crashes this also causes error messages like "The procedure entry point AcquireSRWLockExclusive could not be located in the dynamic link library ... foo.exe".
Thanks to Martin Storsjö / wbs on IRC for some hints:
That seems to me like a change to linker-script on binutils. The
import/export tables are binutils related. Gcc doesn't produce them
at all. As I suspected that nothing like LTO tries to be clever here,
that issue should be solvable by the linker script, which should make
sure that last element of table is NULL.
Regards,
Kai
Am Do., 25. Juni 2020 um 10:52 Uhr schrieb jpa jpa-@users.sourceforge.net:
Related
Bugs: #831
It seems like this was a regression in binutils 2.34, that was fixed again in binutils 2.35.
The commit that caused the breakage was this one: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=90d92a632aaf75ce698335efeb383ddf785c12d8
The issue was resolved later by this commit: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=5e365e474b7561318ddb1a107f05cf0c002e8284