Last update September 1, 2009

Gdc Hacking



Table of contents of this page
The GDC Hackers Guide   
GDC call for contributors!   
TODO   
Installing GDC (in the simplest way possible)   
GCC Structure   
gdc interface for language machine   
Read This   
GCC/GDB versions   
Apple versions   
Quicklinks   

The GDC Hackers Guide    

This page is meant as a resource for all of us that wants to help Walter develop the D language. In order for us to do this, we must learn how to understand and edit the GDC/GCC sources. This is very much easier said than done, but I hope that we together will prevail. NB: this is not a fork per se, but we will probably need to create an experimental repository for testing out features, and maybe some infrastructure for bug tracking... We all only want to see the D language evolve, not devolve, and I hope we will get Walter's blessing on this one.

-Nod-

Some of us also want to be able to use D on alternative operating systems and hardware architectures, beyond the Win32 and Linux X86 options offered by DMD. The GDC compiler works on several additional platforms, some examples:

  • Linux (X86/PPC/ARM)
  • Mac OS X (10.3.x, 10.4.x)
  • Darwin (X86/PPC)
  • FreeBSD 5.2.1
  • Cygwin
  • Solaris (SPARC)
There is also a lot of interest in making D available for the (not yet working) 64-bit platforms, such as X86_64 and PPC64.

Update: I included information and links for the GDB debugger on this page too, as it is kind of related to the GCC compiler ?

-- AndersFBjörklund

Great! Yes, anything related goes. I added DStress too, since creating test cases is a simple and sure way to improve the quality of the compilers.

-Nod-

Isn't GDC on Linux/X86_64 working now? I'm using it since some months ago, producing 64bit binaries, and it works ok.

-- RodolfoBorges?

GDC call for contributors!    

"Over the times since GDC was first released, there has been a fear that it would fall into oblivion as development has been somewhat sporadic. Now GDC looks closer to oblivion than ever, especially as LDC gets closer to a stable release. For Tango this could mean that support for GDC will be difficult to uphold.

"If you want to avoid this situation, help with the mantainance and development of GDC. Arthur Loiret, Debian's GDC mantainer, has promised to commit patches, but you must write them!

"For now, post your patches to bugzilla reports and/or talk to arthur- in #D / #d.tango. For those wanting to look closer at this, updating the frontend to latest DMD would probably be a good idea."

(from DsourceProject:tango/forums/topic/664)

"Arthur is Debian's GDC mantainer, and as far as I know, the only person beyond David with commit access to GDC." (from NG:digitalmars.D/80788)

TODO    

Prebuilt Mac OS X binary packages available from: http://sourceforge.net/projects/gdcmac/

Xcode 2.1 integration: http://www.alanz.com/d/xcode/

Spec files for building gdc rpms (adapted from Anders' original) are at http://languagemachine.sourceforge.net/gdc-0.14.spec. But I simplified the build to be directly equivalent to the standard build process, because the temporary install for unit-tests was causing me problems. To build with a different version of gdc, just change the version number at the beginning - works for gdc-0.15.

    • Neat, my RPM specfile needed some cleanup since it was written for an old version and I haven't used it myself in a while... (Gave up on doing a proper package while GDC was in flux, but it seems more stable again now). It's still missing some patches, such as the one to set the GDC and DMD version info to the version.c file and could probably lose some non-official patches too ?
      • Your specfile doesn't work on vanilla RPM, since it uses some Mandrake-specific macros such as %make ? It also seems to have commented out all arch/target stuff, which means it builds for the wrong platform... I will post a fixed version for GDC 0.15, just checking if it actually builds (and works) first. --afb
      • Thanks, I suspected I might have cut a few corners. I'll refer to your gdc spec from the language machine site. -- Peri.

Installing GDC (in the simplest way possible)    

https://dgcc.svn.sourceforge.net/svnroot/dgcc/trunk/d/INSTALL

or for Tango:

http://dsource.org/projects/tango/wiki/GdcInstallation

Also check out: http://dgcc.sourceforge.net/

Any questions? Go to the D.gnu newsgroup (or on this page somewhere)

GCC Structure    

I will give a short overview of the structure of GCC (for the newbies). GCC is a compiler for many languages and many targets, so it is divided into pieces.
  • frontend - Turn the source code into an internal representation - RTL (Register Transfer Language).
  • middleend - Perform optimizations on the RTL.
  • backend - Turn RTL into target-specific ASM instructions.
What we know as "GDC" is only an implementation of the frontend part of GCC. The middleend uses callbacks to interface with the frontend. GDC is located within its own subfolder in the "core" GCC source tree - (srcdir)/gcc/d/. It is within this subfolder that we must perform all changes to the language. GCC has other frontends such c (C), cp (C++), java (Java), objc (Objective-C), Fortran, Ada. One can look at these for advice, but one probably shouldn't... (one exception: the "c++" package is currently also required to build GDC, since the bundled recls library uses it)

Note that GDC is not an official language for GCC, but a "third party" addition. As such, it is similar to GPC (GNU Pascal Compiler), see http://www.gnu-pascal.de/

The frontend contains the lexer and parser - these together turn the source file into RTL. The GDC frontend relies heavily on the DMD sources to perform this work, and you will find the entire DMD sources in a subfolder.

Sadly, GCC is in a very poor state as far as code readability is concerned. Complex macros and source code generators litter the middle and backends. The source is well commented, but that really doesn't help... Well, Ill let you find out that by yourselves

The documentation (that I have read) is very hard to understand, so if anyone have any good resources, or tips, write them here. Happy hacking!

Note: RTL has now been replaced with Tree SSA in GCC 4.0 : http://gcc.gnu.org/gcc-4.0/changes.html This is among one of the reasons why GDC currently does not work with GCC 4.0, the internal representation is different. With RTL, each frontend could generate its own RTL dialect, with Tree SSA a standardized form of RTL called GENERIC must be generated by the frontends (if I have understood this correctly). So in order to make GDC work with GCC 4.0 and up, we must teach it to speak GENERIC. A brief overview of the IRs in GCC 4.0 can be found here: http://gcc.gnu.org/projects/tree-ssa/#gimple

But see NG:D.gnu/1315 for some great news:

The 4.0 code is not ready yet, but it shouldn't be too much longer.

David

And now it is here, with GDC 0.16:

NG:digitalmars.D.announce/1857

GDC now works with GCC 4.0.x. There are lots of fixes too. Go grab it!

David

gdc interface for language machine    

I have just updated the web pages at the language machine with an example of how stub procedures can be generated from the gcc file tree.def that is said to define the GENERIC interface. There's a rule set to make procedure stubs that produce trace output, and a hacked d-to-d translator backend that calls the stub procedures for a subset of D language expressions. It's all very preliminary - but it's a start, and may be useful.

Peri

Read This    

Here we gather some texts which can help out in order to understand GCC/GDC. GCC is very complex, and unless we acquire good documentation many will surely give up very soon.

  • DMD source guide; dmd internals
  • The GCC wiki - has some internals docs, see "Structure of GCC"
  • (if anyone knows of some good books, add them too)

GCC/GDB versions    

http://www.gnu.org/order/ftp.html

Older versions: (deprecated)

  • GCC 3.3.x
  • GDB 5.3
Previous versions:
  • GCC 3.4.x
  • GDB 6.3
Current versions:
  • GCC 4.0.x
  • GDB 6.4
Newer versions: (recommended)
  • GCC 4.1.x
  • GDB 6.5
GCC 2.9x is too old to work with GDC, and GCC 4.2x is too new (yet)...

Apple versions    

http://developer.apple.com/tools/gcc_overview.html

http://www.opensource.apple.com/darwinsource/

Here are the versions available for Mac OS X 10.3.x "Panther":

Previous versions: (Xcode Tools 1.0-1.1)

  • gcc-1495 (based on GCC 3.3)
  • gdb-282 (based on GDB 5.3)
Current versions: (Xcode Tools 1.2-1.5)
  • gcc-1762 (based on GCC 3.3.x)
  • gdb-330.1 (based on GDB 5.3)
Mac OS X 10.2.x "Jaguar" is too old (Jaguar has GCC 3.1 as the system compiler). But you can build a GCC 3.3 for your Jaguar system, matching the one available in the 2002 Developer Tools update. (gdcmac has such a pkg)

Mac OS X 10.4.x "Tiger" retains backwards compatibility and Xcode 2.x includes GCC 4.0, as well as 3.3 and 3.1. You can also install an optional Legacy PKG with GCC 2.95, and you can also build for both PowerPC and Intel.

Apple versions, for Mac OS X 10.4.x "Tiger":

New versions: (Xcode Tools 2.2)

  • gcc-5247 (based on GCC 4.0.1)
  • gdb-434 (based on GDB 6.3)
Note: Xcode 2.0-2.1 use GCC 4.0.0 and are very buggy in general. Upgrade to Xcode 2.2 or later!

Mac OS XApple GCCDeveloper Toolsa.k.a.
10.12.95.2"December 2001"ProjectBuilder 1.1
10.23.1 20021003"December 2002"ProjectBuilder 2.1
10.33.3 20030304"August 2004"Xcode 1.5
10.44.0.1"November 2005"Xcode 2.2

Quicklinks    


FrontPage | News | TestPage | MessageBoard | Search | Contributors | Folders | Index | Help | Preferences | Edit

Edit text of this page (date of last change: September 1, 2009 21:17 (diff))