diff --git a/plan9/asm_plan9_386.s b/plan9/asm_plan9_386.s index fc67ed1a..7484936f 100644 --- a/plan9/asm_plan9_386.s +++ b/plan9/asm_plan9_386.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" // TODO: How to refer to this? +#include "textflag.h" // // System call support for 386, Plan 9 diff --git a/plan9/asm_plan9_amd64.s b/plan9/asm_plan9_amd64.s index 41cb77e4..25f9dac6 100644 --- a/plan9/asm_plan9_amd64.s +++ b/plan9/asm_plan9_amd64.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" // TODO: How to refer to this? +#include "textflag.h" // // System call support for Plan 9 diff --git a/unix/asm_darwin_386.s b/unix/asm_darwin_386.s index 9b4dfa81..dfe94fb5 100644 --- a/unix/asm_darwin_386.s +++ b/unix/asm_darwin_386.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for 386, Darwin diff --git a/unix/asm_darwin_amd64.s b/unix/asm_darwin_amd64.s index 19ea05be..d6f1c96f 100644 --- a/unix/asm_darwin_amd64.s +++ b/unix/asm_darwin_amd64.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for AMD64, Darwin diff --git a/unix/asm_dragonfly_386.s b/unix/asm_dragonfly_386.s index d24216fd..37d655fb 100644 --- a/unix/asm_dragonfly_386.s +++ b/unix/asm_dragonfly_386.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for 386, FreeBSD diff --git a/unix/asm_dragonfly_amd64.s b/unix/asm_dragonfly_amd64.s index 31d10749..c8434f96 100644 --- a/unix/asm_dragonfly_amd64.s +++ b/unix/asm_dragonfly_amd64.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for AMD64, DragonFly diff --git a/unix/asm_freebsd_386.s b/unix/asm_freebsd_386.s index 91a46b10..f50b5a09 100644 --- a/unix/asm_freebsd_386.s +++ b/unix/asm_freebsd_386.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for 386, FreeBSD diff --git a/unix/asm_freebsd_amd64.s b/unix/asm_freebsd_amd64.s index 7abb3682..58cbfe1a 100644 --- a/unix/asm_freebsd_amd64.s +++ b/unix/asm_freebsd_amd64.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for AMD64, FreeBSD diff --git a/unix/asm_freebsd_arm.s b/unix/asm_freebsd_arm.s index c01ce6fe..5eb40334 100644 --- a/unix/asm_freebsd_arm.s +++ b/unix/asm_freebsd_arm.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System call support for ARM, FreeBSD diff --git a/unix/asm_linux_386.s b/unix/asm_linux_386.s index 30b22073..05cf89aa 100644 --- a/unix/asm_linux_386.s +++ b/unix/asm_linux_386.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System calls for 386, Linux diff --git a/unix/asm_linux_amd64.s b/unix/asm_linux_amd64.s index 995b60ec..51469328 100644 --- a/unix/asm_linux_amd64.s +++ b/unix/asm_linux_amd64.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System calls for AMD64, Linux diff --git a/unix/asm_linux_arm.s b/unix/asm_linux_arm.s index a28bc6cf..014fa618 100644 --- a/unix/asm_linux_arm.s +++ b/unix/asm_linux_arm.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" +#include "textflag.h" // // System calls for arm, Linux diff --git a/unix/asm_nacl_386.s b/unix/asm_nacl_386.s index 9ea1dc0d..cf041317 100644 --- a/unix/asm_nacl_386.s +++ b/unix/asm_nacl_386.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" #include "../runtime/syscall_nacl.h" // TODO: how to refer to this? // diff --git a/unix/asm_nacl_amd64p32.s b/unix/asm_nacl_amd64p32.s index 48b4af35..9e46d7bc 100644 --- a/unix/asm_nacl_amd64p32.s +++ b/unix/asm_nacl_amd64p32.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" #include "../runtime/syscall_nacl.h" // TODO: how to refer to this? // diff --git a/unix/asm_nacl_arm.s b/unix/asm_nacl_arm.s index a62650c6..ee8eb840 100644 --- a/unix/asm_nacl_arm.s +++ b/unix/asm_nacl_arm.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" #include "../runtime/syscall_nacl.h" // TODO: how to refer to this? // diff --git a/unix/asm_netbsd_386.s b/unix/asm_netbsd_386.s index 01e1c339..c5826325 100644 --- a/unix/asm_netbsd_386.s +++ b/unix/asm_netbsd_386.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" // // System call support for 386, NetBSD diff --git a/unix/asm_netbsd_amd64.s b/unix/asm_netbsd_amd64.s index a1dfa4b4..8285382c 100644 --- a/unix/asm_netbsd_amd64.s +++ b/unix/asm_netbsd_amd64.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" // // System call support for AMD64, NetBSD diff --git a/unix/asm_netbsd_arm.s b/unix/asm_netbsd_arm.s index 8e701456..b0611804 100644 --- a/unix/asm_netbsd_arm.s +++ b/unix/asm_netbsd_arm.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" // // System call support for ARM, NetBSD diff --git a/unix/asm_openbsd_386.s b/unix/asm_openbsd_386.s index 4351e43b..17fbb65c 100644 --- a/unix/asm_openbsd_386.s +++ b/unix/asm_openbsd_386.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" // // System call support for 386, OpenBSD diff --git a/unix/asm_openbsd_amd64.s b/unix/asm_openbsd_amd64.s index 31ea9b81..fe61482c 100644 --- a/unix/asm_openbsd_amd64.s +++ b/unix/asm_openbsd_amd64.s @@ -5,7 +5,7 @@ // TODO(rsc): Rewrite all nn(SP) references into name+(nn-8)(FP) // so that go vet can check that they are correct. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" // // System call support for AMD64, OpenBSD diff --git a/unix/mkall.sh b/unix/mkall.sh index 087ce05f..d890a8e8 100755 --- a/unix/mkall.sh +++ b/unix/mkall.sh @@ -120,7 +120,7 @@ darwin_386) ;; darwin_amd64) mkerrors="$mkerrors -m64" - mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h" + mksysnum="./mksysnum_darwin.pl /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/syscall.h" mktypes="GOARCH=$GOARCH go tool cgo -godefs" ;; dragonfly_386) diff --git a/unix/mkerrors.sh b/unix/mkerrors.sh new file mode 100755 index 00000000..ffe28cb9 --- /dev/null +++ b/unix/mkerrors.sh @@ -0,0 +1,246 @@ +#!/usr/bin/env bash +# Copyright 2009 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. + +# Generate Go code listing errors and other #defined constant +# values (ENAMETOOLONG etc.), by asking the preprocessor +# about the definitions. + +unset LANG +export LC_ALL=C +export LC_CTYPE=C + +CC=${CC:-gcc} + +uname=$(uname) + +includes=' +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +' + +ccflags="$@" + +# Write go tool cgo -godefs input. +( + echo package unix + echo + echo '/*' + indirect="includes_$(uname)" + echo "${!indirect} $includes" + echo '*/' + echo 'import "C"' + echo + echo 'const (' + + # The gcc command line prints all the #defines + # it encounters while processing the input + echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | + awk ' + $1 != "#define" || $2 ~ /\(/ || $3 == "" {next} + + $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers + $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} + $2 ~ /^(SCM_SRCRT)$/ {next} + $2 ~ /^(MAP_FAILED)$/ {next} + + $2 !~ /^ETH_/ && + $2 !~ /^EPROC_/ && + $2 !~ /^EQUIV_/ && + $2 !~ /^EXPR_/ && + $2 ~ /^E[A-Z0-9_]+$/ || + $2 ~ /^B[0-9_]+$/ || + $2 ~ /^V[A-Z0-9]+$/ || + $2 ~ /^CS[A-Z0-9]/ || + $2 ~ /^I(SIG|CANON|CRNL|EXTEN|MAXBEL|STRIP|UTF8)$/ || + $2 ~ /^IGN/ || + $2 ~ /^IX(ON|ANY|OFF)$/ || + $2 ~ /^IN(LCR|PCK)$/ || + $2 ~ /(^FLU?SH)|(FLU?SH$)/ || + $2 ~ /^C(LOCAL|READ)$/ || + $2 == "BRKINT" || + $2 == "HUPCL" || + $2 == "PENDIN" || + $2 == "TOSTOP" || + $2 ~ /^PAR/ || + $2 ~ /^SIG[^_]/ || + $2 ~ /^O[CNPFP][A-Z]+[^_][A-Z]+$/ || + $2 ~ /^IN_/ || + $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || + $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || + $2 == "ICMPV6_FILTER" || + $2 == "SOMAXCONN" || + $2 == "NAME_MAX" || + $2 == "IFNAMSIZ" || + $2 ~ /^CTL_(MAXNAME|NET|QUERY)$/ || + $2 ~ /^SYSCTL_VERS/ || + $2 ~ /^(MS|MNT)_/ || + $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || + $2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ || + $2 ~ /^LINUX_REBOOT_CMD_/ || + $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || + $2 !~ "NLA_TYPE_MASK" && + $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ || + $2 ~ /^SIOC/ || + $2 ~ /^TIOC/ || + $2 !~ "RTF_BITS" && + $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || + $2 ~ /^BIOC/ || + $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || + $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ || + $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || + $2 ~ /^CLONE_[A-Z_]+/ || + $2 !~ /^(BPF_TIMEVAL)$/ && + $2 ~ /^(BPF|DLT)_/ || + $2 !~ "WMESGLEN" && + $2 ~ /^W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", $2, $2)} + $2 ~ /^__WCOREFLAG$/ {next} + $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} + + {next} + ' | sort + + echo ')' +) >_const.go + +# Pull out the error names for later. +errors=$( + echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | + sort +) + +# Pull out the signal names for later. +signals=$( + echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | + egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | + sort +) + +# Again, writing regexps to a file. +echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | + sort >_error.grep +echo '#include ' | $CC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | + egrep -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT)' | + sort >_signal.grep + +echo '// mkerrors.sh' "$@" +echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT' +echo +go tool cgo -godefs -- "$@" _const.go >_error.out +cat _error.out | grep -vf _error.grep | grep -vf _signal.grep +echo +echo '// Errors' +echo 'const (' +cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/' +echo ')' + +echo +echo '// Signals' +echo 'const (' +cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= Signal(\1)/' +echo ')' + +# Run C program to print error and syscall strings. +( + echo -E " +#include +#include +#include +#include +#include +#include + +#define nelem(x) (sizeof(x)/sizeof((x)[0])) + +enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below + +int errors[] = { +" + for i in $errors + do + echo -E ' '$i, + done + + echo -E " +}; + +int signals[] = { +" + for i in $signals + do + echo -E ' '$i, + done + + # Use -E because on some systems bash builtin interprets \n itself. + echo -E ' +}; + +static int +intcmp(const void *a, const void *b) +{ + return *(int*)a - *(int*)b; +} + +int +main(void) +{ + int i, j, e; + char buf[1024], *p; + + printf("\n\n// Error table\n"); + printf("var errors = [...]string {\n"); + qsort(errors, nelem(errors), sizeof errors[0], intcmp); + for(i=0; i 0 && errors[i-1] == e) + continue; + strcpy(buf, strerror(e)); + // lowercase first letter: Bad -> bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + printf("\t%d: \"%s\",\n", e, buf); + } + printf("}\n\n"); + + printf("\n\n// Signal table\n"); + printf("var signals = [...]string {\n"); + qsort(signals, nelem(signals), sizeof signals[0], intcmp); + for(i=0; i 0 && signals[i-1] == e) + continue; + strcpy(buf, strsignal(e)); + // lowercase first letter: Bad -> bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + // cut trailing : number. + p = strrchr(buf, ":"[0]); + if(p) + *p = '\0'; + printf("\t%d: \"%s\",\n", e, buf); + } + printf("}\n\n"); + + return 0; +} + +' +) >_errors.c + +$CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out diff --git a/unix/time_nacl_386.s b/unix/time_nacl_386.s index d1fe6b1c..c0c89dcc 100644 --- a/unix/time_nacl_386.s +++ b/unix/time_nacl_386.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" TEXT ·startTimer(SB),NOSPLIT,$0 JMP time·startTimer(SB) diff --git a/unix/time_nacl_amd64p32.s b/unix/time_nacl_amd64p32.s index d1fe6b1c..c0c89dcc 100644 --- a/unix/time_nacl_amd64p32.s +++ b/unix/time_nacl_amd64p32.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" TEXT ·startTimer(SB),NOSPLIT,$0 JMP time·startTimer(SB) diff --git a/unix/time_nacl_arm.s b/unix/time_nacl_arm.s index 35174b79..4f4b4d89 100644 --- a/unix/time_nacl_arm.s +++ b/unix/time_nacl_arm.s @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "../../cmd/ld/textflag.h" // TODO: how to refer to this? +#include "textflag.h" TEXT ·startTimer(SB),NOSPLIT,$0 B time·startTimer(SB)