Skip to content

Commit 4a269fc

Browse files
committed
Port of dmd to DragonFlyBSD
1 parent 66ad69b commit 4a269fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+290
-161
lines changed

ini/dragonflybsd/bin32/dmd.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Environment32]
2+
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib32 -L--export-dynamic
3+
4+
[Environment64]
5+
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib64 -L--export-dynamic

ini/dragonflybsd/bin64/dmd.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[Environment32]
2+
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib32 -L--export-dynamic
3+
4+
[Environment64]
5+
DFLAGS=-I%@P%/../../src/phobos -I%@P%/../../src/druntime/import -L-L%@P%/../lib64 -L--export-dynamic

src/dmd/argtypes.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ TypeTuple toArgTypes(Type t)
434434
}
435435
}
436436
}
437-
else if (!global.params.is64bit && global.params.isFreeBSD && t.sym.fields.dim == 1 &&
437+
else if (!global.params.is64bit && (global.params.isFreeBSD || global.params.isDragonFlyBSD) && t.sym.fields.dim == 1 &&
438438
(sz == 4 || sz == 8))
439439
{
440440
/* FreeBSD changed their 32 bit ABI at some point before 10.3 for the following:

src/dmd/astbase.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6307,7 +6307,8 @@ struct ASTBase
63076307
{
63086308
return Type.tchar.pointerTo();
63096309
}
6310-
else if (global.params.isLinux || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isSolaris || global.params.isOSX)
6310+
else if (global.params.isLinux || global.params.isFreeBSD || global.params.isOpenBSD || global.params.isDragonFlyBSD ||
6311+
global.params.isSolaris || global.params.isOSX)
63116312
{
63126313
if (global.params.is64bit)
63136314
{

src/dmd/backend/backconfig.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ void out_config_init(
178178
config.objfmt = OBJ_ELF;
179179
config.ehmethod = betterC ? EH_NONE : EH_DM;
180180
#endif
181+
#if TARGET_DRAGONFLYBSD
182+
if (model == 64)
183+
{ config.exe = EX_DRAGONFLYBSD64;
184+
config.ehmethod = betterC ? EH_NONE : EH_DWARF;
185+
config.fpxmmregs = TRUE;
186+
config.avx = avx;
187+
}
188+
else
189+
{
190+
assert(0); // Only 64-bit supported on DragonFlyBSD
191+
}
192+
config.flags |= CFGnoebp;
193+
if (!exe)
194+
{
195+
config.flags3 |= CFG3pic;
196+
config.flags |= CFGalwaysframe; // PIC needs a frame for TLS fixups
197+
}
198+
config.objfmt = OBJ_ELF;
199+
#endif
181200
#if TARGET_SOLARIS
182201
if (model == 64)
183202
{ config.exe = EX_SOLARIS64;
@@ -336,7 +355,7 @@ void util_set32()
336355
_tysize[TYnullptr] = LONGSIZE;
337356
_tysize[TYnptr] = LONGSIZE;
338357
_tysize[TYnref] = LONGSIZE;
339-
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
358+
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
340359
_tysize[TYldouble] = 12;
341360
_tysize[TYildouble] = 12;
342361
_tysize[TYcldouble] = 24;
@@ -363,7 +382,7 @@ void util_set32()
363382
_tyalignsize[TYnullptr] = LONGSIZE;
364383
_tyalignsize[TYnref] = LONGSIZE;
365384
_tyalignsize[TYnptr] = LONGSIZE;
366-
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
385+
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
367386
_tyalignsize[TYldouble] = 4;
368387
_tyalignsize[TYildouble] = 4;
369388
_tyalignsize[TYcldouble] = 4;
@@ -401,7 +420,7 @@ void util_set64()
401420
_tysize[TYnullptr] = 8;
402421
_tysize[TYnptr] = 8;
403422
_tysize[TYnref] = 8;
404-
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS || TARGET_OSX
423+
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS || TARGET_OSX
405424
_tysize[TYldouble] = 16;
406425
_tysize[TYildouble] = 16;
407426
_tysize[TYcldouble] = 32;
@@ -424,7 +443,7 @@ void util_set64()
424443
_tyalignsize[TYnullptr] = 8;
425444
_tyalignsize[TYnptr] = 8;
426445
_tyalignsize[TYnref] = 8;
427-
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
446+
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
428447
_tyalignsize[TYldouble] = 16;
429448
_tyalignsize[TYildouble] = 16;
430449
_tyalignsize[TYcldouble] = 16;

src/dmd/backend/cc.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ enum WM
5858
WM_ccast = 25,
5959
WM_obsolete = 26,
6060

61-
// if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
61+
// if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
6262
WM_skip_attribute = 27, // skip GNUC attribute specification
6363
WM_warning_message = 28, // preprocessor warning message
6464
WM_bad_vastart = 29, // args for builtin va_start bad
@@ -84,7 +84,7 @@ enum LANG
8484
//#include "msgs2.h"
8585
//#endif
8686
//#include "ty.h"
87-
//#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
87+
//#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
8888
//#include "../tk/mem.h"
8989
//#else
9090
//#include "mem.h"

src/dmd/backend/cc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ enum WM
7777
WM_badnumber = 24,
7878
WM_ccast = 25,
7979
WM_obsolete = 26,
80-
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
80+
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
8181
WM_skip_attribute = 27, // skip GNUC attribute specification
8282
WM_warning_message = 28, // preprocessor warning message
8383
WM_bad_vastart = 29, // args for builtin va_start bad
@@ -106,7 +106,7 @@ enum LANG
106106
#include "msgs2.h"
107107
#endif
108108
#include "ty.h"
109-
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
109+
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
110110
#include "../tk/mem.h"
111111
#else
112112
#include "mem.h"

src/dmd/backend/cdef.d

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ enum bool HEADER_LIST = true;
8585

8686
// Precompiled header variations
8787
//#define MEMORYHX (_WINDLL && _WIN32) // HX and SYM files are cached in memory
88-
//#define MMFIO (_WIN32 || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun) // if memory mapped files
88+
//#define MMFIO (_WIN32 || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun) // if memory mapped files
8989
//#define LINEARALLOC _WIN32 // if we can reserve address ranges
9090

9191
// H_STYLE takes on one of these precompiled header methods
@@ -272,7 +272,7 @@ enum
272272
{
273273
CHARSIZE = 1,
274274
SHORTSIZE = 2,
275-
WCHARSIZE = 2, // 2 for WIN32, 4 for linux/OSX/FreeBSD/OpenBSD/Solaris
275+
WCHARSIZE = 2, // 2 for WIN32, 4 for linux/OSX/FreeBSD/OpenBSD/DragonFlyBSD/Solaris
276276
LONGSIZE = 4,
277277
LLONGSIZE = 8,
278278
CENTSIZE = 16,
@@ -288,7 +288,7 @@ enum
288288
//#define REGMASK 0xFFFF
289289

290290
// targ_llong is also used to store host pointers, so it should have at least their size
291-
//#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS || TARGET_OSX || MARS
291+
//#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS || TARGET_OSX || MARS
292292
alias targ_ptrdiff_t = targ_llong; // ptrdiff_t for target machine
293293
alias targ_size_t = targ_ullong; // size_t for the target machine
294294
//#else
@@ -311,14 +311,14 @@ alias targ_size_t = targ_ullong; // size_t for the target machine
311311
//#define OMFOBJ TARGET_WINDOS
312312
//#endif
313313
//#ifndef ELFOBJ
314-
//#define ELFOBJ (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS)
314+
//#define ELFOBJ (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS)
315315
//#endif
316316
//#ifndef MACHOBJ
317317
//#define MACHOBJ TARGET_OSX
318318
//#endif
319319

320320
//#define SYMDEB_CODEVIEW TARGET_WINDOS
321-
//#define SYMDEB_DWARF (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS || TARGET_OSX)
321+
//#define SYMDEB_DWARF (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS || TARGET_OSX)
322322

323323
//#define TOOLKIT_H
324324

@@ -500,13 +500,15 @@ enum
500500
EX_SOLARIS64 = 0x200000,
501501
EX_OPENBSD = 0x400000,
502502
EX_OPENBSD64 = 0x800000,
503+
EX_DRAGONFLYBSD64 = 0x1000000,
503504
}
504505

505506

506507
// All flat memory models (no segment registers)
507508
enum exefmt_t EX_flat = EX_OS2 | EX_WIN32 | EX_LINUX | EX_WIN64 | EX_LINUX64 |
508509
EX_OSX | EX_OSX64 | EX_FREEBSD | EX_FREEBSD64 |
509510
EX_OPENBSD | EX_OPENBSD64 |
511+
EX_DRAGONFLYBSD64 |
510512
EX_SOLARIS | EX_SOLARIS64;
511513

512514
// All DOS executable types

src/dmd/backend/cdef.h

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
__APPLE__ Mac OSX
2727
__FreeBSD__ FreeBSD
2828
__OpenBSD__ OpenBSD
29+
__DragonFly__ DragonFlyBSD
2930
__sun Solaris, OpenSolaris, SunOS, OpenIndiana, etc
3031
__OS2__ IBM OS/2
3132
DOS386 32 bit DOS extended executable
@@ -126,6 +127,23 @@ One and only one of these macros must be set by the makefile:
126127
* with these goals, and should be fixed.
127128
*/
128129

130+
/* DragonFlyBSD Version
131+
* -------------
132+
* There are two main issues: hosting the compiler on OpenBSD,
133+
* and generating (targetting) OpenBSD executables.
134+
* The "__DragonFly__" and "__GNUC__" macros control hosting issues
135+
* for operating system and compiler dependencies, respectively.
136+
* To target DragonFlyBSD executables, use ELFOBJ for things specific to the
137+
* ELF object file format, and TARGET_DRAGONFLYBSD for things specific to
138+
* the DragonFlyBSD memory model.
139+
* If this is all done right, one could generate a DragonFlyBSD object file
140+
* even when compiling on linux/windows/osx etc, and vice versa.
141+
* The compiler source code currently uses these macros very inconsistently
142+
* with these goals, and should be fixed.
143+
*
144+
* DMD was Ported to DragonFlyBSD by Diederik de Groot <ddegroot [at] talon.nl>
145+
*/
146+
129147
/* Solaris Version
130148
* -------------
131149
* There are two main issues: hosting the compiler on Solaris,
@@ -186,14 +204,19 @@ One and only one of these macros must be set by the makefile:
186204
#define TARGET_OPENBSD 0 // target is an OpenBSD executable
187205
#endif
188206

207+
// Set to 1 using the makefile
208+
#ifndef TARGET_DRAGONFLYBSD
209+
#define TARGET_DRAGONFLYBSD 0 // target is a DragonFlyBSD executable
210+
#endif
211+
189212
// Set to 1 using the makefile
190213
#ifndef TARGET_SOLARIS
191214
#define TARGET_SOLARIS 0 // target is a Solaris executable
192215
#endif
193216

194217
// This is the default
195218
#ifndef TARGET_WINDOS
196-
#define TARGET_WINDOS (!(TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS))
219+
#define TARGET_WINDOS (!(TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS))
197220
#endif
198221

199222
#if __GNUC__
@@ -296,7 +319,7 @@ typedef long double longdouble;
296319

297320
// Precompiled header variations
298321
#define MEMORYHX (_WINDLL && _WIN32) // HX and SYM files are cached in memory
299-
#define MMFIO (_WIN32 || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun) // if memory mapped files
322+
#define MMFIO (_WIN32 || __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __sun) // if memory mapped files
300323
#define LINEARALLOC _WIN32 // if we can reserve address ranges
301324

302325
// H_STYLE takes on one of these precompiled header methods
@@ -503,7 +526,7 @@ enum
503526
{
504527
CHARSIZE = 1,
505528
SHORTSIZE = 2,
506-
WCHARSIZE = 2, // 2 for WIN32, 4 for linux/OSX/FreeBSD/OpenBSD/Solaris
529+
WCHARSIZE = 2, // 2 for WIN32, 4 for linux/OSX/FreeBSD/OpenBSD/DragonFlyBSD/Solaris
507530
LONGSIZE = 4,
508531
LLONGSIZE = 8,
509532
CENTSIZE = 16,
@@ -519,7 +542,7 @@ enum
519542
#define REGMASK 0xFFFF
520543

521544
// targ_llong is also used to store host pointers, so it should have at least their size
522-
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS || TARGET_OSX || MARS
545+
#if TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS || TARGET_OSX || MARS
523546
typedef targ_llong targ_ptrdiff_t; /* ptrdiff_t for target machine */
524547
typedef targ_ullong targ_size_t; /* size_t for the target machine */
525548
#else
@@ -542,14 +565,14 @@ typedef targ_uns targ_size_t; /* size_t for the target machine */
542565
#define OMFOBJ TARGET_WINDOS
543566
#endif
544567
#ifndef ELFOBJ
545-
#define ELFOBJ (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS)
568+
#define ELFOBJ (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS)
546569
#endif
547570
#ifndef MACHOBJ
548571
#define MACHOBJ TARGET_OSX
549572
#endif
550573

551574
#define SYMDEB_CODEVIEW TARGET_WINDOS
552-
#define SYMDEB_DWARF (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS || TARGET_OSX)
575+
#define SYMDEB_DWARF (TARGET_LINUX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS || TARGET_OSX)
553576

554577
#define TOOLKIT_H
555578

@@ -737,13 +760,15 @@ enum
737760
EX_SOLARIS64 = 0x200000,
738761
EX_OPENBSD = 0x400000,
739762
EX_OPENBSD64 = 0x800000,
763+
EX_DRAGONFLYBSD64 = 0x1000000,
740764
};
741765

742766

743767
// All flat memory models (no segment registers)
744768
const exefmt_t EX_flat = EX_OS2 | EX_WIN32 | EX_LINUX | EX_WIN64 | EX_LINUX64 |
745769
EX_OSX | EX_OSX64 | EX_FREEBSD | EX_FREEBSD64 |
746770
EX_OPENBSD | EX_OPENBSD64 |
771+
EX_DRAGONFLYBSD64 |
747772
EX_SOLARIS | EX_SOLARIS64;
748773

749774
// All DOS executable types

src/dmd/backend/cgcod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,7 @@ if (regcon.cse.mval & 1) elem_print(regcon.cse.value[0]);
25442544
case OPrelconst:
25452545
cdrelconst(cdb,e,pretregs);
25462546
break;
2547-
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_SOLARIS
2547+
#if TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_OPENBSD || TARGET_DRAGONFLYBSD || TARGET_SOLARIS
25482548
case OPgot:
25492549
cdgot(cdb,e,pretregs);
25502550
break;

0 commit comments

Comments
 (0)