mirror of
https://github.com/golang/sys.git
synced 2026-02-08 11:46:04 +03:00
Right now the process for adding in new constants, errors, or syscalls for Linux is a pain and unreliable. The scripts are designed to be run on the target architecture and use the header files installed on the user's system. This makes it hard to generate files for all the architectures or to have consistency between users. See golang/go#15282. This CL fixes this issue by making all of the files for the 11 supported architectures directly from source checkouts of Linux, glibc, and bluez. This is done using Docker, the gcc cross-compilers, and qemu emulation. Previously discussed here: https://go-review.googlesource.com/c/37589/ A README.md file is also added to explain how all the parts of the build system work. In order to get the build working for all the architectures, I made some changes to the other scripts called from mkall_linux.go: - Files only used for generating linux code, moved to linux/ - linux/mksysnum.pl supports a specified CC compiler. - The generated C code in mkerrors.sh changed to avoid a warning - mkerrors.sh headers changed to fix powerpc64 bug in sys/ioctl.h - linux/types.go no longer needs to export Ptrace structs in lowercase Build instructions: - Host system needs to be x86-64 Linux - Install Docker (https://docs.docker.com/engine/installation/) - ./mkall.sh (That's it!!!) Change-Id: I87067c14442ba12f8d51991349a43a9d73f38ae0 Reviewed-on: https://go-review.googlesource.com/37943 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
86 lines
1.9 KiB
Perl
Executable File
86 lines
1.9 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
# 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.
|
|
|
|
use strict;
|
|
|
|
if($ENV{'GOARCH'} eq "" || $ENV{'GOOS'} eq "") {
|
|
print STDERR "GOARCH or GOOS not defined in environment\n";
|
|
exit 1;
|
|
}
|
|
|
|
# Check that we are using the new build system if we should
|
|
if($ENV{'GOLANG_SYS_BUILD'} ne "docker") {
|
|
print STDERR "In the new build system, mksysnum should not be called directly.\n";
|
|
print STDERR "See README.md\n";
|
|
exit 1;
|
|
}
|
|
|
|
my $command = "$0 ". join(' ', @ARGV);
|
|
|
|
print <<EOF;
|
|
// $command
|
|
// Code generated by the command above; see README.md. DO NOT EDIT.
|
|
|
|
// +build $ENV{'GOARCH'},$ENV{'GOOS'}
|
|
|
|
package unix
|
|
|
|
const(
|
|
EOF
|
|
|
|
my $offset = 0;
|
|
|
|
sub fmt {
|
|
my ($name, $num) = @_;
|
|
if($num > 999){
|
|
# ignore deprecated syscalls that are no longer implemented
|
|
# https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/unistd.h?id=refs/heads/master#n716
|
|
return;
|
|
}
|
|
$name =~ y/a-z/A-Z/;
|
|
$num = $num + $offset;
|
|
print " SYS_$name = $num;\n";
|
|
}
|
|
|
|
my $prev;
|
|
open(CC, "$ENV{'CC'} -E -dD @ARGV |") || die "can't run $ENV{'CC'}";
|
|
while(<CC>){
|
|
if(/^#define __NR_Linux\s+([0-9]+)/){
|
|
# mips/mips64: extract offset
|
|
$offset = $1;
|
|
}
|
|
elsif(/^#define __NR(\w*)_SYSCALL_BASE\s+([0-9]+)/){
|
|
# arm: extract offset
|
|
$offset = $1;
|
|
}
|
|
elsif(/^#define __NR_syscalls\s+/) {
|
|
# ignore redefinitions of __NR_syscalls
|
|
}
|
|
elsif(/^#define __NR_(\w*)Linux_syscalls\s+/) {
|
|
# mips/mips64: ignore definitions about the number of syscalls
|
|
}
|
|
elsif(/^#define __NR_(\w+)\s+([0-9]+)/){
|
|
$prev = $2;
|
|
fmt($1, $2);
|
|
}
|
|
elsif(/^#define __NR3264_(\w+)\s+([0-9]+)/){
|
|
$prev = $2;
|
|
fmt($1, $2);
|
|
}
|
|
elsif(/^#define __NR_(\w+)\s+\(\w+\+\s*([0-9]+)\)/){
|
|
fmt($1, $prev+$2)
|
|
}
|
|
elsif(/^#define __NR_(\w+)\s+\(__NR_Linux \+ ([0-9]+)/){
|
|
fmt($1, $2);
|
|
}
|
|
elsif(/^#define __NR_(\w+)\s+\(__NR_SYSCALL_BASE \+ ([0-9]+)/){
|
|
fmt($1, $2);
|
|
}
|
|
}
|
|
|
|
print <<EOF;
|
|
)
|
|
EOF
|