2. Porting the GNU Compiler to Win32
The first step in porting the compiler tools to Win32 was to
enhance them so that they could generate and interpret Win32 native
object files, using Microsoft's Portable Executable (PE) format. This
proved to be relatively straightforward because of similarities to the
Common Object File Format (COFF), which the GNU tools already
supported. Most of these changes were confined to the Binary File
Descriptor (BFD) library and to the linker.
In order to support the Win32 Application Programming Interface
(API), we extended the capabilities of the binary utilities to handle
Dynamic-Linked Libraries (DLLs). After creating export lists for the
specific Win32 API DLLs that are shipped with Win32 hosts, the tools
were able to generate static libraries that executables could use to
gain access to Win32 API functions. Because of redistribution
restrictions on Microsoft's Win32 API header files, we wrote our own
Win32 header files from scratch on an as-needed basis. Once this work
was completed, we were able to build UNIX-hosted cross-compilers
capable of generating valid PE executables that ran on Win32
systems.
The next task was to port the compiler tools themselves
to Win32. Previous experiences using Microsoft Visual C++ to port GDB
convinced us to find another means for bootstrapping the full set of
tools. In addition to wanting to use our own compiler technology, we
wanted a portable build system. The GNU development tools'
configuration and build procedures require a large number of
additional UNIX utilities not available on Win32 hosts. So we decided
to use UNIX-hosted cross-compilers to build our Win32-hosted native
and cross-development tools. It made perfect sense to do this since
we were successfully using a nearly identical technique to build our
DOS-hosted products.
The next obstacle to overcome was the many dependencies on UNIX
system calls in the sources, especially in the GNU debugger GDB.
While we could have rewritten sizable portions of the source code to
work within the context of the Win32 API (as was done for the
DOS-hosted tools), this would have been prohibitively time-consuming.
Worse, we would have introduced conditionalized code that would have
been expensive to maintain in the long run. Instead, Cygnus
developers took a substantially different approach by writing
Cygwin.
|