Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit 3eb1a52

Browse files
committed
Merge pull request #97 from quarnster/pnacl
pnacl low hanging fruit. Fixes #96
2 parents 12f466a + 40e184c commit 3eb1a52

File tree

8 files changed

+44
-15
lines changed

8 files changed

+44
-15
lines changed

cmd/llgo-dist/buildruntime.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ func buildRuntime() (reterr error) {
2222
"os/user", // Issue #72
2323
"runtime/cgo", // Issue #73
2424
}
25+
if triple == "pnacl" {
26+
badPackages = append(badPackages,
27+
"crypto/md5",
28+
"crypto/rc4",
29+
"hash/crc32",
30+
"mime",
31+
"os/exec",
32+
"os/signal",
33+
"path/filepath",
34+
)
35+
}
2536

2637
output, err := command("go", "list", "std").CombinedOutput()
2738
if err != nil {
2839
return err
2940
}
30-
runtimePackages := strings.Split(strings.TrimSpace(string(output)), "\n")
41+
42+
// Always build runtime and syscall first
43+
// TODO: Real import dependency discovery to build packages in the order they depend on each other
44+
runtimePackages := append([]string{"runtime", "syscall"}, strings.Split(strings.TrimSpace(string(output)), "\n")...)
3145
outer:
3246
for _, pkg := range runtimePackages {
3347
// cmd's aren't packages

exports.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ func (c *compiler) packageExportsFile(path string) string {
4444
} else {
4545
gopath = filepath.SplitList(gopath)[0]
4646
}
47-
return filepath.Join(gopath, "pkg", "llgo", c.TargetTriple, path+".lgx")
47+
target := c.TargetTriple
48+
if c.pnacl {
49+
target = "pnacl"
50+
}
51+
return filepath.Join(gopath, "pkg", "llgo", target, path+".lgx")
4852
}
4953

5054
func (c *importer) Import(imports map[string]*types.Package, path string) (pkg *types.Package, err error) {

pkg/crypto/sha1/sha1block_decl.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2013 The llgo Authors
2+
// Use of this source code is governed by an MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package sha1
6+
7+
func block(dig *digest, p []byte)

pkg/os/file_pnacl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,7 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
431431
}
432432
return nil
433433
}
434+
435+
func Pipe() (r *File, w *File, err error) {
436+
return nil, nil, syscall.EPERM
437+
}

pkg/os/stat_pnacl.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
2121
fs := &fileStat{
2222
name: basename(name),
2323
size: int64(st.Size),
24-
modTime: timespecToTime(st.Mtim),
24+
modTime: time.Unix(st.Mtime, st.Mtimensec),
2525
sys: st,
2626
}
2727
fs.mode = FileMode(st.Mode & 0777)
@@ -53,11 +53,8 @@ func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
5353
return fs
5454
}
5555

56-
func timespecToTime(ts syscall.Timespec) time.Time {
57-
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
58-
}
59-
6056
// For testing.
6157
func atime(fi FileInfo) time.Time {
62-
return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
58+
st := fi.Sys().(*syscall.Stat_t)
59+
return time.Unix(st.Atime, st.Atimensec)
6360
}

pkg/syscall/syscall_pnacl.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
package syscall
88

99
import (
10-
"runtime"
11-
"sync"
1210
"unsafe"
1311
)
1412

13+
const ImplementsGetwd = false
14+
1515
var (
1616
Stdin = 0
1717
Stdout = 1
1818
Stderr = 2
1919
)
2020

21+
type SysProcAttr struct{}
22+
2123
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
2224
return 0, 0, EPERM
2325
}
@@ -188,7 +190,7 @@ func Exit(status int) {
188190
_exit(status)
189191
}
190192

191-
func Fstat(path string, buf *Stat_t) (err error) {
193+
func Fstat(fd int, buf *Stat_t) (err error) {
192194
return EPERM
193195
}
194196

@@ -293,8 +295,8 @@ func CloseOnExec(fd int) {
293295
}
294296

295297
func UtimesNano(path string, ts []Timespec) error {
296-
// TODO
297-
return EPERM
298+
// TODO
299+
return EPERM
298300
}
299301

300302
var ioSync int64

pkg/syscall/ztypes_pnacl.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Created by cgo -godefs - DO NOT EDIT
2-
// cgo -godefs -- -nostdinc -D__native_client__ -isystem /home/andrew/prog/nacl_sdk/pepper_canary/toolchain/linux_x86_pnacl/newlib/usr/include -isystem /home/andrew/prog/nacl_sdk/pepper_canary/include -isystem /home/andrew/prog/nacl_sdk/pepper_canary/toolchain/linux_x86_pnacl/host_x86_64/lib/clang/3.3/include -isystem /home/andrew/prog/nacl_sdk/pepper_canary/toolchain/linux_x86_pnacl/newlib/sysroot/include /home/andrew/prog/go/me/src/github.com/axw/llgo/pkg/syscall/types_pnacl.go
31

42
// +build pnacl
53

4+
// Created by cgo -godefs - DO NOT EDIT
5+
// cgo -godefs -objdir /var/folders/n1/yjqlqd2s04x7th1152h48hsr0000gn/T/llgo_dist381379107 -- -nostdinc -D__native_client__ -isystem /Users/quarnster/Downloads/nacl_sdk/pepper_29/toolchain/mac_x86_pnacl/newlib/usr/include -isystem /Users/quarnster/Downloads/nacl_sdk/pepper_29/include -isystem /Users/quarnster/Downloads/nacl_sdk/pepper_29/toolchain/mac_x86_pnacl/host_x86_64/lib/clang/3.3/include -isystem /Users/quarnster/Downloads/nacl_sdk/pepper_29/toolchain/mac_x86_pnacl/newlib/sysroot/include /Users/quarnster/code/go/src/github.com/axw/llgo/pkg/syscall/types_pnacl.go
6+
67
package syscall
78

89
const (

0 commit comments

Comments
 (0)