Index: trunk/src/osx.mak
===================================================================
--- trunk/src/osx.mak	(revision 247)
+++ trunk/src/osx.mak	(working copy)
@@ -4,13 +4,13 @@
 ROOT=root
 
 ## See: http://developer.apple.com/documentation/developertools/conceptual/cross_development/Using/chapter_3_section_2.html#//apple_ref/doc/uid/20002000-1114311-BABGCAAB
-#ENVP= MACOSX_DEPLOYMENT_TARGET=10.3
-#SDK=/Developer/SDKs/MacOSX10.4u.sdk
+ENVP= MACOSX_DEPLOYMENT_TARGET=10.3
+SDK=/Developer/SDKs/MacOSX10.4u.sdk
 ##SDK=/Developer/SDKs/MacOSX10.6.sdk
-#LDFLAGS= -isysroot ${SDK} -Wl,-syslibroot,${SDK}
+LDFLAGS= -isysroot ${SDK} -Wl,-syslibroot,${SDK}
 
-#CC=g++ -m32 -isysroot $(SDK)
-CC=g++ -m32
+CC=g++ -m32 -isysroot $(SDK)
+#CC=g++ -m32
 
 #OPT=-g -g3
 #OPT=-O2
@@ -93,7 +93,7 @@
 all: dmd
 
 dmd: id.o optabgen $(DMD_OBJS)
-	${ENVP} gcc -m32 -lstdc++ $(LDFLAGS) $(COV) $(DMD_OBJS) -o dmd
+	${ENVP} gcc -m32 -lstdc++ $(LDFLAGS) $(COV) $(DMD_OBJS) -o dmd -framework CoreServices
 
 clean:
 	rm -f $(DMD_OBJS) dmd optab.o id.o impcnvgen idgen id.c id.h \
Index: trunk/src/backend/machobj.c
===================================================================
--- trunk/src/backend/machobj.c	(revision 247)
+++ trunk/src/backend/machobj.c	(working copy)
@@ -21,6 +21,10 @@
 #include	<malloc.h>
 #endif
 
+#if __APPLE__
+#import <CoreServices/CoreServices.h>
+#endif
+
 #if linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4
 #include	<signal.h>
 #include	<unistd.h>
@@ -1287,6 +1291,12 @@
 
 void obj_ehsections()
 {
+	SInt32 MacVersion;
+	SInt32 MacOSX_10_5 = 0x1050;
+	SInt32 MacOSX_10_6 = 0x1060;
+	
+	Gestalt(gestaltSystemVersion, &MacVersion);
+	
     //printf("obj_ehsections()\n");
     type *t = type_fake(TYint);
     t->Tmangle = mTYman_c;
@@ -1300,8 +1310,10 @@
     int seg = mach_getsegment("__deh_beg", "__DATA", 2, S_REGULAR);
     symbol *s_deh_beg = symbol_name("_deh_beg", SCglobal, t);
     objpubdef(seg, s_deh_beg, 0);
-    obj_bytes(seg, 0, 12, NULL);	// 12 is size of struct FuncTable in D runtime
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 12, NULL);	// 12 is size of struct FuncTable in D runtime
+
     seg = mach_getsegment("__deh_eh", "__DATA", 2, S_REGULAR);
     Outbuffer *buf = SegData[seg]->SDbuf;
     buf->writezeros(12);		// 12 is size of struct FuncTable in D runtime,
@@ -1310,52 +1322,81 @@
     seg = mach_getsegment("__deh_end", "__DATA", 2, S_REGULAR);
     symbol *s_deh_end = symbol_name("_deh_end", SCglobal, t);
     objpubdef(seg, s_deh_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
+
     /* Thread local storage sections
      */
     seg = mach_getsegment("__tls_beg", "__DATA", 2, S_REGULAR);
     symbol *s_tls_beg = symbol_name("_tls_beg", SCglobal, t);
     objpubdef(seg, s_tls_beg, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
-    seg = mach_getsegment("__tlsdata", "__DATA", 2, S_REGULAR);
-    SegData[seg]->SDbuf->writezeros(4);
+	if (MacVersion < MacOSX_10_6)
+		mach_getsegment("__tlsdata", "__DATA", 2, S_REGULAR); 
+		
+	else
+	{
+		obj_bytes(seg, 0, 4, NULL);
 
+	    seg = mach_getsegment("__tlsdata", "__DATA", 2, S_REGULAR);
+	    SegData[seg]->SDbuf->writezeros(4);
+	}
+
     seg = mach_getsegment("__tls_end", "__DATA", 2, S_REGULAR);
     symbol *s_tls_end = symbol_name("_tls_end", SCglobal, t);
     objpubdef(seg, s_tls_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
+
     /* Thread local comdat sections
      */
     seg = mach_getsegment("__tlscoal_beg", "__DATA", 2, S_REGULAR);
     symbol *s_tlscoal_beg = symbol_name("_tlscoal_beg", SCglobal, t);
     objpubdef(seg, s_tlscoal_beg, 0);
-    obj_bytes(seg, 0, 4, NULL);
+	
+	if (MacVersion < MacOSX_10_6)
+		mach_getsegment("__tlscoal_nt", "__DATA", 4, S_COALESCED);
+		
+	else
+	{
+		obj_bytes(seg, 0, 4, NULL);
 
-    seg = mach_getsegment("__tlscoal_nt", "__DATA", 4, S_COALESCED);
-    SegData[seg]->SDbuf->writezeros(4);
-
+	    seg = mach_getsegment("__tlscoal_nt", "__DATA", 4, S_COALESCED);
+	    SegData[seg]->SDbuf->writezeros(4);
+	}
+	
     seg = mach_getsegment("__tlscoal", "__DATA", 2, S_REGULAR);
     symbol *s_tlscoal_end = symbol_name("_tlscoal_end", SCglobal, t);
     objpubdef(seg, s_tlscoal_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
+
     /* Module info sections
      */
     seg = mach_getsegment("__minfo_beg", "__DATA", 2, S_REGULAR);
     symbol *s_minfo_beg = symbol_name("_minfo_beg", SCglobal, t);
     objpubdef(seg, s_minfo_beg, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
-    seg = mach_getsegment("__minfodata", "__DATA", 2, S_REGULAR);
-    SegData[seg]->SDbuf->writezeros(4);
+	if (MacVersion < MacOSX_10_6)
+		mach_getsegment("__minfodata", "__DATA", 2, S_REGULAR); 
+		
+	else
+	{
+		obj_bytes(seg, 0, 4, NULL);
 
+	    seg = mach_getsegment("__minfodata", "__DATA", 2, S_REGULAR);
+	    SegData[seg]->SDbuf->writezeros(4);
+	}
+
     seg = mach_getsegment("__minfo_end", "__DATA", 2, S_REGULAR);
     symbol *s_minfo_end = symbol_name("_minfo_end", SCglobal, t);
     objpubdef(seg, s_minfo_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
+
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
 }
 
 /*********************************
Index: branches/dmd-1.x/src/osx.mak
===================================================================
--- branches/dmd-1.x/src/osx.mak	(revision 247)
+++ branches/dmd-1.x/src/osx.mak	(working copy)
@@ -4,13 +4,13 @@
 ROOT=root
 
 ## See: http://developer.apple.com/documentation/developertools/conceptual/cross_development/Using/chapter_3_section_2.html#//apple_ref/doc/uid/20002000-1114311-BABGCAAB
-#ENVP= MACOSX_DEPLOYMENT_TARGET=10.3
-#SDK=/Developer/SDKs/MacOSX10.4u.sdk
+ENVP= MACOSX_DEPLOYMENT_TARGET=10.3
+SDK=/Developer/SDKs/MacOSX10.4u.sdk
 ##SDK=/Developer/SDKs/MacOSX10.6.sdk
-#LDFLAGS= -isysroot ${SDK} -Wl,-syslibroot,${SDK}
+LDFLAGS= -isysroot ${SDK} -Wl,-syslibroot,${SDK}
 
-#CC=g++ -m32 -isysroot $(SDK)
-CC=g++ -m32
+CC=g++ -m32 -isysroot $(SDK) -framework CoreServices
+#CC=g++ -m32
 
 #OPT=-g -g3
 #OPT=-O2
@@ -93,7 +93,7 @@
 all: dmd
 
 dmd: id.o optabgen $(DMD_OBJS)
-	${ENVP} gcc -m32 -lstdc++ $(LDFLAGS) $(COV) $(DMD_OBJS) -o dmd
+	${ENVP} gcc -m32 -lstdc++ $(LDFLAGS) $(COV) $(DMD_OBJS) -o dmd -framework CoreServices
 
 clean:
 	rm -f $(DMD_OBJS) dmd optab.o id.o impcnvgen idgen id.c id.h \
Index: branches/dmd-1.x/src/backend/machobj.c
===================================================================
--- branches/dmd-1.x/src/backend/machobj.c	(revision 247)
+++ branches/dmd-1.x/src/backend/machobj.c	(working copy)
@@ -26,6 +26,10 @@
 #include	<unistd.h>
 #endif
 
+#if __APPLE__
+#import <CoreServices/CoreServices.h>
+#endif
+
 #include	"cc.h"
 #include	"global.h"
 #include	"code.h"
@@ -1287,6 +1291,12 @@
 
 void obj_ehsections()
 {
+	SInt32 MacVersion;
+	SInt32 MacOSX_10_5 = 0x1050;
+	SInt32 MacOSX_10_6 = 0x1060;
+	
+	Gestalt(gestaltSystemVersion, &MacVersion);
+	
     //printf("obj_ehsections()\n");
     type *t = type_fake(TYint);
     t->Tmangle = mTYman_c;
@@ -1300,8 +1310,10 @@
     int seg = mach_getsegment("__deh_beg", "__DATA", 2, S_REGULAR);
     symbol *s_deh_beg = symbol_name("_deh_beg", SCglobal, t);
     objpubdef(seg, s_deh_beg, 0);
-    obj_bytes(seg, 0, 12, NULL);	// 12 is size of struct FuncTable in D runtime
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 12, NULL);	// 12 is size of struct FuncTable in D runtime
+
     seg = mach_getsegment("__deh_eh", "__DATA", 2, S_REGULAR);
     Outbuffer *buf = SegData[seg]->SDbuf;
     buf->writezeros(12);		// 12 is size of struct FuncTable in D runtime,
@@ -1310,52 +1322,81 @@
     seg = mach_getsegment("__deh_end", "__DATA", 2, S_REGULAR);
     symbol *s_deh_end = symbol_name("_deh_end", SCglobal, t);
     objpubdef(seg, s_deh_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
+
     /* Thread local storage sections
      */
     seg = mach_getsegment("__tls_beg", "__DATA", 2, S_REGULAR);
     symbol *s_tls_beg = symbol_name("_tls_beg", SCglobal, t);
     objpubdef(seg, s_tls_beg, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
-    seg = mach_getsegment("__tlsdata", "__DATA", 2, S_REGULAR);
-    SegData[seg]->SDbuf->writezeros(4);
+	if (MacVersion < MacOSX_10_6)
+		mach_getsegment("__tlsdata", "__DATA", 2, S_REGULAR);
+	
+	else
+	{
+		obj_bytes(seg, 0, 4, NULL);
 
+	    seg = mach_getsegment("__tlsdata", "__DATA", 2, S_REGULAR);
+	    SegData[seg]->SDbuf->writezeros(4);
+	}
+
     seg = mach_getsegment("__tls_end", "__DATA", 2, S_REGULAR);
     symbol *s_tls_end = symbol_name("_tls_end", SCglobal, t);
     objpubdef(seg, s_tls_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
+
     /* Thread local comdat sections
      */
     seg = mach_getsegment("__tlscoal_beg", "__DATA", 2, S_REGULAR);
     symbol *s_tlscoal_beg = symbol_name("_tlscoal_beg", SCglobal, t);
     objpubdef(seg, s_tlscoal_beg, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
-    seg = mach_getsegment("__tlscoal_nt", "__DATA", 4, S_COALESCED);
-    SegData[seg]->SDbuf->writezeros(4);
+	if (MacVersion < MacOSX_10_6)
+		mach_getsegment("__tlscoal_nt", "__DATA", 4, S_COALESCED);
+		
+	else
+	{
+		obj_bytes(seg, 0, 4, NULL);
 
+	    seg = mach_getsegment("__tlscoal_nt", "__DATA", 4, S_COALESCED);
+	    SegData[seg]->SDbuf->writezeros(4);
+	}
+
     seg = mach_getsegment("__tlscoal", "__DATA", 2, S_REGULAR);
     symbol *s_tlscoal_end = symbol_name("_tlscoal_end", SCglobal, t);
     objpubdef(seg, s_tlscoal_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
 
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
+
     /* Module info sections
      */
     seg = mach_getsegment("__minfo_beg", "__DATA", 2, S_REGULAR);
     symbol *s_minfo_beg = symbol_name("_minfo_beg", SCglobal, t);
     objpubdef(seg, s_minfo_beg, 0);
-    obj_bytes(seg, 0, 4, NULL);
+	
+	if (MacVersion < MacOSX_10_6)
+		mach_getsegment("__minfodata", "__DATA", 2, S_REGULAR);
+		
+	else
+	{
+		obj_bytes(seg, 0, 4, NULL);
 
-    seg = mach_getsegment("__minfodata", "__DATA", 2, S_REGULAR);
-    SegData[seg]->SDbuf->writezeros(4);
+	    seg = mach_getsegment("__minfodata", "__DATA", 2, S_REGULAR);
+	    SegData[seg]->SDbuf->writezeros(4);
+	}
 
     seg = mach_getsegment("__minfo_end", "__DATA", 2, S_REGULAR);
     symbol *s_minfo_end = symbol_name("_minfo_end", SCglobal, t);
     objpubdef(seg, s_minfo_end, 0);
-    obj_bytes(seg, 0, 4, NULL);
+
+	if (MacVersion >= MacOSX_10_6)
+    	obj_bytes(seg, 0, 4, NULL);
 }
 
 /*********************************
