Thread overview
Preview: LDC2 on Windows 64bit with SEH support
May 25, 2013
Kai Nacke
May 25, 2013
David Nadlinger
May 25, 2013
Kai Nacke
May 26, 2013
Michael
May 26, 2013
Kai Nacke
Jun 06, 2013
David Nadlinger
Jun 19, 2013
Vladimir Panteleev
Jun 20, 2013
Kai Nacke
May 25, 2013
As promised at DConf I continued my work on the exception handling issue on Win64. The wiki page http://wiki.dlang.org/Building_and_hacking_LDC_on_Windows_using_MSVC
contains now a patch against LLVM head which enables exception support on Win64.

If you are curious but don't want to build LDC yourself you can also download a
preview version here: http://www.redstar.de/ldc/LDC.zip (MD5: fb149c3575cd2c35f56e4e10c19046fc).
This build is based on the upcoming 0.11.0 release and LLVM 3.4 head with my patch applied.

Prerequisite: You need VS 2012 installed for the linker and the CRT dll. (Any version should do, including the C++ express version.)

This version has only alpha quality and contains known bugs:

- Non-ABI-compliant code is generated for aligned variables on the stack.
  This should be no issue if you do not use the vector extension.

- The epilogue core is always required to get the stack unwinding right.
  Unfortunately LLVM does not generate the epilogue code if it can prove that it is really dead code. E.g.:

void doIt()
{
    printf("doIt: start\n");
    try
    {
        printf("doIt: try\n");
        throw new Exception("Failure");
    }
    catch (OutOfMemoryError) {}
    finally
    {
        printf("doIt: finally\n");
    }
    printf("doIt: end\n");
}

This works as expected. But if you remove the catch statement then the application crashes. Root cause is that LLVM knows that everything after the throw is unreachable and therefore dead code. The last generated instruction in this function is a call to _d_resume_unwind. Without the epilogue code the unwind fails.

I like to get feedback on the implementation. I am quite sure that there are other bugs lurking around. Feel free to report any bug in our issue tracker at https://github.com/ldc-developers/ldc/issues/166 or in this forum.

Regards
Kai
May 25, 2013
On 25 May 2013, at 18:08, Kai Nacke wrote:
> As promised at DConf I continued my work on the exception handling issue on Win64. The wiki page http://wiki.dlang.org/Building_and_hacking_LDC_on_Windows_using_MSVC
> contains now a patch against LLVM head which enables exception support on Win64.
>
> If you are curious but don't want to build LDC yourself you can also download a
> preview version here: http://www.redstar.de/ldc/LDC.zip (MD5: fb149c3575cd2c35f56e4e10c19046fc).
> This build is based on the upcoming 0.11.0 release and LLVM 3.4 head with my patch applied.

Great! I'll definitely give it a try once I find a few spare minutes.

> Prerequisite: You need VS 2012 installed for the linker and the CRT dll. (Any version should do, including the C++ express version.)

I suppose I need to invoke it from a Visual Studio Command Prompt (resp. execute the appropriate batch file first)?

> - The epilogue core is always required to get the stack unwinding right.
> Unfortunately LLVM does not generate the epilogue code if it can prove that it is really dead code. E.g.:
>
> void doIt()
> {
> printf("doIt: start\n");
> try
> {
> printf("doIt: try\n");
> throw new Exception("Failure");
> }
> catch (OutOfMemoryError) {}
> finally
> {
> printf("doIt: finally\n");
> }
> printf("doIt: end\n");
> }
>
> This works as expected. But if you remove the catch statement then the application crashes. Root cause is that LLVM knows that everything after the throw is unreachable and therefore dead code. The last generated instruction
> in this function is a call to _d_resume_unwind. Without the epilogue code the unwind fails.

I didn't think about the issue in any detail yet, but could you maybe use llvm::ResumeInst to work around this?

David
May 25, 2013
On Saturday, 25 May 2013 at 19:02:50 UTC, David Nadlinger wrote:
>
> I suppose I need to invoke it from a Visual Studio Command Prompt (resp. execute the appropriate batch file first)?

Yes.

>> The last generated instruction
>> in this function is a call to _d_resume_unwind. Without the epilogue code the unwind fails.
>
> I didn't think about the issue in any detail yet, but could you maybe use llvm::ResumeInst to work around this?

I give that a try.

Kai
May 26, 2013
How to create custom ini settings file?

May 26, 2013
On Sunday, 26 May 2013 at 13:28:13 UTC, Michael wrote:
> How to create custom ini settings file?

The ini file is ldc2.conf and located in the etc folder. You can either change this file or create your own. The current search order on Windows is:

- the current working directory
- in same directory as ldc2.exe
- %USERPROFILE%\.ldc
- %USERPROFILE%
- <path of ldc2.exe>\..\etc
- path specified in registry key HKLM\SOFTWARE\ldc-developers\LDC\0.11.0\Path (this is subject to change)

Inside the ldc2.conf there is 1 variable which could be used:

%%ldcbinarypath%% is replaced with the absolute path of ldc2.exe

The lines inside the switches block are simply appended to the command line. You can add everything which is also valid on the command line.

Regards
Kai
June 06, 2013
On Saturday, 25 May 2013 at 16:08:20 UTC, Kai Nacke wrote:
> If you are curious but don't want to build LDC yourself you can also download a
> preview version here: http://www.redstar.de/ldc/LDC.zip (MD5: fb149c3575cd2c35f56e4e10c19046fc).
> This build is based on the upcoming 0.11.0 release and LLVM 3.4 head with my patch applied.

The ldc2.conf should use %%ldcbinarypath%% instead of your hardcoded installation directory.

I do something similar as part of the packaging scripts: https://github.com/ldc-developers/ldc-scripts/blob/master/ldc2-packaging/2-build-ldc.sh#L45

David
June 19, 2013
On Saturday, 25 May 2013 at 16:08:20 UTC, Kai Nacke wrote:
>   Unfortunately LLVM does not generate the epilogue code if it can prove that it is really dead code.

Is the error message "_d_eh_resume_unwind: No exception object provided" a symptom of this problem?
June 20, 2013
On Wednesday, 19 June 2013 at 11:43:57 UTC, Vladimir Panteleev wrote:
> On Saturday, 25 May 2013 at 16:08:20 UTC, Kai Nacke wrote:
>>  Unfortunately LLVM does not generate the epilogue code if it can prove that it is really dead code.
>
> Is the error message "_d_eh_resume_unwind: No exception object provided" a symptom of this problem?

The general symptom is a crash of the program. This looks like another problem, because the exception object passed to the exception handler is not passed to the resume function.
Can you provide the source or a test case for this?

Kai