## D Front End for GCC - Release 0.24

Last update: August 22, 2007

### Supported Systems

- GCC 3.4.x, 4.0.x, 4.1.x
- Linux (tested on Fedora Core 5 x86, x86_64, and PowerPC)
- Mac OS X 10.3.9, 10.4.x
- FreeBSD 6.x
- Cygwin
- MinGW
- AIX (tested on 5.1)

Similar versions of the above systems should work and other Unix platforms may work. Although the compiler will probably work on most architectures, the D runtime library will still need to be updated to support them.

### Requirements

The MacOS X universal binary package requires XCode 2.4.1 or the equivalent version of cctools.

### Downloads

- Main package
- Build Instructions

### Links

- GDC: D Compiler for GCC
- The D Programming Language
- D Links Page
- The D.gnu newsgroup
- For general D discussion, the digitalmars.D and digitalmars.D.bugs newsgroups
- The GNU Compiler Collection
- Mac OS X binary distribution

### Contact

David Friedman
e-mail: dvdfrdmn <at> users.sf.net

### Status

#### Known Issues

- See the DStress page for known failing cases.
- Debugging information may have a few problems. To enable D name mangling in gdb, apply this patch.
- Some targets do not support once-only linking. A workaround is to manually control template emission. See the -femit-templates option below. For Darwin, Apple's GCC 3.x compiler supports one-only linking, but GDC does not build with those sources. There are no problems with the stock GCC 4.x on Darwin.

- Complex floating point operations may not work the same as DMD.
- Some math functions behave differently due to different implementations of the extended floating-point type.
- Volatile statements may not always do the right thing.
- Because of a problem on AIX, the linker will pull in more modules than needed.
- Some C libraries (Cygwin, MinGW, AIX) don't handle floating-point formatting and parsing in a standard way.

#### Known Differences from DMD

- The type of _argptr in variadic functions is the target-specific va_list type. The only portable way to use _argptr is the std.stdarg.va_arg template. In particular, you cannot construct a va_list from a pointer to data an expect it to work.
- In assembler code, direct access to parameters in naked functions works differently. Frame relative addressing through [ESP+4] does work the same way.
- Currently, GDC uses the C calling convention for all functions except those declared extern (Windows).
- GDC allows catch statements in finally blocks.
- pragma(lib) is not supported.
- Some targets do not have a distinct extended floating-point type. On these targets, real and double are the same size.
- On Win32, GDC allocates 12 bytes for the real type, while DMD allocates 10 bytes. This also applies to the components of the creal type.

#### Inline Assembler Notes

- Getting GCC to respect the "naked" attribute is difficult. It is recommended that you use only assembler statements in a naked function. When generating position-independent code, accessing global symbols in a naked function will result in an error.
- Jumps from assembler statements will not run cleanups (auto and finally)

### Usage

#### Invoking gdc and gdmd

The compiler driver is named 'gdc' and accepts the standard GCC options. There is also a script named 'gdmd' which has the same interface as the Digital Mars dmd.
The mapping from DMD options to GCC is as follows:

-c | -c
-D | -fdoc
-Dd<docdir> | -fdoc-dir=<docdir>
-Df<filename> | -fdoc-file=<filename>
-d | -fdeprecated
-debug[=<arg>] | -fdebug[=<arg>]
-g | -g
-inline | -finline-functions
-I<path> | -I <path>
-J<path> | -J<path>
-L<arg> | -Wl,<arg>
-O | -O3 without inlining (may not be equivalent)
-o- | -fsyntax-only
-od<dir> | no equivalent; use the wrapper script
-of<file> | -o <file>
-op<dir> | no equivalent; use the wrapper script
-profile | (see the GCC manual for profiling options)
-quiet | no equivalent
-release | -frelease
-run | no equivalent; use the wrapper script
-unittest | -funittest
-version=<arg> | -fversion=<arg>
-w | -Wall
<.ddoc file> | -fdoc-inc=<.ddoc file>

Other options:

-f[no-]bounds-check | Controls array bounds checking

-femit-templates[=normal|private|all|none|auto]
-f[no-]emit-templates

Controls whether or not template code is emitted.
"normal" -- Emit templates, expecting multiple copies to be merged by the linker.
"private" -- Emit templates, but make them private to the translation unit. The executable will have multiple copies of code and data.
"all" -- Emit all template instances with public visibility. Do this even if they would not normally be emitted.
"none" -- Do not emit templates at all.
"auto" -- For targets that support templates, the "full" mode is used. Otherwise, the "private" mode is used.
"none" and -fno-emit-templates are synonyms.
"auto" and -femit-templates are synonyms.

-fall-sources | For each source file on the command line, semantically process each file preceding it. Use this if compilation errors occur due to complicated circular module references. This will slow compilation noticeably.
-fdump-source | Dump decoded UTF-8 text and source from HTML to <source>.utf-8 and <source>.d.utf-8.

#### Extensions

##### Extended Assembler

GDC implements a GCC extension that allows inline assembler with D expression operands. It is available on nearly all targets, not just i386. The syntax differs from the C language extension in the follow ways.

- Statements start with 'asm { ...', just like the regular DMD inline assembler.
- It is not necesary to put parentheses around operands.
- Instruction templates can be compile-time string constants, not just string literals. If the template is not a string literal, use parenthesis to indicate that it is not an opcode.

Unlike i386 inline assembler statements, extended assembler statements do not prevent a function from being inlined.
See the GCC manual for more information about this extension.
Example:
uint invert(uint v)
{
uint result;
version(X86)
asm{ "notl %[iov]" : [iov] "=r" result : "0" v; }
else version(PPC)
asm{ "nor %[oresult],%[iv],%[iv]" : [oresult] "=r" result : [iv] "r" v; }
return result;
}

##### Declaration and Type Attributes

(This extension is a work in progress.)
GDC implements the GCC __attribute__ extension with two pragmas:
pragma(GNU_attribute, name1(arg1, arg2, ...), ...) declarations...
pragma(GNU_set_attribute, symbol, name1(arg1, arg2...), ...);
If an attribute has no arguments, the argument list may be omitted.
The first form applies to declarations directly contained in the pragma. The second form affects the given symbol. See the GCC manual for a list of attributes that can be set. Not all attributes are supported yet by GDC. Also, the interaction between these extended attributes and D languge attributes (alignment, for example) is not well defined.

### Changes

0.24:

- Removed support for GCC 3.3.x
- Updated to DMD 1.020
- Fixed Bugzilla 1037, 1038 (gdc specific), 1043, 1045, 1046,
1031, 1032, 1034, 1065, 1109, 1191, 1137, 1152, 1208, 1325, 1329, 1898, 1400
- Fixed SourceForge issues 1689634, 1749622, 1721496, 1721435

0.23:

- Added support for 64-bit targets
- Added multilib support
- Updated to DMD 1.007
- Fixed Bugzilla 984, 1013

0.22:

- Added support for GCC 4.1.x
- Support for GCC 3.3.x is deprecated
- Updated to DMD 1.004
- Fixed Bugzilla 836, 837, 838, 839, 841, 843, 844, 889, 896
- Fixed problems with missing debug information
- Added Rick Mann's -frameowrk patch for gdmd

0.21:

- Updated to DMD 1.00
- Fixed Bugzilla 695, 696, 737, 738, 739, 742, 743, 745
- Implemented GCC extended assembler
- Implemented basic support for GCC attributes

0.20:

- Updated to DMD 0.177
- Fixes for synchronized code generation
- Better support for cross-hosted builds
- Fixed Bugzilla 307, 375, 403, 575, 578
- Applied Anders Björklund's MacOS X build patches

0.19:

- Fixed D Bugzilla bugs 141(gdc), 157, 162, 164, 171, 174, 175, 192, 229
- Applied Dave Fladebo's suggestion for -O3 in gdmd
- Updated to DMD 0.162
- The version symbol for FreeBSD is now "freebsd"
- Enabled std.loader for FreeBSD
- Implement offsetof in assembler
- Support building with Apple's GCC (4.0 only)
- Fix parallel builds

0.18:

- Fixes

- ICE on assignment arithmetic
- Problems mixing D and assembler floating point operations
- Mac OS X 10.2 build problems
- The gdc driver no longer compiles C source as C++.
- Many others...

- Improvements

- Updated to DMD 0.157.
- Added support for PowerPC Linux.
- Added partial support for SkyOS.
- Compiler can be relocated to another directory.

0.17:

- Fixes

- Mixed complex/float operations on GCC 4.0 (D.gnu/1485)
- Applied Thomas Kuhne's HTML line number fix
- Foreach/nested functions in templates (D.gnu/1514)
- Use correct default initializer when allocating arrays of typedef'd types
- Recursive calls to nested functions (D.gnu/1525)

- Improvements

- Updated to DMD 0.140

0.16:

- Fixes

- Concatenating a array and single element
- "__arrayArg already defined"
- ICE on nested foreach statements (D.gnu/1393)
- Inline assembler

- Functions returning floating point types

- Spurious error on scaled register without a base register
- Access to locals by var+ofs[EBP] now works with optimization.
- Can now guess operand size from referenced variables.

- Thunks errors with reimplemented interfaces (e.g., Mango)

- Improvements

- Support GCC 4.0.x
- Updated to DMD 0.137
- Support DW_LANG_D for DWARF debugging
- Support compiling multiple sources to a single object with GCC 3.4.x.

0.15:
Updated to DMD 0.128
0.14:

- Fixes

- Classes nested in functions actually work now.
- Fix for newest versions of the GNU assembler.

- Improvements

- Updated to DMD 0.127

0.13:

- Fixes

- Cygwin/MinGW assembler problem

- Improvements

- Updated to DMD 0.126.
- Calling nested functions with delegates is faster.
- The "check-target-libphobos" uses unit tests and runtime checks.

0.12.1:

- Fixes

- Compilation errors and crashes with -fpic
- Crashes with interfaces on Cygwin/MinGW
- Support the -mno-cygwin option

0.12:

- Fixes

- Various problems building MinGW in MSYS
- Mango "endless output"
- Build problems with gcc 3.4.1
- Various problems revealed by dmdscript
- Error message now go to standard error
- DStress catch_01, catch_02, new_04, switch_19, throw_02, and others.

- Improvements

- Updated to DMD 0.125
- New target: AIX
- GDC and DMD versions are reported with "gcc --version"
- Take advantage of DMD template improvements on

- Changes

- std.c.unix is now std.c.unix.unix
- The runtime library is now "libgphobos" to avoid conflicts with DMD.
- The dmd wrapper script...

- Is now named "gdmd".
- Looks for gdc in its own directory instead of searching the path
- Requires a comma after the "-q" option.

0.11:

- Fixes

- Reversed structure compare
- Correct meaning of '-L' option in wrapper script
- Static data GC bug on Linux

- Improvements

- Updated to DMD 0.121
- New target: MingGW
- Included Anders F Björklund's man pages.
- It is now possible to build a cross-compiler. Only MingGW is supported out-of-the-box, however.

### License

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA