Tag Archives: openwatcom

OpenWatcom: Fixing a Compiler Bug

Here I go through the story of finding a bug in a compiler, building, and fixing it. It’s a story of dealing with an unfamiliar build system and unfamiliar code base. Not all the details of the false starts and mistakes follow, but enough of them to show how one can use basic tools to figure out how an unfamiliar system works.

Why OpenWatcom? I first came across OpenWatcom when I started being interested in programming for OS/2. This was in 2006 or so. At the time, and still I believe, OpenWatcom was the only current compiler that made native OS/2 binaries. GCC compiled code requires a Posix runtime environment, either the old EMX, or the newer klibc1.

I’ve also used OpenWatcom for DOS development. I am interested in retro programming, and at the time (in the 90s) I just wasn’t good enough to do what I wanted to do; so I’ve let my teenage dreams come true in recent years. Mostly I run my DOS applications in DOSBox, and I run my compiler in the same system I use to run DOSBox, such as ArcaOS and Windows. OpenWatcom is famous for being the compiler of choice for most of the big name DOS games such as Doom and Tomb Raider; see the list of software made with the Watcom compilers.

Even though OpenWatcom only makes 32bit binaries, I’ve also used this occasionally for Windows programming. I don’t remember where and when, but I came across Structured Exception Handling in the context of Windows programming, and one day I wanted to give it a try; this time I chose OpenWatcom rather than Visual Studio.
Continue reading OpenWatcom: Fixing a Compiler Bug

Building OpenSSL with OpenWatcom on ArcaOS: Second Porting Effort

I’ve written before about my OpenSSL port to OS/2. I’m doing this with OpenWatcom 1.9 on the ArcaOS flavour of OS/2.

Building with no Assembler

First, we copy OS2-OW.cmd to OS2-OW-NOASM.cmd and then make the new file run perl Configure OS2-OW no-asm and perl util\mk1mf.pl no-asm OS2-OW > OS2-OW.mak.

Then it’s just a matter of building the make file with OS2\OS2-OW-NOAM.cmd and building with wmake -u -c -f OS2-OW.mak.

This builds the libraries ssl.lib and crypto.lib plus a few applications. Some of them work.

apps/ca.c

This file fails to build with the error message .\apps\ca.c(86): Error! E1055: Unable to open 'sys/file.h' and we fix that by adding

&& !defined(OPENSSL_SYS_OS2)

on line 85 where it’s including sys/file.h and now this application builds also.

The Heisenbug

Now that we have crypto.lib and ssl.lib it’s time to try out OpenSSL with a simple example. Copying some code from the internet, and trying it out, we get a mysterious crash inside

SSL_CTX_new( method )

which causes the example program to terminate.

In order to debug this problem, we start by changing the optimization parameters and replace them with debugging symbols. In util/pl/OS2-OW.pl we make

$cflags="-DL_ENDIAN -d2 ";

in order for OpenSSL to be built with debugging symbols instead of optimizations.

Then we just delete everything in the out/ and tmp/ directories and build all over again with OS2-OW-NOASM.cmd and wmake -u -c -f OS2-OW.mak.

Lo and behold, there is no crash when we link with the new .lib files. This is definitely a Heisenbug.

Final Words

We now have a somewhat functioning OpenSSL port and can make simple applications such as hello, world work, albeit with a debug build, but more research is needed before the port can be considered finished. Particularly because there is a Heisenbug in the optimized version, which could be a code generation bug in OpenWatcom, or a symptom of something broken inside OpenSSL.

Do you need professional help with OS/2? Write to johann@myrkraverk.com.

Building OpenSSL with OpenWatcom on ArcaOS: First Porting Effort

I have previously written about my OpenSSL port to OS/2. Here I go over the first C code changes that make it compile with OpenWatcom 1.9.

As previously mentioned, I’m doing this on ArcaOS; so some Unix-ism will be present in the build system. This is apparently unavoidable, and fortunately, ArcaOS already comes with a lot of Unix ports; both out of the box and installed through yum (or the Arca Noae Package Manager).

The following changes leave us with a port that builds for the most part. Some parts will need more changes before they are strictly “correct” and we’ll return to those later.
Continue reading Building OpenSSL with OpenWatcom on ArcaOS: First Porting Effort

Building OpenSSL with OpenWatcom on ArcaOS: The Initial Hurdles

Building OpenSSL on a new system or compiler presents a lot of hurdles. The build system is a perl hack upon a perl hack; and no documentation about how it works, from what I can tell.

I am porting OpenSSL 1.0.2, which is what the software I want to work on expects. Hopefully my work can be applied to other versions as well.

Here I go through the initial steps to get a working build system on ArcaOS 5, also known as OS/2, using the OpenWatcom compiler; even though OpenSSL has already been ported to the EMX runtime, with GCC.

Because we’re using perl, the steps here are taken after installing perl with

yum install perl

and this gives us a working build system with the changes below, so the real work on porting OpenSSL can start.
Continue reading Building OpenSSL with OpenWatcom on ArcaOS: The Initial Hurdles

Using the OpenWatcom Assembler with Jam

I’ve previously covered the OS/2 port of Perforce Jam.

Here we’ll go over what it takes to make Jam know about the OpenWatcom assembler, Wasm.

First we can look at the Jambase file, in the source where we find the

actions As
{
$(AS) $(ASFLAGS) $(ASHDRS) -o $(<) $(>)
}

and we see that Jam has a few variables related to assembler files.

The Jamfile

First, we tell Jam that our assembler is Wasm.

AS = wasm ;

Then we redefine the As actions to be

actions As
{
$(AS) -q $(ASFLAGS) $(ASHDRS) -fo=$(<) $(>)
}

where -fo=$(<) is the output file, and $(>) the input file. We could also have used the newer syntax, $(1) and $(2). The -q tells Wasm to operate quetly; it means we won’t see the copyright information every time we run Jam; only the nice As file.asm output.

Now, we can make use of these changes with

Main hello.exe : hello.c sum.asm ;

The Sources

The source files we mentioned above are hello.c and sum.asm.

Here is hello.c

  #include <stdio.h>

  int sum( int a, int b );

  int main( int argc, char *argv[] ) {

    printf( "Hello, %d.\n", sum( 3, 5 ) );
    return 0;
  }

And here is sum.asm

  .386
  .model flat
  .code
  PUBLIC sum_
  sum_ PROC
      add eax, edx
      ret
  sum_ ENDP
  END

These two files demonstrate how we can declare a function in C, and then define it in an assembly file. We are using the register calling convention of OpenWatcom. The first argument is in eax, the second in edx and the return value is again in eax. That means we don’t have to worry about stack manipulation at all, in a simple function like sum(). OpenWatcom appends _ to function names with the register convention, so we have to append it also in the .asm file.

With the above Jamfile, we just run

jam

and our demonstration program is built and linked properly for us.

Running the Demo

Now, when we run

hello

on the command line, we see

Hello, 8.

Final Words

This has been written as Jamfile demonstration, but it can also be viewed as a demonstration of the register calling in OpenWatcom.

Do you need professional help with OS/2? Write to johann@myrkraverk.com.