all: compiler/bootstrap for dragonfly/amd64

Add dragonfly/amd64 support to the Go compiler, bootstrap and GOOS list.

R=devon.odell, bradfitz
CC=golang-dev
https://golang.org/cl/12796050
diff --git a/src/cmd/6l/asm.c b/src/cmd/6l/asm.c
index 88fa67d..31c6b83 100644
--- a/src/cmd/6l/asm.c
+++ b/src/cmd/6l/asm.c
@@ -43,6 +43,7 @@
 char freebsddynld[] = "/libexec/ld-elf.so.1";
 char openbsddynld[] = "/usr/libexec/ld.so";
 char netbsddynld[] = "/libexec/ld.elf_so";
+char dragonflydynld[] = "/libexec/ld-elf.so.2";
 
 char	zeroes[32];
 
@@ -672,6 +673,7 @@
 	case Hfreebsd:
 	case Hnetbsd:
 	case Hopenbsd:
+	case Hdragonfly:
 		debug['8'] = 1;	/* 64-bit addresses */
 		break;
 	case Hwindows:
@@ -700,6 +702,7 @@
 		case Hfreebsd:
 		case Hnetbsd:
 		case Hopenbsd:
+		case Hdragonfly:
 			symo = rnd(HEADR+segtext.len, INITRND)+rnd(segrodata.len, INITRND)+segdata.filelen;
 			symo = rnd(symo, INITRND);
 			break;
@@ -790,6 +793,7 @@
 	case Hfreebsd:
 	case Hnetbsd:
 	case Hopenbsd:
+	case Hdragonfly:
 		asmbelf(symo);
 		break;
 	case Hwindows:
diff --git a/src/cmd/6l/obj.c b/src/cmd/6l/obj.c
index 30775e0..5337eca 100644
--- a/src/cmd/6l/obj.c
+++ b/src/cmd/6l/obj.c
@@ -48,6 +48,7 @@
 	"plan9", Hplan9x64,
 	"elf", Helf,
 	"darwin", Hdarwin,
+	"dragonfly", Hdragonfly,
 	"linux", Hlinux,
 	"freebsd", Hfreebsd,
 	"netbsd", Hnetbsd,
@@ -62,6 +63,7 @@
  *	-Hplan9 -T0x200028 -R0x200000	is plan9 64-bit format
  *	-Helf -T0x80110000 -R4096	is ELF32
  *	-Hdarwin -Tx -Rx		is apple MH-exec
+ *	-Hdragonfly -Tx -Rx		is DragonFly elf-exec
  *	-Hlinux -Tx -Rx			is linux elf-exec
  *	-Hfreebsd -Tx -Rx		is FreeBSD elf-exec
  *	-Hnetbsd -Tx -Rx		is NetBSD elf-exec
@@ -170,7 +172,7 @@
 	default:
 		diag("unknown -H option");
 		errorexit();
-	case Hplan9x32:	/* plan 9 */
+	case Hplan9x32:		/* plan 9 */
 		HEADR = 32L;
 		if(INITTEXT == -1)
 			INITTEXT = 4096+HEADR;
@@ -179,7 +181,7 @@
 		if(INITRND == -1)
 			INITRND = 4096;
 		break;
-	case Hplan9x64:	/* plan 9 */
+	case Hplan9x64:		/* plan 9 */
 		HEADR = 32L + 8L;
 		if(INITTEXT == -1)
 			INITTEXT = 0x200000+HEADR;
@@ -188,7 +190,7 @@
 		if(INITRND == -1)
 			INITRND = 0x200000;
 		break;
-	case Helf:	/* elf32 executable */
+	case Helf:		/* elf32 executable */
 		HEADR = rnd(52L+3*32L, 16);
 		if(INITTEXT == -1)
 			INITTEXT = 0x80110000L;
@@ -197,7 +199,7 @@
 		if(INITRND == -1)
 			INITRND = 4096;
 		break;
-	case Hdarwin:	/* apple MACH */
+	case Hdarwin:		/* apple MACH */
 		/*
 		 * OS X system constant - offset from 0(GS) to our TLS.
 		 * Explained in ../../pkg/runtime/cgo/gcc_darwin_amd64.c.
@@ -212,10 +214,11 @@
 		if(INITDAT == -1)
 			INITDAT = 0;
 		break;
-	case Hlinux:	/* elf64 executable */
-	case Hfreebsd:	/* freebsd */
-	case Hnetbsd:	/* netbsd */
-	case Hopenbsd:	/* openbsd */
+	case Hlinux:		/* elf64 executable */
+	case Hfreebsd:		/* freebsd */
+	case Hnetbsd:		/* netbsd */
+	case Hopenbsd:		/* openbsd */
+	case Hdragonfly:	/* dragonfly */
 		/*
 		 * ELF uses TLS offset negative from FS.
 		 * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
@@ -232,7 +235,7 @@
 		if(INITRND == -1)
 			INITRND = 4096;
 		break;
-	case Hwindows: /* PE executable */
+	case Hwindows:		/* PE executable */
 		peinit();
 		HEADR = PEFILEHEADR;
 		if(INITTEXT == -1)
diff --git a/src/cmd/6l/pass.c b/src/cmd/6l/pass.c
index 65e8127..be1bc4f 100644
--- a/src/cmd/6l/pass.c
+++ b/src/cmd/6l/pass.c
@@ -322,7 +322,7 @@
 		}
 		if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd
 		|| HEADTYPE == Hopenbsd || HEADTYPE == Hnetbsd
-		|| HEADTYPE == Hplan9x64) {
+		|| HEADTYPE == Hplan9x64 || HEADTYPE == Hdragonfly) {
 			// ELF uses FS instead of GS.
 			if(p->from.type == D_INDIR+D_GS)
 				p->from.type = D_INDIR+D_FS;
@@ -522,7 +522,8 @@
 			p->as = AMOVQ;
 			if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd
 			|| HEADTYPE == Hopenbsd || HEADTYPE == Hnetbsd
-			|| HEADTYPE == Hplan9x64)	// ELF uses FS
+			|| HEADTYPE == Hplan9x64 || HEADTYPE == Hdragonfly)
+				// ELF uses FS
 				p->from.type = D_INDIR+D_FS;
 			else
 				p->from.type = D_INDIR+D_GS;
diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c
index fa43c77..0a74ce8 100644
--- a/src/cmd/dist/build.c
+++ b/src/cmd/dist/build.c
@@ -48,6 +48,7 @@
 // The known operating systems.
 static char *okgoos[] = {
 	"darwin",
+	"dragonfly",
 	"linux",
 	"freebsd",
 	"netbsd",
diff --git a/src/cmd/dist/unix.c b/src/cmd/dist/unix.c
index 0011e2f..fa388e0 100644
--- a/src/cmd/dist/unix.c
+++ b/src/cmd/dist/unix.c
@@ -674,6 +674,8 @@
 		gohostarch = "amd64";
 #elif defined(__linux__)
 	gohostos = "linux";
+#elif defined(__DragonFly__)
+	gohostos = "dragonfly";
 #elif defined(__FreeBSD__)
 	gohostos = "freebsd";
 #elif defined(__FreeBSD_kernel__)
diff --git a/src/cmd/go/signal_unix.go b/src/cmd/go/signal_unix.go
index 124f356..00c7165 100644
--- a/src/cmd/go/signal_unix.go
+++ b/src/cmd/go/signal_unix.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 package main
 
diff --git a/src/cmd/ld/doc.go b/src/cmd/ld/doc.go
index 5f7c256..06b4116 100644
--- a/src/cmd/ld/doc.go
+++ b/src/cmd/ld/doc.go
@@ -33,6 +33,8 @@
 		linker. This flag cannot be used when $GOOS is windows.
 	-H darwin     (only in 6l/8l)
 		Write Apple Mach-O binaries (default when $GOOS is darwin)
+	-H dragonfly  (only in 6l)
+		Write DragonFly ELF binaries (default when $GOOS is dragonfly)
 	-H linux
 		Write Linux ELF binaries (default when $GOOS is linux)
 	-H freebsd
diff --git a/src/cmd/ld/elf.c b/src/cmd/ld/elf.c
index 52bf333..6b3638e 100644
--- a/src/cmd/ld/elf.c
+++ b/src/cmd/ld/elf.c
@@ -1189,6 +1189,9 @@
 			case Hopenbsd:
 				interpreter = openbsddynld;
 				break;
+			case Hdragonfly:
+				interpreter = dragonflydynld;
+				break;
 			}
 		}
 		resoff -= elfinterp(sh, startva, resoff, interpreter);
@@ -1461,6 +1464,8 @@
 		eh->ident[EI_OSABI] = ELFOSABI_NETBSD;
 	else if(HEADTYPE == Hopenbsd)
 		eh->ident[EI_OSABI] = ELFOSABI_OPENBSD;
+	else if(HEADTYPE == Hdragonfly)
+		eh->ident[EI_OSABI] = ELFOSABI_NONE;
 	if(PtrSize == 8)
 		eh->ident[EI_CLASS] = ELFCLASS64;
 	else
diff --git a/src/cmd/ld/elf.h b/src/cmd/ld/elf.h
index dee5a63..5b2ff04 100644
--- a/src/cmd/ld/elf.h
+++ b/src/cmd/ld/elf.h
@@ -1009,6 +1009,7 @@
 extern char freebsddynld[];
 extern char netbsddynld[];
 extern char openbsddynld[];
+extern char dragonflydynld[];
 int	elfreloc1(Reloc*, vlong sectoff);
 void	putelfsectionsyms(void);
 
diff --git a/src/cmd/ld/lib.h b/src/cmd/ld/lib.h
index 0ba5203..7ad630e 100644
--- a/src/cmd/ld/lib.h
+++ b/src/cmd/ld/lib.h
@@ -344,6 +344,7 @@
 	Hfreebsd,	// FreeBSD ELF
 	Hwindows,	// MS Windows PE
 	Hopenbsd,	// OpenBSD ELF
+	Hdragonfly,	// DragonFly ELF
 };
 
 typedef struct Header Header;
diff --git a/src/lib9/run_unix.c b/src/lib9/run_unix.c
index c26cf0a..3db33c7 100644
--- a/src/lib9/run_unix.c
+++ b/src/lib9/run_unix.c
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 #include <u.h>
 #include <errno.h>
diff --git a/src/lib9/tempdir_unix.c b/src/lib9/tempdir_unix.c
index 99a7092..3ce8775 100644
--- a/src/lib9/tempdir_unix.c
+++ b/src/lib9/tempdir_unix.c
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin freebsd linux netbsd openbsd
+// +build darwin dragonfly freebsd linux netbsd openbsd
 
 #include <u.h>
 #include <dirent.h>
diff --git a/src/libmach/dragonfly.c b/src/libmach/dragonfly.c
new file mode 100644
index 0000000..43dd005
--- /dev/null
+++ b/src/libmach/dragonfly.c
@@ -0,0 +1,62 @@
+// This is stubbed out for the moment. Will revisit when the time comes.
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+#include <mach.h>
+
+int
+ctlproc(int pid, char *msg)
+{
+	USED(pid);
+	USED(msg);
+
+	sysfatal("ctlproc unimplemented in DragonFly");
+	return -1;
+}
+
+char*
+proctextfile(int pid)
+{
+	USED(pid);
+	
+	sysfatal("proctextfile unimplemented in DragonFly");
+	return nil;
+}
+
+char*
+procstatus(int pid)
+{
+	USED(pid);
+
+	sysfatal("procstatus unimplemented in DragonFly");
+	return nil;
+}
+
+Map*
+attachproc(int pid, Fhdr *fp)
+{
+	USED(pid);
+	USED(fp);
+
+	sysfatal("attachproc unimplemented in DragonFly");
+	return nil;
+}
+
+void
+detachproc(Map *m)
+{
+	USED(m);
+
+	sysfatal("detachproc unimplemented in DragonFly");
+}
+
+int
+procthreadpids(int pid, int *p, int np)
+{
+	USED(pid);
+	USED(p);
+	USED(np);
+
+	sysfatal("procthreadpids unimplemented in DragonFly");
+	return -1;
+}
diff --git a/src/pkg/go/build/deps_test.go b/src/pkg/go/build/deps_test.go
index 1a85641..65c5efb 100644
--- a/src/pkg/go/build/deps_test.go
+++ b/src/pkg/go/build/deps_test.go
@@ -356,7 +356,7 @@
 }
 
 var bools = []bool{false, true}
-var geese = []string{"darwin", "freebsd", "linux", "netbsd", "openbsd", "plan9", "windows"}
+var geese = []string{"darwin", "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "plan9", "windows"}
 var goarches = []string{"386", "amd64", "arm"}
 
 type osPkg struct {
diff --git a/src/pkg/go/build/syslist.go b/src/pkg/go/build/syslist.go
index ea21f3c..e1fbf63 100644
--- a/src/pkg/go/build/syslist.go
+++ b/src/pkg/go/build/syslist.go
@@ -4,5 +4,5 @@
 
 package build
 
-const goosList = "darwin freebsd linux netbsd openbsd plan9 windows "
+const goosList = "darwin dragonfly freebsd linux netbsd openbsd plan9 windows "
 const goarchList = "386 amd64 arm "