Gdc Hacking
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)
Update: I included information and links for the GDB debugger on this page too, as it is kind of related to the GCC compiler ?
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)
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.
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:
|
And now it is here, with GDC 0.16:
NG:digitalmars.D.announce/1857
|
gdc interface for language machine
I have just updated the web pages at 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
- GCC 3.4.x
- GDB 6.3
- GCC 4.0.x
- GDB 6.4
- GCC 4.1.x
- GDB 6.5
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)
- gcc-1762 (based on GCC 3.3.x)
- gdb-330.1 (based on GDB 5.3)
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)
|
Quicklinks
GCC (the GNU Compiler Collection)
GDC ("GCC D Compiler")
GDB (the GNU Debugger)
Patching GDB to understand D code/mangling- DStress, test cases for D compilers