On Thursday, 7 March 2013 at 01:25:02 UTC, Walter Bright wrote:
Some months ago, I did make the source to optlink available on github:

https://github.com/DigitalMars/optlink

Rainer Schuetze has improved it where it can be built with modern tools (the older tools would not run on Win7). I know some of you are frustrated by optlink problems. Well, now you can do something about it!

Note that the optlink source is quite a challenge to work on. It's very old skool (80's style).

Here's an approach that I've used successfully to fix optlink seg faults:

1. Find out where in the source code it is. This is not so easy, even if using a debugger. The trouble is the asm functions do not have standard stack frames, so the debugger cannot do a stack trace. Even where there is a standard stack frame, the modern Microsoft debuggers fail to recognize them. You gotta use an older debugger under Windows XP.

So, what I do, is look at the asm code where the seg fault occurs, and then grep through the asm source till I find it.

2. Convert the source file where the seg fault occurs to C. I do this one function at a time, running the full set of tests at each step. Otherwise, it's just impossible to figure out where you made a mistake in the conversion. Sometimes, you gotta go even finer grained - using the inline assembler feature of dmc to convert asm code line by line.

You gotta pay very, very close attention to which registers have parameters passed through them, which registers are saved, and which registers have parameters that are silently passed through a function to callees of that function (!). This information is all pretty much utterly lacking in the comments, and the comments are often dead wrong as they refer to much older versions of the code.

3. Once it is in C, things get a lot easier. You can, for example, insert printf's to figure out where things go wrong, and *then* fix it.


The full test suite for optlink has a lot of stuff I cannot publish on github. However, what you can do is run the win32 tests for dmd. I, of course, will run the full one when verifying pulls.

Happy hacking!

Is this the current linker used by DMD on all platforms?

Reply via email to