Skip to content

Commit

Permalink
lib9: enable on Plan 9
Browse files Browse the repository at this point in the history
This change depends on CL 57170052.

LGTM=rsc
R=rsc, bradfitz
CC=golang-codereviews
https://golang.org/cl/60840049
  • Loading branch information
0intro committed Feb 13, 2014
1 parent 705d7c1 commit 174b8c9
Show file tree
Hide file tree
Showing 44 changed files with 170 additions and 18 deletions.
1 change: 1 addition & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ build.out
test.out
doc/tmpltohtml
doc/articles/wiki/*.bin
include/plan9/libc_plan9.h
misc/cgo/life/run.out
misc/cgo/stdio/run.out
misc/cgo/testso/main
Expand Down
7 changes: 7 additions & 0 deletions include/plan9/errno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

int errno;

#define ERANGE 1001
64 changes: 64 additions & 0 deletions include/plan9/fmt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "../fmt.h"

#pragma varargck argpos fmtprint 2
#pragma varargck argpos fprint 2
#pragma varargck argpos print 1
#pragma varargck argpos runeseprint 3
#pragma varargck argpos runesmprint 1
#pragma varargck argpos runesnprint 3
#pragma varargck argpos runesprint 2
#pragma varargck argpos seprint 3
#pragma varargck argpos smprint 1
#pragma varargck argpos snprint 3
#pragma varargck argpos sprint 2

#pragma varargck type "lld" vlong
#pragma varargck type "llo" vlong
#pragma varargck type "llx" vlong
#pragma varargck type "llb" vlong
#pragma varargck type "lld" uvlong
#pragma varargck type "llo" uvlong
#pragma varargck type "llx" uvlong
#pragma varargck type "llb" uvlong
#pragma varargck type "ld" long
#pragma varargck type "lo" long
#pragma varargck type "lx" long
#pragma varargck type "lb" long
#pragma varargck type "ld" ulong
#pragma varargck type "lo" ulong
#pragma varargck type "lx" ulong
#pragma varargck type "lb" ulong
#pragma varargck type "d" int
#pragma varargck type "o" int
#pragma varargck type "x" int
#pragma varargck type "c" int
#pragma varargck type "C" int
#pragma varargck type "b" int
#pragma varargck type "d" uint
#pragma varargck type "x" uint
#pragma varargck type "c" uint
#pragma varargck type "C" uint
#pragma varargck type "b" uint
#pragma varargck type "f" double
#pragma varargck type "e" double
#pragma varargck type "g" double
#pragma varargck type "s" char*
#pragma varargck type "q" char*
#pragma varargck type "S" Rune*
#pragma varargck type "Q" Rune*
#pragma varargck type "r" void
#pragma varargck type "%" void
#pragma varargck type "n" int*
#pragma varargck type "p" uintptr
#pragma varargck type "p" void*
#pragma varargck flag ','
#pragma varargck flag ' '
#pragma varargck flag 'h'
#pragma varargck type "<" void*
#pragma varargck type "[" void*
#pragma varargck type "H" void*
#pragma varargck type "lH" void*
7 changes: 6 additions & 1 deletion include/plan9/libc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "/sys/include/libc.h"
#include "/sys/include/ctype.h"
#include "fmt.h"
#include "utf.h"
#include "libc_plan9.h"

char* getgoos(void);
char* getgoarch(void);
Expand All @@ -26,3 +28,6 @@ void flagprint(int);
// The libraries use size_t to avoid -Wconversion warnings from GCC
// when calling standard library functions like memcpy.
typedef unsigned long size_t;

// math.h
#define HUGE_VAL 1.79769313486231e+308
13 changes: 13 additions & 0 deletions include/plan9/mklibc.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/rc

pattern='/umuldiv/d
/UTFmax/d
/Runesync/d
/Runeself/d
/Runeerror/d
/Runemax/d
/rune routines/,/^\/\*/d
/print routines/,/^\/\*/d
/error string for/,/^\/\*/d'

sed -e $pattern /sys/include/libc.h
3 changes: 3 additions & 0 deletions include/plan9/stdarg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
5 changes: 5 additions & 0 deletions include/plan9/utf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "../utf.h"
19 changes: 4 additions & 15 deletions src/cmd/dist/build.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,13 +968,15 @@ install(char *dir)
vadd(&compile, "-m64");
else if(streq(gohostarch, "386"))
vadd(&compile, "-m32");
if(streq(dir, "lib9"))
vadd(&compile, "-DPLAN9PORT");

vadd(&compile, "-I");
vadd(&compile, bpathf(&b, "%s/include", goroot));
}

if(streq(dir, "lib9"))
vadd(&compile, "-DPLAN9PORT");


vadd(&compile, "-I");
vadd(&compile, bstr(&path));

Expand Down Expand Up @@ -1159,19 +1161,6 @@ shouldbuild(char *file, char *dir)
int i, j, ret;
Buf b;
Vec lines, fields;

// On Plan 9, most of the libraries are already present.
// The main exception is libmach which has been modified
// in various places to support Go object files.
if(streq(gohostos, "plan9")) {
if(streq(dir, "lib9")) {
name = lastelem(file);
if(streq(name, "goos.c") || streq(name, "flag.c"))
return 1;
if(!contains(name, "plan9"))
return 0;
}
}

// Check file name for GOOS or GOARCH.
name = lastelem(file);
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/_exits.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/_exits.c
http://code.swtch.com/plan9port/src/tip/src/lib9/_exits.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/_p9dir.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/_p9dir.c
http://code.swtch.com/plan9port/src/tip/src/lib9/_p9dir.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/atoi.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/ato*.c
http://code.swtch.com/plan9port/src/tip/src/lib9/atoi.c
Expand Down
1 change: 1 addition & 0 deletions src/lib9/await.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// +build !plan9
// +build !windows

/*
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/cleanname.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Inferno libkern/cleanname.c
http://code.google.com/p/inferno-os/source/browse/libkern/cleanname.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/create.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/create.c
http://code.swtch.com/plan9port/src/tip/src/lib9/create.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build !plan9

#define NOPLAN9DEFINES
#include <u.h>
#include <libc.h>
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/dirfstat.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/dirfstat.c
http://code.swtch.com/plan9port/src/tip/src/lib9/dirfstat.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/dirfwstat.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/dirfwstat.c
http://code.swtch.com/plan9port/src/tip/src/lib9/dirfwstat.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/dirstat.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/dirstat.c
http://code.swtch.com/plan9port/src/tip/src/lib9/dirstat.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/dirwstat.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/dirwstat.c
http://code.swtch.com/plan9port/src/tip/src/lib9/dirwstat.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/dup.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/dup.c
http://code.swtch.com/plan9port/src/tip/src/lib9/dup.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/exec.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/exec.c
http://code.swtch.com/plan9port/src/tip/src/lib9/exec.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/execl.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/execl.c
http://code.swtch.com/plan9port/src/tip/src/lib9/execl.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/exitcode.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/exitcode.c
http://code.swtch.com/plan9port/src/tip/src/lib9/exitcode.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/exits.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/_exits.c
http://code.swtch.com/plan9port/src/tip/src/lib9/_exits.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/fmtlock2.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/fmtlock2.c
http://code.swtch.com/plan9port/src/tip/src/lib9/fmtlock2.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/getenv.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/getenv.c
http://code.swtch.com/plan9port/src/tip/src/lib9/getenv.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/getwd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/getwd.c
http://code.swtch.com/plan9port/src/tip/src/lib9/getwd.c
Expand Down
1 change: 1 addition & 0 deletions src/lib9/jmp.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// +build !plan9
// +build !windows

/*
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/main.c
http://code.swtch.com/plan9port/src/tip/src/lib9/main.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/nan.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/nan.c
http://code.swtch.com/plan9port/src/tip/src/lib9/nan.c
Expand Down
1 change: 1 addition & 0 deletions src/lib9/notify.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// +build !plan9
// +build !windows

/*
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/nulldir.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Inferno lib9/nulldir.c
http://code.google.com/p/inferno-os/source/browse/lib9/nulldir.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/open.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/open.c
http://code.swtch.com/plan9port/src/tip/src/lib9/open.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/readn.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Inferno lib9/readn.c
http://code.google.com/p/inferno-os/source/browse/lib9/readn.c
Expand Down
1 change: 1 addition & 0 deletions src/lib9/rfork.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// +build !plan9
// +build !windows

/*
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/run_plan9.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build plan9

#include <u.h>
#include <libc.h>

Expand Down
2 changes: 2 additions & 0 deletions src/lib9/seek.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/seek.c
http://code.swtch.com/plan9port/src/tip/src/lib9/seek.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/strecpy.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Inferno lib9/strecpy.c
http://code.google.com/p/inferno-os/source/browse/lib9/strecpy.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/sysfatal.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/sysfatal.c
http://code.swtch.com/plan9port/src/tip/src/lib9/sysfatal.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/tempdir_plan9.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build plan9

#include <u.h>
#include <libc.h>

Expand Down
2 changes: 2 additions & 0 deletions src/lib9/time.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Plan 9 from User Space src/lib9/time.c
http://code.swtch.com/plan9port/src/tip/src/lib9/time.c
Expand Down
2 changes: 2 additions & 0 deletions src/lib9/tokenize.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !plan9

/*
Inferno lib9/tokenize.c
http://code.google.com/p/inferno-os/source/browse/lib9/tokenize.c
Expand Down
2 changes: 0 additions & 2 deletions src/libbio/bprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ Bvprint(Biobuf *bp, char *fmt, va_list arg)
Fmt f;

memset(&f, 0, sizeof f);
#ifndef PLAN9
fmtlocaleinit(&f, nil, nil, nil);
#endif
f.stop = bp->ebuf;
f.to = (char*)f.stop + bp->ocount;
f.flush = bflush;
Expand Down
3 changes: 3 additions & 0 deletions src/make.rc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ if(! test -f run.rc){
exit wrongdir
}

# Generate libc_plan9.h.
../include/plan9/mklibc.rc > ../include/plan9/libc_plan9.h

# Clean old generated file that will cause problems in the build.
rm -f ./pkg/runtime/runtime_defs.go

Expand Down

0 comments on commit 174b8c9

Please sign in to comment.