Bug 14327 – Unhandled exception from writeln() in C++/D application

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2015-03-24T18:48:00Z
Last change time
2016-02-28T19:04:40Z
Keywords
C++, pull
Assigned to
nobody
Creator
szymon.gatner
See also
https://issues.dlang.org/show_bug.cgi?id=14318

Comments

Comment #0 by szymon.gatner — 2015-03-24T18:48:37Z
With this C++ application: extern "C" int rt_init(); // prototypes of standard D runtime functions extern "C" void rt_term(); extern "C" void dfunc(); int main() { auto dinit = rt_init(); // returns 1 dfunc(); // causes unhandled exception } and linking to this D library: module lib; extern(C) void dfunc() { import std.stdio; writeln("Hello from D!"); } int main() { return 0; } call to dfunc() on C++ side causes Unhandled exception in stdio.d line 2917: // Specialization for strings - a very frequent case auto w = .trustedStdout.lockingTextWriter(); initial report on D forums [1] leads potential issue with stdio module static initialization failure. Using Visual Studio 2012, x64 app, Win 7 x64 [1] http://forum.dlang.org/thread/[email protected]#post-mailman.397.1409844359.5783.digitalmars-d-learn:40puremagic.com
Comment #1 by dlang-bugzilla — 2015-03-30T19:12:32Z
Why are there two main functions?
Comment #2 by dlang-bugzilla — 2015-03-30T19:24:13Z
I can't even get this application to link... keep getting minfo_beg/minfo_end errors (with both -m64 and -m32mscoff).
Comment #3 by szymon.gatner — 2015-03-30T22:04:56Z
(In reply to Vladimir Panteleev from comment #1) > Why are there two main functions? Without main() in D library link errors occur
Comment #4 by szymon.gatner — 2015-03-30T22:06:15Z
(In reply to Vladimir Panteleev from comment #2) > I can't even get this application to link... keep getting > minfo_beg/minfo_end errors (with both -m64 and -m32mscoff). m32mscoff won't work as there is no coff32 phobos. What link errors are you getting?
Comment #5 by dlang-bugzilla — 2015-03-30T22:09:59Z
(In reply to Szymon Gatner from comment #4) > m32mscoff won't work as there is no coff32 phobos. Build my own. > What link errors are you getting? --------------------------------------------- C:\Temp\D\issues\14327> "C:\Downloads\!dmd\dmd.2.066.0\dmd2\windows\bin\dmd.exe" -c -m64 lib.d C:\Temp\D\issues\14327> cl test.cpp lib.obj "C:\Downloads\!dmd\dmd.2.066.0\dmd2\windows\lib64\phobos64.lib" Microsoft (R) C/C++ Optimizing Compiler Version 18.00.30723 for x64 Copyright (C) Microsoft Corporation. All rights reserved. test.cpp Microsoft (R) Incremental Linker Version 12.00.30723.0 Copyright (C) Microsoft Corporation. All rights reserved. /out:test.exe test.obj lib.obj C:\Downloads\!dmd\dmd.2.066.0\dmd2\windows\lib64\phobos64.lib phobos64.lib(dmain2_4ec_2f9.obj) : error LNK2019: unresolved external symbol _deh_beg referenced in function rt_init phobos64.lib(sections_win64_575_4e2.obj) : error LNK2001: unresolved external symbol _deh_beg phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved external symbol _minfo_end referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved external symbol _minfo_beg referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo phobos64.lib(sections_win64_575_4e2.obj) : error LNK2019: unresolved external symbol _deh_end referenced in function _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9FuncTable test.exe : fatal error LNK1120: 4 unresolved externals --------------------------------------------- Please supply exact commands to reproduce the problem, I guess
Comment #6 by szymon.gatner — 2015-03-31T12:23:35Z
(In reply to Vladimir Panteleev from comment #5) > (In reply to Szymon Gatner from comment #4) > > m32mscoff won't work as there is no coff32 phobos. > > Build my own. > > > What link errors are you getting? > > --------------------------------------------- > C:\Temp\D\issues\14327> > "C:\Downloads\!dmd\dmd.2.066.0\dmd2\windows\bin\dmd.exe" -c -m64 lib.d > > C:\Temp\D\issues\14327> cl test.cpp lib.obj > "C:\Downloads\!dmd\dmd.2.066.0\dmd2\windows\lib64\phobos64.lib" > Microsoft (R) C/C++ Optimizing Compiler Version 18.00.30723 for x64 > Copyright (C) Microsoft Corporation. All rights reserved. > > test.cpp > Microsoft (R) Incremental Linker Version 12.00.30723.0 > Copyright (C) Microsoft Corporation. All rights reserved. > > /out:test.exe > test.obj > lib.obj > C:\Downloads\!dmd\dmd.2.066.0\dmd2\windows\lib64\phobos64.lib > phobos64.lib(dmain2_4ec_2f9.obj) : error LNK2019: unresolved external symbol > _deh_beg referenced in function rt_init > phobos64.lib(sections_win64_575_4e2.obj) : error LNK2001: unresolved > external symbol _deh_beg > phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved > external symbol _minfo_end referenced in function > _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo > phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved > external symbol _minfo_beg referenced in function > _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo > phobos64.lib(sections_win64_575_4e2.obj) : error LNK2019: unresolved > external symbol _deh_end referenced in function > _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9Fun > cTable > test.exe : fatal error LNK1120: 4 unresolved externals > --------------------------------------------- > > > Please supply exact commands to reproduce the problem, I guess Doing everything in IDE. Will try to get to build logs and commands used
Comment #7 by szymon.gatner — 2015-04-03T20:53:47Z
Build started 2015-04-03 22:49:35. 1>Project "C:\Users\bravo\documents\visual studio 2012\Projects\CppDMix\CppDMix\CppDMix.vcxproj" on node 2 (Build target(s)). 1>ClCompile: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\CL.exe /c /Zi /nologo /W3 /WX- /Od /D WIN32 /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"x64\Debug\\" /Fd"x64\Debug\vc110.pdb" /Gd /TP /errorReport:prompt main.cpp main.cpp Link: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"C:\Users\bravo\documents\visual studio 2012\Projects\CppDMix\x64\Debug\CppDMix.exe" /INCREMENTAL /NOLOGO /LIBPATH:D:\devel\D\dmd2\windows\lib64 /LIBPATH:"C:\Users\bravo\Documents\visual studio 2012\Projects\CppDMix\dlib\Debug" phobos64.lib dlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\bravo\documents\visual studio 2012\Projects\CppDMix\x64\Debug\CppDMix.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\bravo\documents\visual studio 2012\Projects\CppDMix\x64\Debug\CppDMix.lib" /MACHINE:X64 x64\Debug\main.obj CppDMix.vcxproj -> C:\Users\bravo\documents\visual studio 2012\Projects\CppDMix\x64\Debug\CppDMix.exe 1>Done Building Project "C:\Users\bravo\documents\visual studio 2012\Projects\CppDMix\CppDMix\CppDMix.vcxproj" (Build target(s)). Build succeeded. Time Elapsed 00:00:00.32
Comment #8 by dlang-bugzilla — 2015-04-04T05:43:02Z
I'm still seeing the same errors. How are you compiling dlib.lib?
Comment #9 by szymon.gatner — 2015-04-04T08:37:47Z
I assume that was agnerated by VisualD: set PATH=D:\devel\D\dmd2\windows\\bin;C:\Program Files (x86)\Windows Kits\8.1\\\bin;%PATH% set DMD_LIB=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\\lib\amd64;C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64 set WindowsSdkDir=C:\Program Files (x86)\Windows Kits\8.1\ set VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ "C:\Program Files (x86)\VisualD\pipedmd.exe" dmd -lib -m64 -g -debug -X -Xf"Debug\dlib.json" -deps="Debug\dlib.dep" -of"Debug\dlib.lib" -map "Debug\dlib.map" lib.d if errorlevel 1 goto reportError if not exist "Debug\dlib.lib" (echo "Debug\dlib.lib" not created! && goto reportError) goto noError :reportError echo Building Debug\dlib.lib failed! :noError
Comment #10 by szymon.gatner — 2015-04-09T11:58:32Z
Did it help to reproduce?
Comment #11 by szymon.gatner — 2015-10-14T12:24:21Z
Just tested the same with Visual Studio 2015 and Beta D 2.069.0-b1 using mscoff32 version of phobos. Bug still persists I am afraid. This time excpetion is thrown from stdio.d line 3076: auto w = .trustedStdout.lockingTextWriter();
Comment #12 by r.sagitario — 2015-10-18T08:45:20Z
The problem is that the stdin,stdout,stderr handles are only initialized when running d_run_main, but not rt_init.
Comment #13 by r.sagitario — 2015-10-18T08:58:05Z
Comment #14 by github-bugzilla — 2015-10-29T14:01:31Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/848c97c52186934dae807e2b0923c8fbb0f17e15 issue 14327: move call to init_msvc() into rt_init() https://github.com/D-Programming-Language/druntime/commit/1c95b5827012f448d2d917c98dd310ac211dec69 Merge pull request #1412 from rainers/issue_14327 issue 14327: move call to init_msvc() into rt_init()
Comment #15 by github-bugzilla — 2015-10-29T14:30:17Z
Commit pushed to stable at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/de2788d911129545531e0e42d1c8630b3f406e7c Merge pull request #1412 from rainers/issue_14327 issue 14327: move call to init_msvc() into rt_init()
Comment #16 by github-bugzilla — 2015-10-30T15:38:25Z
Commit pushed to stable at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/82715d0589d815a77c7139a59193899866a35f02 fixed Issue 14327 - Unhandled exception from writeln() - this is an empty dummy commit to close the bugzilla issue and generate a changelog entry - see #1412 (and de2788d911) for the original fix
Comment #17 by github-bugzilla — 2016-01-03T14:10:06Z
Comment #18 by github-bugzilla — 2016-02-28T19:04:40Z