Skip to content

Commit 0489a26

Browse files
dhobsdrsc
authored andcommitted
FreeBSD-specific porting work.
cgo/libmach remain unimplemented. However, compilers, runtime, and packages are 100%. I still need to go through and implement missing syscalls (at least make sure they're all listed), but for all shipped functionality, this is done. Ship! ;) R=rsc, VenkateshSrinivas https://golang.org/cl/152142
1 parent 30b1b9a commit 0489a26

36 files changed

Lines changed: 3956 additions & 8 deletions

misc/cgo/stdio/test.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
# license that can be found in the LICENSE file.
55

66
set -e
7-
make hello fib chain
7+
gomake hello fib chain
88
echo '*' hello >run.out
99
./hello >>run.out
1010
echo '*' fib >>run.out
1111
./fib >>run.out
1212
echo '*' chain >>run.out
1313
./chain >>run.out
1414
diff run.out golden.out
15-
make clean
15+
gomake clean

src/cmd/6l/asm.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define PADDR(a) ((uint32)(a) & ~0x80000000)
3939

4040
char linuxdynld[] = "/lib64/ld-linux-x86-64.so.2";
41+
char freebsddynld[] = "/libexec/ld-elf.so.1";
4142

4243
char zeroes[32];
4344

@@ -284,7 +285,7 @@ doelf(void)
284285
Sym *s, *shstrtab, *dynamic, *dynstr, *d;
285286
int h, nsym, t;
286287

287-
if(HEADTYPE != 7)
288+
if(HEADTYPE != 7 && HEADTYPE != 9)
288289
return;
289290

290291
/* predefine strings we need for section headers */
@@ -317,7 +318,14 @@ doelf(void)
317318
s = lookup(".interp", 0);
318319
s->reachable = 1;
319320
s->type = SDATA; // TODO: rodata
320-
addstring(lookup(".interp", 0), linuxdynld);
321+
switch(HEADTYPE) {
322+
case 7:
323+
addstring(lookup(".interp", 0), linuxdynld);
324+
break;
325+
case 9:
326+
addstring(lookup(".interp", 0), freebsddynld);
327+
break;
328+
}
321329

322330
/*
323331
* hash table.
@@ -512,6 +520,7 @@ asmb(void)
512520
break;
513521

514522
case 7:
523+
case 9:
515524
debug['8'] = 1; /* 64-bit addresses */
516525
v = rnd(HEADR+textsize, INITRND);
517526
seek(cout, v, 0);
@@ -565,6 +574,7 @@ asmb(void)
565574
symo = rnd(HEADR+textsize, INITRND)+rnd(datsize, INITRND)+machlink;
566575
break;
567576
case 7:
577+
case 9:
568578
symo = rnd(HEADR+textsize, INITRND)+datsize;
569579
symo = rnd(symo, INITRND);
570580
break;
@@ -649,6 +659,7 @@ asmb(void)
649659
asmbmacho(symdatva, symo);
650660
break;
651661
case 7:
662+
case 9:
652663
/* elf amd-64 */
653664

654665
eh = getElfEhdr();
@@ -871,6 +882,8 @@ asmb(void)
871882
eh->ident[EI_MAG1] = 'E';
872883
eh->ident[EI_MAG2] = 'L';
873884
eh->ident[EI_MAG3] = 'F';
885+
if(HEADTYPE == 9)
886+
eh->ident[EI_OSABI] = 9;
874887
eh->ident[EI_CLASS] = ELFCLASS64;
875888
eh->ident[EI_DATA] = ELFDATA2LSB;
876889
eh->ident[EI_VERSION] = EV_CURRENT;

src/cmd/6l/obj.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ char* paramspace = "FP";
4646
* -H5 -T0x80110000 -R4096 is ELF32
4747
* -H6 -Tx -Rx is apple MH-exec
4848
* -H7 -Tx -Rx is linux elf-exec
49+
* -H9 -Tx -Rx is FreeBSD elf-exec
4950
*
5051
* options used: 189BLQSWabcjlnpsvz
5152
*/
@@ -149,6 +150,10 @@ main(int argc, char *argv[])
149150
if(strcmp(goos, "darwin") == 0)
150151
HEADTYPE = 6;
151152
else
153+
if(strcmp(goos, "freebsd") == 0) {
154+
debug['d'] = 1; /* no dynamic syms for now */
155+
HEADTYPE = 9;
156+
} else
152157
print("goos is not known: %s\n", goos);
153158
}
154159

@@ -194,6 +199,7 @@ main(int argc, char *argv[])
194199
INITDAT = 0;
195200
break;
196201
case 7: /* elf64 executable */
202+
case 9: /* freebsd */
197203
elfinit();
198204
HEADR = ELFRESERVE;
199205
if(INITTEXT == -1)

src/cmd/cov/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ clean:
2424

2525
install: install-$(shell uname | tr A-Z a-z)
2626
install-linux: install-default
27+
install-freebsd: install-default
2728

2829
# on Darwin, have to install and setgid; see $GOROOT/src/sudo.bash
2930
install-darwin: $(TARG)

src/cmd/prof/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ clean:
2424

2525
install: install-$(shell uname | tr A-Z a-z)
2626
install-linux: install-default
27+
install-freebsd: install-default
2728

2829
# on Darwin, have to install and setgid; see $GOROOT/src/sudo.bash
2930
install-darwin: $(TARG)

src/libcgo/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CFLAGS_amd64=-m64
1616

1717
LDFLAGS_linux=-shared -lpthread -lm
1818
LDFLAGS_darwin=-dynamiclib -Wl,-undefined,dynamic_lookup /usr/lib/libpthread.dylib
19+
LDFLAGS_freebsd=-pthread -shared -lm
1920

2021
%.o: %.c
2122
gcc $(CFLAGS_$(GOARCH)) -O2 -fPIC -o $@ -c $*.c

src/libcgo/freebsd_amd64.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
#include <pthread.h>
6+
#include "libcgo.h"
7+
8+
static void* threadentry(void*);
9+
10+
void
11+
initcgo(void)
12+
{
13+
}
14+
15+
void
16+
libcgo_sys_thread_start(ThreadStart *ts)
17+
{
18+
pthread_attr_t attr;
19+
pthread_t p;
20+
size_t size;
21+
22+
pthread_attr_init(&attr);
23+
pthread_attr_getstacksize(&attr, &size);
24+
ts->g->stackguard = size;
25+
pthread_create(&p, &attr, threadentry, ts);
26+
}
27+
28+
static void*
29+
threadentry(void *v)
30+
{
31+
ThreadStart ts;
32+
33+
ts = *(ThreadStart*)v;
34+
free(v);
35+
36+
ts.g->stackbase = (uintptr)&ts;
37+
38+
/*
39+
* libcgo_sys_thread_start set stackguard to stack size;
40+
* change to actual guard pointer.
41+
*/
42+
ts.g->stackguard = (uintptr)&ts - ts.g->stackguard + 4096;
43+
44+
crosscall_amd64(ts.m, ts.g, ts.fn);
45+
return nil;
46+
}

src/libmach/freebsd.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This is stubbed out for the moment. Will revisit when the time comes.
2+
#include <u.h>
3+
#include <libc.h>
4+
#include <bio.h>
5+
#include <mach.h>
6+
7+
int
8+
ctlproc(int pid, char *msg)
9+
{
10+
sysfatal("ctlproc unimplemented in FreeBSD");
11+
}
12+
13+
char*
14+
proctextfile(int pid)
15+
{
16+
sysfatal("proctextfile unimplemented in FreeBSD");
17+
}
18+
19+
char*
20+
procstatus(int pid)
21+
{
22+
sysfatal("procstatus unimplemented in FreeBSD");
23+
}
24+
25+
Map*
26+
attachproc(int pid, Fhdr *fp)
27+
{
28+
sysfatal("attachproc unimplemented in FreeBSD");
29+
}
30+
31+
void
32+
detachproc(Map *m)
33+
{
34+
sysfatal("detachproc unimplemented in FreeBSD");
35+
}
36+
37+
int
38+
procthreadpids(int pid, int *p, int np)
39+
{
40+
sysfatal("procthreadpids unimplemented in FreeBSD");
41+
}

src/pkg/debug/proc/proc_freebsd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package proc
6+
7+
import "os"
8+
9+
// Process tracing is not supported on FreeBSD yet.
10+
11+
func Attach(pid int) (Process, os.Error) {
12+
return nil, os.NewError("debug/proc not implemented on FreeBSD")
13+
}
14+
15+
func ForkExec(argv0 string, argv []string, envv []string, dir string, fd []*os.File) (Process, os.Error) {
16+
return Attach(0)
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright 2009 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package proc

0 commit comments

Comments
 (0)