Merge pull request #364 from ClarkWang-2013/master

MIPS64EL: Add support for build libchromiumcontent.
This commit is contained in:
Cheng Zhao 2017-11-21 23:01:39 +09:00 коммит произвёл GitHub
Родитель b0c0a9e10b 20b6d687ec
Коммит 1f25411df9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
21 изменённых файлов: 1783 добавлений и 22 удалений

Просмотреть файл

@ -156,6 +156,22 @@ jobs:
- store_artifacts:
path: libchromiumcontent-static.zip
libchromiumcontent-linux-mips64el:
docker:
- image: electronbuilds/libchromiumcontent:0.0.4
environment:
TARGET_ARCH: mips64el
resource_class: xlarge
steps:
- checkout
- run: script/bootstrap
- run: script/update --clean -t $TARGET_ARCH
- run: script/build -t $TARGET_ARCH -c static_library
- run: script/build -t $TARGET_ARCH -c shared_library
- run: script/build -t $TARGET_ARCH -c ffmpeg
- run: script/create-dist -t $TARGET_ARCH
- run: script/upload -t $TARGET_ARCH
workflows:
version: 2
build-x64:

2
.gitignore поставляемый
Просмотреть файл

@ -6,6 +6,8 @@
/libchromiumcontent.zip
/libchromiumcontent-static.zip
/vendor/binutils-aarch64
/vendor/gcc-4.8.3-d197-n64-loongson
/vendor/readme-gcc483-loongson.txt
.gclient
.gclient_entries
_gclient_src_*

Просмотреть файл

@ -0,0 +1,41 @@
From 482fcd2171c58e1855b8f1d15657ad6811883746 Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Wed, 27 Sep 2017 09:54:14 +0800
Subject: [PATCH] Use system ninja-build instead of ninja in depot_tools on
Loongson(Mips64el) platform.
---
tools/gn/bootstrap/bootstrap.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/gn/bootstrap/bootstrap.py b/tools/gn/bootstrap/bootstrap.py
index 8252799..12d368e 100755
--- a/tools/gn/bootstrap/bootstrap.py
+++ b/tools/gn/bootstrap/bootstrap.py
@@ -24,6 +24,7 @@ import shutil
import subprocess
import sys
import tempfile
+import platform
BOOTSTRAP_DIR = os.path.dirname(os.path.abspath(__file__))
GN_ROOT = os.path.dirname(BOOTSTRAP_DIR)
@@ -196,7 +197,14 @@ def build_gn_with_ninja_manually(tempdir, options):
write_gn_ninja(os.path.join(tempdir, 'build.ninja'),
root_gen_dir, options)
- cmd = ['ninja', '-C', tempdir]
+
+ # ninja in depot_tools not support mips.
+ # use system ninja-build instead of ninja.
+ if platform.uname()[5] == 'mips64':
+ cmd = ['ninja-build', '-C', tempdir]
+ else:
+ cmd = ['ninja', '-C', tempdir]
+
if options.verbose:
cmd.append('-v')
--
2.1.0

Просмотреть файл

@ -0,0 +1,76 @@
From 891fc52b6efa19c547ae4c1d0bef4ffa4b67f730 Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Thu, 14 Sep 2017 16:21:51 +0800
Subject: [PATCH] Add support for mips64 with build gn.
This patch has merged into chromium master branch:
https://chromium.googlesource.com/chromium/src.git/+/a735e99b56ecaf6d6bd8e6af59e27eb7720906f2
---
build/toolchain/linux/BUILD.gn | 24 ++++++++++++++++++++++++
tools/gn/args.cc | 3 +++
2 files changed, 27 insertions(+)
diff --git a/build/toolchain/linux/BUILD.gn b/build/toolchain/linux/BUILD.gn
index 3be5c36..82e21aa 100644
--- a/build/toolchain/linux/BUILD.gn
+++ b/build/toolchain/linux/BUILD.gn
@@ -154,6 +154,13 @@ clang_toolchain("clang_mipsel") {
}
}
+clang_toolchain("clang_mips64el") {
+ toolchain_args = {
+ current_cpu = "mips64el"
+ current_os = "linux"
+ }
+}
+
gcc_toolchain("mipsel") {
cc = "mipsel-linux-gnu-gcc"
cxx = "mipsel-linux-gnu-g++"
@@ -170,3 +177,20 @@ gcc_toolchain("mipsel") {
use_goma = false
}
}
+
+gcc_toolchain("mips64el") {
+ cc = "gcc"
+ cxx = "g++"
+ ar = "ar"
+ ld = cxx
+ readelf = "readelf"
+ nm = "nm"
+
+ toolchain_args = {
+ cc_wrapper = ""
+ current_cpu = "mips64el"
+ current_os = "linux"
+ is_clang = false
+ use_goma = false
+ }
+}
diff --git a/tools/gn/args.cc b/tools/gn/args.cc
index 3bb40b4..185d3b0 100644
--- a/tools/gn/args.cc
+++ b/tools/gn/args.cc
@@ -312,6 +312,7 @@ void Args::SetSystemVarsLocked(Scope* dest) const {
static const char kArm[] = "arm";
static const char kArm64[] = "arm64";
static const char kMips[] = "mipsel";
+ static const char kMips64[] = "mips64el";
static const char kS390X[] = "s390x";
static const char kPPC64[] = "ppc64";
const char* arch = nullptr;
@@ -329,6 +330,8 @@ void Args::SetSystemVarsLocked(Scope* dest) const {
arch = kArm64;
else if (os_arch == "mips")
arch = kMips;
+ else if (os_arch == "mips64")
+ arch = kMips64;
else if (os_arch == "s390x")
arch = kS390X;
else if (os_arch == "mips")
--
2.1.0

Просмотреть файл

@ -0,0 +1,154 @@
From d7c8cfcc21ba626fdf0e943a679371d6ce7cd75e Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Fri, 15 Sep 2017 11:27:42 +0800
Subject: [PATCH] Add mips64el support and loongson3a for compiler.
This patch has merged into chromium master branch:
https://chromium.googlesource.com/chromium/src.git/+/f808fa2ee42b46124ed104dd46cd407632a492e0
https://chromium.googlesource.com/chromium/src.git/+/a735e99b56ecaf6d6bd8e6af59e27eb7720906f2
---
build/config/compiler/BUILD.gn | 26 ++++++++++++++++++++++++++
build/config/compiler/compiler.gni | 4 ++--
build/config/features.gni | 4 ++--
build/config/gcc/BUILD.gn | 2 +-
build/config/mips.gni | 9 ++++++++-
5 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 3b77c05..f098498 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -663,6 +663,24 @@ config("compiler_cpu_abi") {
"-Wa,-mips32",
]
}
+ } else if (mips_arch_variant == "loongson2e") {
+ cflags += [
+ "-march=loongson2e",
+ "-Wa,-march=loongson2e",
+ ]
+ ldfalgs += [ "-march=loongson2e" ]
+ } else if (mips_arch_variant == "loongson2f") {
+ cflags += [
+ "-march=loongson2f",
+ "-Wa,-march=loongson2f",
+ ]
+ ldfalgs += [ "-march=loongson2f" ]
+ } else if (mips_arch_variant == "loongson3") {
+ cflags += [
+ "-march=loongson3a",
+ "-Wa,-march=loongson3a",
+ ]
+ ldfalgs += [ "-march=loongson3a" ]
}
if (mips_dsp_rev == 1) {
@@ -702,6 +720,12 @@ config("compiler_cpu_abi") {
"-Wa,-mips64r2",
]
ldflags += [ "-mips64r2" ]
+ } else if (mips_arch_variant == "loongson3") {
+ cflags += [
+ "-march=loongson3a",
+ "-Wa,-march=loongson3a",
+ ]
+ ldflags += [ "-march=loongson3a" ]
}
} else if (current_cpu == "pnacl" && is_nacl_nonsfi) {
if (target_cpu == "x86" || target_cpu == "x64") {
@@ -1269,6 +1293,8 @@ config("no_incompatible_pointer_warnings") {
cflags += [ "-Wno-incompatible-pointer-types" ]
} else if (current_cpu == "mipsel") {
cflags += [ "-w" ]
+ } else if (current_cpu == "mips64el") {
+ cflags += [ "-w" ]
} else if (is_chromeos && current_cpu == "arm") {
cflags += [ "-w" ]
}
diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni
index e4f463a..637f57a 100644
--- a/build/config/compiler/compiler.gni
+++ b/build/config/compiler/compiler.gni
@@ -126,9 +126,9 @@ declare_args() {
declare_args() {
# Whether to use the gold linker from binutils instead of lld or bfd.
use_gold = !use_lld && !(is_chromecast && is_linux &&
- (current_cpu == "arm" || current_cpu == "mipsel")) &&
+ (current_cpu == "arm" || current_cpu == "mipsel" || current_cpu == "mips64el")) &&
((is_linux && (current_cpu == "x64" || current_cpu == "x86" ||
- current_cpu == "arm" || current_cpu == "mipsel")) ||
+ current_cpu == "arm" || current_cpu == "mipsel" || current_cpu == "mips64el")) ||
(is_android && (current_cpu == "x86" || current_cpu == "x64" ||
current_cpu == "arm" || current_cpu == "arm64")))
}
diff --git a/build/config/features.gni b/build/config/features.gni
index 441bd21..e06199fb 100644
--- a/build/config/features.gni
+++ b/build/config/features.gni
@@ -25,10 +25,10 @@ declare_args() {
# Temporarily disable nacl on arm64 linux to get rid of compilation errors.
# TODO(mcgrathr): When mipsel-nacl-clang is available, drop the exclusion.
enable_nacl = !is_ios && !is_android && !is_chromecast &&
- current_cpu != "mipsel" && !(is_linux && target_cpu == "arm64")
+ current_cpu != "mipsel" && current_cpu != "mips64el" && !(is_linux && target_cpu == "arm64")
# Non-SFI is not yet supported on mipsel
- enable_nacl_nonsfi = current_cpu != "mipsel"
+ enable_nacl_nonsfi = current_cpu != "mipsel" && current_cpu != "mips64el"
# Enables the Media Router.
enable_media_router = !is_ios && !is_chromecast
diff --git a/build/config/gcc/BUILD.gn b/build/config/gcc/BUILD.gn
index bf97f71..55ee374 100644
--- a/build/config/gcc/BUILD.gn
+++ b/build/config/gcc/BUILD.gn
@@ -105,7 +105,7 @@ config("executable_ldconfig") {
if (is_component_build || using_sanitizer) {
configs = [ ":rpath_for_built_shared_libraries" ]
}
- if (current_cpu == "mipsel") {
+ if (current_cpu == "mipsel" || current_cpu == "mips64el") {
ldflags += [ "-pie" ]
}
}
diff --git a/build/config/mips.gni b/build/config/mips.gni
index 5604ca6..994de41 100644
--- a/build/config/mips.gni
+++ b/build/config/mips.gni
@@ -14,6 +14,7 @@ if (current_cpu == "mipsel" || v8_current_cpu == "mipsel") {
# "r1"
# "r2"
# "r6"
+ # "loongson3"
mips_arch_variant = "r1"
# MIPS DSP ASE revision. Possible values are:
@@ -40,6 +41,7 @@ if (current_cpu == "mipsel" || v8_current_cpu == "mipsel") {
# MIPS arch variant. Possible values are:
# "r2"
# "r6"
+ # "loongson3"
if (current_os == "android" || target_os == "android") {
declare_args() {
mips_arch_variant = "r6"
@@ -49,10 +51,15 @@ if (current_cpu == "mipsel" || v8_current_cpu == "mipsel") {
}
} else {
declare_args() {
- mips_arch_variant = "r2"
+ mips_arch_variant = "loongson3"
# MIPS SIMD Arch compilation flag.
mips_use_msa = false
}
}
+
+ # MIPS floating-point ABI. Possible values are:
+ # "hard": sets the GCC -mhard-float option.
+ # "soft": sets the GCC -msoft-float option.
+ mips_float_abi = "hard"
}
--
2.1.0

Просмотреть файл

@ -0,0 +1,911 @@
From d49a019f05d0daead9859dbf21a9f159a8d13e54 Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Fri, 14 Jul 2017 16:21:21 +0800
Subject: [PATCH] Add support for using seccomp_bpf on mips64el.
Currently, seccomp_bpf is not supported on mips64el, and the build
configuration sets use_seccomp_bpf=false on mips64el. This CL adds
support for seccomp-bpf on mips64el, and resolves many compiler errors
when compiling on mips64el.
This patch merge into chromium master branch:
https://chromium.googlesource.com/chromium/src/+/534d7ce2af699715acfc4fe516ef3c2ffee65bc5
BUG: 742738
R= machenbach@chromium.org, brettw@chromium.org
---
base/macros.h | 10 +++
.../sandbox_linux/sandbox_seccomp_bpf_linux.cc | 4 +-
sandbox/features.gni | 5 +-
sandbox/linux/BUILD.gn | 1 +
sandbox/linux/bpf_dsl/linux_syscall_ranges.h | 9 ++-
sandbox/linux/bpf_dsl/seccomp_macros.h | 63 +++++++++++++++-
sandbox/linux/bpf_dsl/syscall_set.cc | 5 +-
.../linux/seccomp-bpf-helpers/baseline_policy.cc | 8 +-
.../linux/seccomp-bpf-helpers/sigsys_handlers.cc | 2 +-
sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc | 88 ++++++++++++----------
sandbox/linux/seccomp-bpf-helpers/syscall_sets.h | 13 ++--
sandbox/linux/seccomp-bpf/syscall.cc | 51 ++++++++++++-
sandbox/linux/system_headers/linux_seccomp.h | 3 +
sandbox/linux/system_headers/linux_signal.h | 9 ++-
sandbox/linux/system_headers/linux_syscalls.h | 4 +-
sandbox/linux/system_headers/linux_ucontext.h | 4 +-
.../linux/system_headers/mips64_linux_syscalls.h | 2 +-
.../linux/system_headers/mips64_linux_ucontext.h | 50 ++++++++++++
sandbox/linux/system_headers/mips_linux_syscalls.h | 2 +-
20 files changed, 267 insertions(+), 67 deletions(-)
create mode 100644 sandbox/linux/system_headers/mips64_linux_ucontext.h
diff --git a/base/macros.h b/base/macros.h
index 154d4b0..d88119a 100644
--- a/base/macros.h
+++ b/base/macros.h
@@ -12,6 +12,16 @@
#include <stddef.h> // For size_t.
+// Distinguish mips32.
+#if defined(__mips__) && (_MIPS_SIM == _ABIO32)
+#define __mips32__
+#endif
+
+// Distinguish mips64.
+#if defined(__mips__) && (_MIPS_SIM == _ABI64)
+#define __mips64__
+#endif
+
// Put this in the declarations for a class to be uncopyable.
#define DISALLOW_COPY(TypeName) \
TypeName(const TypeName&) = delete
diff --git a/content/common/sandbox_linux/sandbox_seccomp_bpf_linux.cc b/content/common/sandbox_linux/sandbox_seccomp_bpf_linux.cc
index 9b27f94..1ab05a7 100644
--- a/content/common/sandbox_linux/sandbox_seccomp_bpf_linux.cc
+++ b/content/common/sandbox_linux/sandbox_seccomp_bpf_linux.cc
@@ -47,9 +47,9 @@ using sandbox::bpf_dsl::ResultExpr;
// Make sure that seccomp-bpf does not get disabled by mistake. Also make sure
// that we think twice about this when adding a new architecture.
-#if !defined(ARCH_CPU_ARM64)
+#if !defined(ARCH_CPU_ARM64) && !defined(ARCH_CPU_MIPS64EL)
#error "Seccomp-bpf disabled on supported architecture!"
-#endif // !defined(ARCH_CPU_ARM64)
+#endif // !defined(ARCH_CPU_ARM64) && !defined(ARCH_CPU_MIPS64EL)
#endif //
diff --git a/sandbox/features.gni b/sandbox/features.gni
index aa18c04..89693c5 100644
--- a/sandbox/features.gni
+++ b/sandbox/features.gni
@@ -4,13 +4,14 @@
import("//build/config/nacl/config.gni")
-# The seccomp-bpf sandbox is only supported on five architectures
+# The seccomp-bpf sandbox is only supported on six architectures
# currently.
# Do not disable seccomp_bpf anywhere without talking to
# security@chromium.org!
use_seccomp_bpf =
(is_linux || is_android) &&
(current_cpu == "x86" || current_cpu == "x64" || current_cpu == "arm" ||
- current_cpu == "arm64" || current_cpu == "mipsel")
+ current_cpu == "arm64" || current_cpu == "mipsel" ||
+ current_cpu == "mips64el")
use_seccomp_bpf = use_seccomp_bpf || is_nacl_nonsfi
diff --git a/sandbox/linux/BUILD.gn b/sandbox/linux/BUILD.gn
index 421d8b0..4b321e2 100644
--- a/sandbox/linux/BUILD.gn
+++ b/sandbox/linux/BUILD.gn
@@ -431,6 +431,7 @@ source_set("sandbox_services_headers") {
"system_headers/linux_time.h",
"system_headers/linux_ucontext.h",
"system_headers/mips64_linux_syscalls.h",
+ "system_headers/mips64_linux_ucontext.h",
"system_headers/mips_linux_syscalls.h",
"system_headers/mips_linux_ucontext.h",
"system_headers/x86_32_linux_syscalls.h",
diff --git a/sandbox/linux/bpf_dsl/linux_syscall_ranges.h b/sandbox/linux/bpf_dsl/linux_syscall_ranges.h
index a747770..334a00b 100644
--- a/sandbox/linux/bpf_dsl/linux_syscall_ranges.h
+++ b/sandbox/linux/bpf_dsl/linux_syscall_ranges.h
@@ -33,16 +33,19 @@
#define MIN_GHOST_SYSCALL (MIN_PRIVATE_SYSCALL + 0xfff0u)
#define MAX_SYSCALL (MIN_GHOST_SYSCALL + 4u)
-#elif defined(__mips__) && (_MIPS_SIM == _ABIO32)
+#elif defined(__mips32__)
#include <asm/unistd.h> // for __NR_O32_Linux and __NR_Linux_syscalls
#define MIN_SYSCALL __NR_O32_Linux
#define MAX_PUBLIC_SYSCALL (MIN_SYSCALL + __NR_Linux_syscalls)
#define MAX_SYSCALL MAX_PUBLIC_SYSCALL
-#elif defined(__mips__) && (_MIPS_SIM == _ABI64)
+#elif defined(__mips64__)
-#error "Add support to header file"
+#include <asm/unistd.h> // for __NR_64_Linux and __NR_64_Linux_syscalls
+#define MIN_SYSCALL __NR_64_Linux
+#define MAX_PUBLIC_SYSCALL (MIN_SYSCALL + __NR_64_Linux_syscalls)
+#define MAX_SYSCALL MAX_PUBLIC_SYSCALL
#elif defined(__aarch64__)
diff --git a/sandbox/linux/bpf_dsl/seccomp_macros.h b/sandbox/linux/bpf_dsl/seccomp_macros.h
index af70f21..e4e8142 100644
--- a/sandbox/linux/bpf_dsl/seccomp_macros.h
+++ b/sandbox/linux/bpf_dsl/seccomp_macros.h
@@ -190,7 +190,7 @@ typedef user_regs regs_struct;
#define SECCOMP_PT_PARM5(_regs) (_regs).REG_r4
#define SECCOMP_PT_PARM6(_regs) (_regs).REG_r5
-#elif defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32)
+#elif defined(__mips32__)
#define SECCOMP_ARCH AUDIT_ARCH_MIPSEL
#define SYSCALL_EIGHT_ARGS
// MIPS sigcontext_t is different from i386/x86_64 and ARM.
@@ -224,7 +224,7 @@ typedef user_regs regs_struct;
#define SECCOMP_ARG_LSB_IDX(nr) (offsetof(struct arch_seccomp_data, args) + \
8*(nr) + 0)
-// On Mips we don't have structures like user_regs or user_regs_struct in
+// On MIPS we don't have structures like user_regs or user_regs_struct in
// sys/user.h that we could use, so we just define regs_struct directly.
struct regs_struct {
unsigned long long regs[32];
@@ -244,6 +244,65 @@ struct regs_struct {
#define SECCOMP_PT_PARM3(_regs) (_regs).REG_a2
#define SECCOMP_PT_PARM4(_regs) (_regs).REG_a3
+#elif defined(__mips64__)
+#define SECCOMP_ARCH AUDIT_ARCH_MIPSEL64
+#define SYSCALL_EIGHT_ARGS
+// MIPS sigcontext_t is different from i386/x86_64 and ARM.
+// See </arch/mips/include/uapi/asm/sigcontext.h> in the Linux kernel.
+#define SECCOMP_REG(_ctx, _reg) ((_ctx)->uc_mcontext.gregs[_reg])
+// Based on MIPS n64 ABI syscall convention.
+// On MIPS, when an indirect syscall is being made (syscall(__NR_foo)),
+// the real identifier (__NR_foo) is not in v0, but in a0.
+#define SECCOMP_RESULT(_ctx) SECCOMP_REG(_ctx, 2)
+#define SECCOMP_SYSCALL(_ctx) SECCOMP_REG(_ctx, 2)
+#define SECCOMP_IP(_ctx) (_ctx)->uc_mcontext.pc
+#define SECCOMP_PARM1(_ctx) SECCOMP_REG(_ctx, 4)
+#define SECCOMP_PARM2(_ctx) SECCOMP_REG(_ctx, 5)
+#define SECCOMP_PARM3(_ctx) SECCOMP_REG(_ctx, 6)
+#define SECCOMP_PARM4(_ctx) SECCOMP_REG(_ctx, 7)
+#define SECCOMP_PARM5(_ctx) SECCOMP_REG(_ctx, 8)
+#define SECCOMP_PARM6(_ctx) SECCOMP_REG(_ctx, 9)
+#define SECCOMP_PARM7(_ctx) SECCOMP_REG(_ctx, 10)
+#define SECCOMP_PARM8(_ctx) SECCOMP_REG(_ctx, 11)
+#define SECCOMP_NR_IDX (offsetof(struct arch_seccomp_data, nr))
+#define SECCOMP_ARCH_IDX (offsetof(struct arch_seccomp_data, arch))
+#define SECCOMP_IP_MSB_IDX (offsetof(struct arch_seccomp_data, \
+ instruction_pointer) + 4)
+#define SECCOMP_IP_LSB_IDX (offsetof(struct arch_seccomp_data, \
+ instruction_pointer) + 0)
+#define SECCOMP_ARG_MSB_IDX(nr) (offsetof(struct arch_seccomp_data, args) + \
+ 8*(nr) + 4)
+#define SECCOMP_ARG_LSB_IDX(nr) (offsetof(struct arch_seccomp_data, args) + \
+ 8*(nr) + 0)
+
+// On MIPS we don't have structures like user_regs or user_regs_struct in
+// sys/user.h that we could use, so we just define regs_struct directly.
+struct regs_struct {
+ unsigned long long regs[32];
+};
+
+#define REG_a7 regs[11]
+#define REG_a6 regs[10]
+#define REG_a5 regs[9]
+#define REG_a4 regs[8]
+#define REG_a3 regs[7]
+#define REG_a2 regs[6]
+#define REG_a1 regs[5]
+#define REG_a0 regs[4]
+#define REG_v1 regs[3]
+#define REG_v0 regs[2]
+
+#define SECCOMP_PT_RESULT(_regs) (_regs).REG_v0
+#define SECCOMP_PT_SYSCALL(_regs) (_regs).REG_v0
+#define SECCOMP_PT_PARM1(_regs) (_regs).REG_a0
+#define SECCOMP_PT_PARM2(_regs) (_regs).REG_a1
+#define SECCOMP_PT_PARM3(_regs) (_regs).REG_a2
+#define SECCOMP_PT_PARM4(_regs) (_regs).REG_a3
+#define SECCOMP_PT_PARM5(_regs) (_regs).REG_a4
+#define SECCOMP_PT_PARM6(_regs) (_regs).REG_a5
+#define SECCOMP_PT_PARM7(_regs) (_regs).REG_a6
+#define SECCOMP_PT_PARM8(_regs) (_regs).REG_a7
+
#elif defined(__aarch64__)
struct regs_struct {
unsigned long long regs[31];
diff --git a/sandbox/linux/bpf_dsl/syscall_set.cc b/sandbox/linux/bpf_dsl/syscall_set.cc
index 3d61fa3..b975a2b 100644
--- a/sandbox/linux/bpf_dsl/syscall_set.cc
+++ b/sandbox/linux/bpf_dsl/syscall_set.cc
@@ -14,9 +14,12 @@ namespace sandbox {
namespace {
-#if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32)
+#if defined(__mips32__)
// This is true for Mips O32 ABI.
static_assert(MIN_SYSCALL == __NR_Linux, "min syscall number should be 4000");
+#elif defined(__mips64__)
+// This is true for MIPS N64 ABI.
+static_assert(MIN_SYSCALL == __NR_Linux, "min syscall number should be 5000");
#else
// This true for supported architectures (Intel and ARM EABI).
static_assert(MIN_SYSCALL == 0u,
diff --git a/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
index 4889a9a..d06e765 100644
--- a/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
@@ -86,7 +86,7 @@ bool IsBaselinePolicyWatched(int sysno) {
SyscallSets::IsNuma(sysno) ||
SyscallSets::IsPrctl(sysno) ||
SyscallSets::IsProcessGroupOrSession(sysno) ||
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
SyscallSets::IsSocketCall(sysno) ||
#endif
#if defined(__arm__)
@@ -147,7 +147,7 @@ ResultExpr EvaluateSyscallImpl(int fs_denied_errno,
if (sysno == __NR_fcntl)
return RestrictFcntlCommands();
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
if (sysno == __NR_fcntl64)
return RestrictFcntlCommands();
#endif
@@ -191,7 +191,7 @@ ResultExpr EvaluateSyscallImpl(int fs_denied_errno,
return RestrictMmapFlags();
#endif
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
if (sysno == __NR_mmap2)
return RestrictMmapFlags();
#endif
@@ -241,7 +241,7 @@ ResultExpr EvaluateSyscallImpl(int fs_denied_errno,
return Error(EPERM);
}
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
if (SyscallSets::IsSocketCall(sysno))
return RestrictSocketcallCommand();
#endif
diff --git a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
index e6c64de..68890d2 100644
--- a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
@@ -95,7 +95,7 @@ void PrintSyscallError(uint32_t sysno) {
sysno_base10[i] = '0' + mod;
}
-#if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32)
+#if defined(__mips32__)
static const char kSeccompErrorPrefix[] = __FILE__
":**CRASHING**:" SECCOMP_MESSAGE_COMMON_CONTENT " in syscall 4000 + ";
#else
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc b/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
index 1d9f95c..9f1cdef 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc
@@ -28,7 +28,7 @@ bool SyscallSets::IsKill(int sysno) {
bool SyscallSets::IsAllowedGettime(int sysno) {
switch (sysno) {
case __NR_gettimeofday:
-#if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__mips32__)
case __NR_time:
#endif
return true;
@@ -38,11 +38,11 @@ bool SyscallSets::IsAllowedGettime(int sysno) {
case __NR_clock_gettime:
case __NR_clock_nanosleep: // Could be allowed.
case __NR_clock_settime: // Privileged.
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_ftime: // Obsolete.
#endif
case __NR_settimeofday: // Privileged.
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_stime:
#endif
default:
@@ -97,7 +97,9 @@ bool SyscallSets::IsFileSystem(int sysno) {
case __NR_stat: // EPERM not a valid errno.
case __NR_symlink:
case __NR_unlink:
+#if !defined(__mips64__)
case __NR_uselib: // Neither EPERM, nor ENOENT are valid errno.
+#endif
case __NR_ustat: // Same as above. Deprecated.
case __NR_utimes:
#endif // !defined(__aarch64__)
@@ -108,7 +110,7 @@ bool SyscallSets::IsFileSystem(int sysno) {
case __NR_fchownat: // Should be called chownat ?
#if defined(__x86_64__) || defined(__aarch64__)
case __NR_newfstatat: // fstatat(). EPERM not a valid errno.
-#elif defined(__i386__) || defined(__arm__) || defined(__mips__)
+#elif defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_fstatat64:
#endif
#if defined(__i386__) || defined(__arm__)
@@ -117,7 +119,7 @@ bool SyscallSets::IsFileSystem(int sysno) {
case __NR_linkat:
case __NR_lookup_dcookie: // ENOENT not a valid errno.
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_lstat64:
#endif
case __NR_memfd_create:
@@ -131,16 +133,16 @@ bool SyscallSets::IsFileSystem(int sysno) {
case __NR_readlinkat:
case __NR_renameat:
case __NR_renameat2:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_stat64:
#endif
case __NR_statfs: // EPERM not a valid errno.
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_statfs64:
#endif
case __NR_symlinkat:
case __NR_truncate:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_truncate64:
#endif
case __NR_unlinkat:
@@ -157,7 +159,7 @@ bool SyscallSets::IsFileSystem(int sysno) {
bool SyscallSets::IsAllowedFileSystemAccessViaFd(int sysno) {
switch (sysno) {
case __NR_fstat:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_fstat64:
#endif
return true;
@@ -174,7 +176,7 @@ bool SyscallSets::IsAllowedFileSystemAccessViaFd(int sysno) {
case __NR_fdatasync: // EPERM not a valid errno.
case __NR_flock: // EPERM not a valid errno.
case __NR_fstatfs: // Give information about the whole filesystem.
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_fstatfs64:
#endif
case __NR_fsync: // EPERM not a valid errno.
@@ -202,14 +204,14 @@ bool SyscallSets::IsDeniedFileSystemAccessViaFd(int sysno) {
#if defined(__i386__) || defined(__arm__)
case __NR_fchown32:
#endif
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_ftruncate64:
#endif
#if !defined(__aarch64__)
case __NR_getdents: // EPERM not a valid errno.
#endif
case __NR_getdents64: // EPERM not a valid errno.
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_readdir:
#endif
return true;
@@ -299,7 +301,7 @@ bool SyscallSets::IsAllowedSignalHandling(int sysno) {
case __NR_rt_sigaction:
case __NR_rt_sigprocmask:
case __NR_rt_sigreturn:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_sigaction:
case __NR_sigprocmask:
case __NR_sigreturn:
@@ -315,11 +317,11 @@ bool SyscallSets::IsAllowedSignalHandling(int sysno) {
case __NR_signalfd:
#endif
case __NR_signalfd4:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_sigpending:
case __NR_sigsuspend:
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_signal:
case __NR_sgetmask: // Obsolete.
case __NR_ssetmask:
@@ -343,7 +345,7 @@ bool SyscallSets::IsAllowedOperationOnFd(int sysno) {
#endif
return true;
case __NR_fcntl:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_fcntl64:
#endif
default:
@@ -460,12 +462,14 @@ bool SyscallSets::IsDeniedGetOrModifySocket(int sysno) {
}
}
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
// Big multiplexing system call for sockets.
bool SyscallSets::IsSocketCall(int sysno) {
switch (sysno) {
+#if !defined(__mips64__)
case __NR_socketcall:
return true;
+#endif
default:
return false;
}
@@ -500,10 +504,10 @@ bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
defined(__aarch64__)
case __NR_mmap:
#endif
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_mmap2:
#endif
-#if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
+#if defined(__i386__) || defined(__x86_64__) || defined(__mips32__)
case __NR_modify_ldt:
#endif
case __NR_mprotect:
@@ -524,7 +528,7 @@ bool SyscallSets::IsAllowedAddressSpaceAccess(int sysno) {
bool SyscallSets::IsAllowedGeneralIo(int sysno) {
switch (sysno) {
case __NR_lseek:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR__llseek:
#endif
#if !defined(__aarch64__)
@@ -534,7 +538,7 @@ bool SyscallSets::IsAllowedGeneralIo(int sysno) {
case __NR_pselect6:
case __NR_read:
case __NR_readv:
-#if defined(__arm__) || defined(__mips__)
+#if defined(__arm__) || defined(__mips32__)
case __NR_recv:
#endif
#if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
@@ -548,7 +552,7 @@ bool SyscallSets::IsAllowedGeneralIo(int sysno) {
#if defined(__i386__) || defined(__arm__) || defined(__mips__)
case __NR__newselect:
#endif
-#if defined(__arm__) || defined(__mips__)
+#if defined(__arm__) || defined(__mips32__)
case __NR_send:
#endif
#if defined(__x86_64__) || defined(__arm__) || defined(__mips__) || \
@@ -566,7 +570,7 @@ bool SyscallSets::IsAllowedGeneralIo(int sysno) {
case __NR_pwritev:
case __NR_recvmmsg: // Could specify source.
case __NR_sendfile:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_sendfile64:
#endif
case __NR_sendmmsg: // Could specify destination.
@@ -608,7 +612,7 @@ bool SyscallSets::IsAllowedBasicScheduler(int sysno) {
case __NR_nanosleep:
return true;
case __NR_getpriority:
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_nice:
#endif
case __NR_setpriority:
@@ -619,7 +623,7 @@ bool SyscallSets::IsAllowedBasicScheduler(int sysno) {
bool SyscallSets::IsAdminOperation(int sysno) {
switch (sysno) {
-#if defined(__i386__) || defined(__arm__) || defined(__mips__)
+#if defined(__i386__) || defined(__arm__) || defined(__mips32__)
case __NR_bdflush:
#endif
case __NR_kexec_load:
@@ -667,7 +671,7 @@ bool SyscallSets::IsFsControl(int sysno) {
case __NR_quotactl:
case __NR_swapoff:
case __NR_swapon:
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_umount:
#endif
case __NR_umount2:
@@ -718,7 +722,7 @@ bool SyscallSets::IsGlobalProcessEnvironment(int sysno) {
#if defined(__i386__) || defined(__arm__)
case __NR_ugetrlimit:
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_ulimit:
#endif
case __NR_getrusage:
@@ -799,10 +803,9 @@ bool SyscallSets::IsKeyManagement(int sysno) {
}
}
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
-bool SyscallSets::IsSystemVSemaphores(int sysno) {
- switch (sysno) {
- case __NR_semctl:
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
+ defined(__mips64__)
+bool SyscallSets::IsSystemVSemaphores(int sysno) { switch (sysno) { case __NR_semctl:
case __NR_semget:
case __NR_semop:
case __NR_semtimedop:
@@ -813,7 +816,8 @@ bool SyscallSets::IsSystemVSemaphores(int sysno) {
}
#endif
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
+ defined(__mips64__)
// These give a lot of ambient authority and bypass the setuid sandbox.
bool SyscallSets::IsSystemVSharedMemory(int sysno) {
switch (sysno) {
@@ -828,7 +832,8 @@ bool SyscallSets::IsSystemVSharedMemory(int sysno) {
}
#endif
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
+ defined(__mips64__)
bool SyscallSets::IsSystemVMessageQueue(int sysno) {
switch (sysno) {
case __NR_msgctl:
@@ -842,12 +847,14 @@ bool SyscallSets::IsSystemVMessageQueue(int sysno) {
}
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
// Big system V multiplexing system call.
bool SyscallSets::IsSystemVIpc(int sysno) {
switch (sysno) {
+#if !defined(__mips64__)
case __NR_ipc:
return true;
+#endif
default:
return false;
}
@@ -855,10 +862,11 @@ bool SyscallSets::IsSystemVIpc(int sysno) {
#endif
bool SyscallSets::IsAnySystemV(int sysno) {
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) \
+ || defined(__mips64__)
return IsSystemVMessageQueue(sysno) || IsSystemVSemaphores(sysno) ||
IsSystemVSharedMemory(sysno);
-#elif defined(__i386__) || defined(__mips__)
+#elif defined(__i386__) || defined(__mips32__)
return IsSystemVIpc(sysno);
#endif
}
@@ -973,13 +981,13 @@ bool SyscallSets::IsMisc(int sysno) {
#if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
case __NR_afs_syscall:
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_break:
#endif
#if defined(__i386__) || defined(__x86_64__) || defined(__mips__)
case __NR_getpmsg:
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_gtty:
case __NR_idle:
case __NR_lock:
@@ -993,7 +1001,7 @@ bool SyscallSets::IsMisc(int sysno) {
#if defined(__x86_64__)
case __NR_security:
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
case __NR_stty:
#endif
#if defined(__x86_64__)
@@ -1048,7 +1056,9 @@ bool SyscallSets::IsMipsPrivate(int sysno) {
bool SyscallSets::IsMipsMisc(int sysno) {
switch (sysno) {
case __NR_sysmips:
+#if !defined(__mips64__)
case __NR_unused150:
+#endif
return true;
default:
return false;
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.h b/sandbox/linux/seccomp-bpf-helpers/syscall_sets.h
index 5ba6335..c31d5e9 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_sets.h
+++ b/sandbox/linux/seccomp-bpf-helpers/syscall_sets.h
@@ -42,7 +42,7 @@ class SANDBOX_EXPORT SyscallSets {
static bool IsAllowedGetOrModifySocket(int sysno);
static bool IsDeniedGetOrModifySocket(int sysno);
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
// Big multiplexing system call for sockets.
static bool IsSocketCall(int sysno);
#endif
@@ -70,19 +70,22 @@ class SANDBOX_EXPORT SyscallSets {
// Asynchronous I/O API.
static bool IsAsyncIo(int sysno);
static bool IsKeyManagement(int sysno);
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
+ defined(__mips64__)
static bool IsSystemVSemaphores(int sysno);
#endif
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
+ defined(__mips64__)
// These give a lot of ambient authority and bypass the setuid sandbox.
static bool IsSystemVSharedMemory(int sysno);
#endif
-#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__) || \
+ defined(__mips64__)
static bool IsSystemVMessageQueue(int sysno);
#endif
-#if defined(__i386__) || defined(__mips__)
+#if defined(__i386__) || defined(__mips32__)
// Big system V multiplexing system call.
static bool IsSystemVIpc(int sysno);
#endif
diff --git a/sandbox/linux/seccomp-bpf/syscall.cc b/sandbox/linux/seccomp-bpf/syscall.cc
index 4d55936..d6db70f 100644
--- a/sandbox/linux/seccomp-bpf/syscall.cc
+++ b/sandbox/linux/seccomp-bpf/syscall.cc
@@ -188,7 +188,7 @@ asm(// We need to be able to tell the kernel exactly where we made a
".fnend\n"
#endif
"9:.size SyscallAsm, 9b-SyscallAsm\n"
-#elif defined(__mips__)
+#elif defined(__mips32__)
".text\n"
".option pic2\n"
".align 4\n"
@@ -240,6 +240,53 @@ asm(// We need to be able to tell the kernel exactly where we made a
".set pop\n"
".end SyscallAsm\n"
".size SyscallAsm,.-SyscallAsm\n"
+#elif defined(__mips64__)
+ ".text\n"
+ ".option pic2\n"
+ ".global SyscallAsm\n"
+ ".type SyscallAsm, @function\n"
+ "SyscallAsm:.ent SyscallAsm\n"
+ ".frame $sp, 16, $ra\n"
+ ".set push\n"
+ ".set noreorder\n"
+ "daddiu $sp, $sp, -16\n"
+ ".cpsetup $25, 0, SyscallAsm\n"
+ "sd $ra, 8($sp)\n"
+ // Check if "v0" is negative. If so, do not attempt to make a
+ // system call. Instead, compute the return address that is visible
+ // to the kernel after we execute "syscall". This address can be
+ // used as a marker that BPF code inspects.
+ "bgez $v0, 1f\n"
+ " nop\n"
+ // This is equivalent to "la $v0, 2f".
+ // LA macro has to be avoided since LLVM-AS has issue with LA in PIC mode
+ // https://llvm.org/bugs/show_bug.cgi?id=27644
+ "ld $v0, %got(2f)($gp)\n"
+ "daddiu $v0, $v0, %lo(2f)\n"
+ "b 2f\n"
+ " nop\n"
+ // On MIPS N64 all eight arguments go to registers a0 - a7
+ // We can go ahead and directly copy the entries from the arguments array
+ // into the appropriate CPU registers.
+ "1:ld $a7, 56($a0)\n"
+ "ld $a6, 48($a0)\n"
+ "ld $a5, 40($a0)\n"
+ "ld $a4, 32($a0)\n"
+ "ld $a3, 24($a0)\n"
+ "ld $a2, 16($a0)\n"
+ "ld $a1, 8($a0)\n"
+ "ld $a0, 0($a0)\n"
+ // Enter the kernel
+ "syscall\n"
+ // This is our "magic" return address that the BPF filter sees.
+ // Restore the return address from the stack.
+ "2:ld $ra, 8($sp)\n"
+ ".cpreturn\n"
+ "jr $ra\n"
+ "daddiu $sp, $sp, 16\n"
+ ".set pop\n"
+ ".end SyscallAsm\n"
+ ".size SyscallAsm,.-SyscallAsm\n"
#elif defined(__aarch64__)
".text\n"
".align 2\n"
@@ -358,7 +405,7 @@ intptr_t Syscall::Call(int nr,
ret = inout;
}
#elif defined(__mips__)
- int err_status;
+ intptr_t err_status;
intptr_t ret = Syscall::SandboxSyscallRaw(nr, args, &err_status);
if (err_status) {
diff --git a/sandbox/linux/system_headers/linux_seccomp.h b/sandbox/linux/system_headers/linux_seccomp.h
index 3deb3d2..a60fe2a 100644
--- a/sandbox/linux/system_headers/linux_seccomp.h
+++ b/sandbox/linux/system_headers/linux_seccomp.h
@@ -48,6 +48,9 @@
#ifndef AUDIT_ARCH_MIPSEL
#define AUDIT_ARCH_MIPSEL (EM_MIPS|__AUDIT_ARCH_LE)
#endif
+#ifndef AUDIT_ARCH_MIPSEL64
+#define AUDIT_ARCH_MIPSEL64 (EM_MIPS|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#endif
#ifndef AUDIT_ARCH_AARCH64
#define AUDIT_ARCH_AARCH64 (EM_AARCH64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#endif
diff --git a/sandbox/linux/system_headers/linux_signal.h b/sandbox/linux/system_headers/linux_signal.h
index fb9a47b..5ac4fdb 100644
--- a/sandbox/linux/system_headers/linux_signal.h
+++ b/sandbox/linux/system_headers/linux_signal.h
@@ -116,13 +116,20 @@ typedef siginfo_t LinuxSigInfo;
#endif // !defined(__native_client_nonsfi__)
// struct sigset_t is different size in PNaCl from the Linux's.
-#if defined(__mips__)
+#if defined(__mips32__)
#if !defined(_NSIG_WORDS)
#define _NSIG_WORDS 4
#endif
struct LinuxSigSet {
unsigned long sig[_NSIG_WORDS];
};
+#elif defined(__mips64__)
+#if !defined(_NSIG_WORDS)
+#define _NSIG_WORDS 2
+#endif
+struct LinuxSigSet {
+ unsigned long sig[_NSIG_WORDS];
+};
#else
typedef uint64_t LinuxSigSet;
#endif
diff --git a/sandbox/linux/system_headers/linux_syscalls.h b/sandbox/linux/system_headers/linux_syscalls.h
index 2b441e4..761c08a 100644
--- a/sandbox/linux/system_headers/linux_syscalls.h
+++ b/sandbox/linux/system_headers/linux_syscalls.h
@@ -21,11 +21,11 @@
#include "sandbox/linux/system_headers/arm_linux_syscalls.h"
#endif
-#if defined(__mips__) && (_MIPS_SIM == _ABIO32)
+#if defined(__mips32__)
#include "sandbox/linux/system_headers/mips_linux_syscalls.h"
#endif
-#if defined(__mips__) && (_MIPS_SIM == _ABI64)
+#if defined(__mips64__)
#include "sandbox/linux/system_headers/mips64_linux_syscalls.h"
#endif
diff --git a/sandbox/linux/system_headers/linux_ucontext.h b/sandbox/linux/system_headers/linux_ucontext.h
index ea4d8a6..e97d727 100644
--- a/sandbox/linux/system_headers/linux_ucontext.h
+++ b/sandbox/linux/system_headers/linux_ucontext.h
@@ -13,8 +13,10 @@
#include "sandbox/linux/system_headers/i386_linux_ucontext.h"
#elif defined(__x86_64__)
#include "sandbox/linux/system_headers/x86_64_linux_ucontext.h"
-#elif defined(__mips__)
+#elif defined(__mips32__)
#include "sandbox/linux/system_headers/mips_linux_ucontext.h"
+#elif defined(__mips64__)
+#include "sandbox/linux/system_headers/mips64_linux_ucontext.h"
#elif defined(__aarch64__)
#include "sandbox/linux/system_headers/arm64_linux_ucontext.h"
#else
diff --git a/sandbox/linux/system_headers/mips64_linux_syscalls.h b/sandbox/linux/system_headers/mips64_linux_syscalls.h
index 90f3d1be..ec75815 100644
--- a/sandbox/linux/system_headers/mips64_linux_syscalls.h
+++ b/sandbox/linux/system_headers/mips64_linux_syscalls.h
@@ -6,7 +6,7 @@
#ifndef SANDBOX_LINUX_SYSTEM_HEADERS_MIPS64_LINUX_SYSCALLS_H_
#define SANDBOX_LINUX_SYSTEM_HEADERS_MIPS64_LINUX_SYSCALLS_H_
-#if !defined(__mips__) || (_MIPS_SIM != _ABI64)
+#if !defined(__mips__)
#error "Including header on wrong architecture"
#endif
diff --git a/sandbox/linux/system_headers/mips64_linux_ucontext.h b/sandbox/linux/system_headers/mips64_linux_ucontext.h
new file mode 100644
index 0000000..3d10479
--- /dev/null
+++ b/sandbox/linux/system_headers/mips64_linux_ucontext.h
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SANDBOX_LINUX_SYSTEM_HEADERS_MIPS64_LINUX_UCONTEXT_H_
+#define SANDBOX_LINUX_SYSTEM_HEADERS_MIPS64_LINUX_UCONTEXT_H_
+
+#include <stdint.h>
+
+// This is mostly copied from breakpad (common/android/include/sys/ucontext.h),
+// except we do use sigset_t for uc_sigmask instead of a custom type.
+#if !defined(__BIONIC_HAVE_UCONTEXT_T)
+// Ensure that 'stack_t' is defined.
+#include <asm/signal.h>
+
+// We also need greg_t for the sandbox, include it in this header as well.
+typedef unsigned long greg_t;
+
+typedef struct {
+ uint64_t gregs[32];
+ uint64_t fpregs[32];
+ uint64_t mdhi;
+ uint64_t hi1;
+ uint64_t hi2;
+ uint64_t hi3;
+ uint64_t mdlo;
+ uint64_t lo1;
+ uint64_t lo2;
+ uint64_t lo3;
+ uint64_t pc;
+ uint32_t fpc_csr;
+ uint32_t used_math;
+ uint32_t dsp;
+ uint32_t reserved;
+} mcontext_t;
+
+typedef struct ucontext {
+ uint32_t uc_flags;
+ struct ucontext* uc_link;
+ stack_t uc_stack;
+ mcontext_t uc_mcontext;
+ sigset_t uc_sigmask;
+ // Other fields are not used by Google Breakpad. Don't define them.
+} ucontext_t;
+
+#else
+#include <sys/ucontext.h>
+#endif // __BIONIC_HAVE_UCONTEXT_T
+
+#endif // SANDBOX_LINUX_SYSTEM_HEADERS_MIPS64_LINUX_UCONTEXT_H_
diff --git a/sandbox/linux/system_headers/mips_linux_syscalls.h b/sandbox/linux/system_headers/mips_linux_syscalls.h
index 784d6b8..ddbf97f 100644
--- a/sandbox/linux/system_headers/mips_linux_syscalls.h
+++ b/sandbox/linux/system_headers/mips_linux_syscalls.h
@@ -6,7 +6,7 @@
#ifndef SANDBOX_LINUX_SYSTEM_HEADERS_MIPS_LINUX_SYSCALLS_H_
#define SANDBOX_LINUX_SYSTEM_HEADERS_MIPS_LINUX_SYSCALLS_H_
-#if !defined(__mips__) || (_MIPS_SIM != _ABIO32)
+#if !defined(__mips__)
#error "Including header on wrong architecture"
#endif
--
2.1.0

Просмотреть файл

@ -0,0 +1,57 @@
From 81bbd23ad0649bfd381eaeecbd58c2c43ba08122 Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Thu, 14 Sep 2017 20:51:10 +0800
Subject: [PATCH] Set kernal page size to 16K on loongson(MIPS) archtecture.
This patch is specail used for mips64.
---
base/allocator/partition_allocator/page_allocator.h | 7 +++++++
base/allocator/partition_allocator/partition_alloc.h | 5 +++++
2 files changed, 12 insertions(+)
diff --git a/base/allocator/partition_allocator/page_allocator.h b/base/allocator/partition_allocator/page_allocator.h
index f57beb7..0ef1705 100644
--- a/base/allocator/partition_allocator/page_allocator.h
+++ b/base/allocator/partition_allocator/page_allocator.h
@@ -17,6 +17,8 @@ namespace base {
#if defined(OS_WIN)
static const size_t kPageAllocationGranularityShift = 16; // 64KB
+#elif __mips__
+static const size_t kPageAllocationGranularityShift = 14; // 64KB
#else
static const size_t kPageAllocationGranularityShift = 12; // 4KB
#endif
@@ -29,7 +31,12 @@ static const size_t kPageAllocationGranularityBaseMask =
// All Blink-supported systems have 4096 sized system pages and can handle
// permissions and commit / decommit at this granularity.
+// But, on mips have 16384 sized system pages.
+#ifdef __mips__
+static const size_t kSystemPageSize = 16384;
+#else
static const size_t kSystemPageSize = 4096;
+#endif
static const size_t kSystemPageOffsetMask = kSystemPageSize - 1;
static const size_t kSystemPageBaseMask = ~kSystemPageOffsetMask;
diff --git a/base/allocator/partition_allocator/partition_alloc.h b/base/allocator/partition_allocator/partition_alloc.h
index c720a50..67c3598 100644
--- a/base/allocator/partition_allocator/partition_alloc.h
+++ b/base/allocator/partition_allocator/partition_alloc.h
@@ -94,7 +94,12 @@ static const size_t kBucketShift = (kAllocationGranularity == 8) ? 3 : 2;
// system page of the span. For our current max slot span size of 64k and other
// constant values, we pack _all_ PartitionAllocGeneric() sizes perfectly up
// against the end of a system page.
+// On mips have 16KB pagesize, So kPartitionPageSize is 64KB.
+#ifdef __mips__
+static const size_t kPartitionPageShift = 16; // 64KB
+#else
static const size_t kPartitionPageShift = 14; // 16KB
+#endif
static const size_t kPartitionPageSize = 1 << kPartitionPageShift;
static const size_t kPartitionPageOffsetMask = kPartitionPageSize - 1;
static const size_t kPartitionPageBaseMask = ~kPartitionPageOffsetMask;
--
2.1.0

Просмотреть файл

@ -0,0 +1,35 @@
From c225042994cebe5717013bde26bbad757fefaa17 Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Thu, 28 Sep 2017 14:24:17 +0800
Subject: [PATCH] Add mips64el-redhat-linux- to gcc_toolchain for mips64el
cross compile on x64.
---
build/toolchain/linux/BUILD.gn | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/build/toolchain/linux/BUILD.gn b/build/toolchain/linux/BUILD.gn
index bd37707..2fbc4d6e 100644
--- a/build/toolchain/linux/BUILD.gn
+++ b/build/toolchain/linux/BUILD.gn
@@ -172,12 +172,12 @@ gcc_toolchain("mipsel") {
}
gcc_toolchain("mips64el") {
- cc = "gcc"
- cxx = "g++"
- ar = "ar"
+ cc = "mips64el-redhat-linux-gcc"
+ cxx = "mips64el-redhat-linux-g++"
+ ar = "mips64el-redhat-linux-ar"
ld = cxx
- readelf = "readelf"
- nm = "nm"
+ readelf = "mips64el-redhat-linux-readelf"
+ nm = "mips64el-redhat-linux-nm"
toolchain_args = {
cc_wrapper = ""
--
2.1.0

Просмотреть файл

@ -0,0 +1,25 @@
From a5d62b0f77143912453e1b60b5e3414570fb739f Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Sat, 30 Sep 2017 09:38:26 +0800
Subject: [PATCH] Add mips64 support for sysroot.
---
build/config/sysroot.gni | 2 ++
1 file changed, 2 insertions(+)
diff --git a/build/config/sysroot.gni b/build/config/sysroot.gni
index aa43c2c..b7ac48c 100644
--- a/build/config/sysroot.gni
+++ b/build/config/sysroot.gni
@@ -47,6 +47,8 @@ if (current_os == target_os && current_cpu == target_cpu &&
sysroot = "$target_sysroot_dir/debian_jessie_i386-sysroot"
} else if (current_cpu == "mipsel") {
sysroot = "$target_sysroot_dir/debian_jessie_mips-sysroot"
+ } else if (current_cpu == "mips64el") {
+ sysroot = "$target_sysroot_dir/debian_jessie_mips64-sysroot"
} else if (current_cpu == "arm") {
sysroot = "$target_sysroot_dir/debian_jessie_arm-sysroot"
} else if (current_cpu == "arm64") {
--
2.7.4

Просмотреть файл

@ -0,0 +1,30 @@
From 317dff3f396f5e0fc7010a76d7ccbcb708e515a3 Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Sat, 30 Sep 2017 09:30:05 +0800
Subject: [PATCH] Fix mips cross-toolchain build src/crypto/ec/p256-64.c with
-O2.
---
third_party/boringssl/BUILD.gn | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/third_party/boringssl/BUILD.gn b/third_party/boringssl/BUILD.gn
index abe39b2..a7bd880 100644
--- a/third_party/boringssl/BUILD.gn
+++ b/third_party/boringssl/BUILD.gn
@@ -32,6 +32,12 @@ config("internal_config") {
]
if (is_posix) {
cflags_c = [ "-std=c99" ]
+ # TODO(wangqing): Fix mips cross-toolchain build src/crypto/ec/p256-64.c
+ # with -O2.
+ if (current_cpu == "mips64el" && current_cpu != host_cpu) {
+ cflags_c += [ "-O1" ]
+ }
+
defines += [ "_XOPEN_SOURCE=700" ]
}
}
--
2.7.4

Просмотреть файл

@ -0,0 +1,46 @@
From 0c64df90e4ca25644ac5aa3f35ab4884f697165e Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Mon, 9 Oct 2017 16:53:22 +0800
Subject: [PATCH] Fix error about "relocation truncated to fit: R_MIPS_CALL16"
when cross-compiling shared_library with is_debug on x64.
---
content/common/BUILD.gn | 5 +++++
ppapi/proxy/BUILD.gn | 5 +++++
2 files changed, 10 insertions(+)
diff --git a/content/common/BUILD.gn b/content/common/BUILD.gn
index fd5c0dc..e91e8348 100644
--- a/content/common/BUILD.gn
+++ b/content/common/BUILD.gn
@@ -15,6 +15,11 @@ if (is_mac) {
import("//build/config/mac/mac_sdk.gni")
}
+if (is_debug && current_cpu == "mips64el") {
+ cflags_cc = [ "-mxgot" ]
+ cflags_cc += [ "-mlong-calls" ]
+}
+
# For feature flags internal to content. See content/public/common:features
# for feature flags that clients of contents need to know about.
buildflag_header("features") {
diff --git a/ppapi/proxy/BUILD.gn b/ppapi/proxy/BUILD.gn
index b572778..a2630f20 100644
--- a/ppapi/proxy/BUILD.gn
+++ b/ppapi/proxy/BUILD.gn
@@ -8,6 +8,11 @@ config("proxy_implementation") {
defines = [ "PPAPI_PROXY_IMPLEMENTATION" ]
}
+if (is_debug && current_cpu == "mips64el") {
+ cflags_cc = [ "-mxgot" ]
+ cflags_cc += [ "-mlong-calls" ]
+}
+
component("proxy") {
output_name = "ppapi_proxy"
--
2.7.4

Просмотреть файл

@ -0,0 +1,60 @@
From 933a965b62273f4eafa73e958e922042cbc8d5bb Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Wed, 27 Sep 2017 10:31:08 +0800
Subject: [PATCH] Fix build_ffmpeg.py with mips64 support.
This patch is merged into third_party/ffmpeg:
https://chromium.googlesource.com/chromium/third_party/ffmpeg/+/76ea8a21dfb145468466b355a296c8d7a5a83ef2
---
chromium/scripts/build_ffmpeg.py | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/chromium/scripts/build_ffmpeg.py b/chromium/scripts/build_ffmpeg.py
index a052e27..0dbd9eb 100755
--- a/chromium/scripts/build_ffmpeg.py
+++ b/chromium/scripts/build_ffmpeg.py
@@ -109,6 +109,8 @@ def DetermineHostOsAndArch():
host_arch = 'x64'
elif platform.machine() == 'aarch64':
host_arch = 'arm64'
+ elif platform.machine() == 'mips64':
+ host_arch = 'mips64el'
elif platform.machine().startswith('arm'):
host_arch = 'arm'
else:
@@ -498,7 +500,21 @@ def main(argv):
])
elif target_arch == 'mips64el':
if target_os != "android":
- configure_flags['Common'].extend([
+ if target_arch == host_arch:
+ configure_flags['Common'].extend([
+ '--target-os=linux',
+ '--arch=mips',
+ '--extra-cflags=-mips64r2',
+ '--extra-cflags=-EL',
+ '--extra-ldflags=-mips64r2',
+ '--extra-ldflags=-EL',
+ '--disable-mipsfpu',
+ '--disable-mipsdsp',
+ '--disable-mipsdspr2',
+ '--disable-mips32r2',
+ ])
+ else:
+ configure_flags['Common'].extend([
'--enable-cross-compile',
'--cross-prefix=mips64el-linux-gnuabi64-',
'--target-os=linux',
@@ -511,7 +527,7 @@ def main(argv):
'--disable-mipsdsp',
'--disable-mipsdspr2',
'--disable-mips32r2',
- ])
+ ])
else:
configure_flags['Common'].extend([
'--arch=mips',
--
2.1.0

Просмотреть файл

@ -0,0 +1,25 @@
From dcd2071f20aa79f2eb1959cd5f040a0e4a0c058b Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Sat, 30 Sep 2017 10:21:25 +0800
Subject: [PATCH] Fix build_ffmpeg with cross-prefix mips64el-redhat-linux-.
---
chromium/scripts/build_ffmpeg.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/chromium/scripts/build_ffmpeg.py b/chromium/scripts/build_ffmpeg.py
index 0dbd9eb..79b5af2 100755
--- a/chromium/scripts/build_ffmpeg.py
+++ b/chromium/scripts/build_ffmpeg.py
@@ -516,7 +516,7 @@ def main(argv):
else:
configure_flags['Common'].extend([
'--enable-cross-compile',
- '--cross-prefix=mips64el-linux-gnuabi64-',
+ '--cross-prefix=mips64el-redhat-linux-',
'--target-os=linux',
'--arch=mips',
'--extra-cflags=-mips64r2',
--
2.7.4

Просмотреть файл

@ -0,0 +1,68 @@
From 69d1323ffac9b541c80d24d7d8fec6088ca6b2ce Mon Sep 17 00:00:00 2001
From: Wang Qing <wangqing-hf@loongson.cn>
Date: Fri, 15 Sep 2017 11:02:59 +0800
Subject: [PATCH] Fix v8 sunspider-1.0.2 some cases test failed with use madd
instruction.
This patch is similar to V8 master patch:
https://chromium.googlesource.com/v8/v8/+/99459edf5fee3681da24356612e48b8afa14656f
When update chromium and has this patch:
https://chromium.googlesource.com/v8/v8/+/99459edf5fee3681da24356612e48b8afa14656f
Then this patch is not needed.
---
BUILD.gn | 3 +++
src/mips64/macro-assembler-mips64.cc | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/BUILD.gn b/BUILD.gn
index e13162a..78762c6 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -369,6 +369,9 @@ config("toolchain") {
defines += [ "_MIPS_ARCH_MIPS64R6" ]
} else if (mips_arch_variant == "r2") {
defines += [ "_MIPS_ARCH_MIPS64R2" ]
+ } else if (mips_arch_variant == "loongson3") {
+ defines += [ "_MIPS_ARCH_LOONGSON" ]
+ defines += [ "FPU_MODE_FP64" ]
}
}
if (v8_current_cpu == "s390" || v8_current_cpu == "s390x") {
diff --git a/src/mips64/macro-assembler-mips64.cc b/src/mips64/macro-assembler-mips64.cc
index 84a55d4..c5088c5 100644
--- a/src/mips64/macro-assembler-mips64.cc
+++ b/src/mips64/macro-assembler-mips64.cc
@@ -2383,7 +2383,14 @@ void MacroAssembler::Trunc_ul_s(FPURegister fd, Register rs,
void MacroAssembler::Madd_s(FPURegister fd, FPURegister fr, FPURegister fs,
FPURegister ft, FPURegister scratch) {
if (kArchVariant == kMips64r2) {
+// MADD not used on loongson mips64r2.
+#ifdef _MIPS_ARCH_LOONGSON
+ DCHECK(!fr.is(scratch) && !fs.is(scratch) && !ft.is(scratch));
+ mul_s(scratch, fs, ft);
+ add_s(fd, fr, scratch);
+#else
madd_s(fd, fr, fs, ft);
+#endif
} else {
DCHECK(!fr.is(scratch) && !fs.is(scratch) && !ft.is(scratch));
mul_s(scratch, fs, ft);
@@ -2394,7 +2401,14 @@ void MacroAssembler::Madd_s(FPURegister fd, FPURegister fr, FPURegister fs,
void MacroAssembler::Madd_d(FPURegister fd, FPURegister fr, FPURegister fs,
FPURegister ft, FPURegister scratch) {
if (kArchVariant == kMips64r2) {
+// MADD not used on loongson mips64r2.
+#ifdef _MIPS_ARCH_LOONGSON
+ DCHECK(!fr.is(scratch) && !fs.is(scratch) && !ft.is(scratch));
+ mul_d(scratch, fs, ft);
+ add_d(fd, fr, scratch);
+#else
madd_d(fd, fr, fs, ft);
+#endif
} else {
DCHECK(!fr.is(scratch) && !fs.is(scratch) && !ft.is(scratch));
mul_d(scratch, fs, ft);
--
2.1.0

Просмотреть файл

@ -10,6 +10,7 @@ from patch import apply_patches_from_directory
SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
PATCHES_DIR = os.path.join(SOURCE_ROOT, 'patches')
PATCHES_MAS_DIR = os.path.join(SOURCE_ROOT, 'patches-mas')
PATCHES_MIPS64EL_DIR = os.path.join(SOURCE_ROOT, 'patches-mips64el')
SRC = 'src'
SRC_DIR = os.path.join(SOURCE_ROOT, SRC)
@ -19,6 +20,8 @@ def main():
if not error:
if os.environ.has_key('MAS_BUILD'):
error = apply_patches_for_dir(PATCHES_MAS_DIR)
elif sys.argv[1] == 'mips64el':
error = apply_patches_for_dir(PATCHES_MIPS64EL_DIR)
if not error:
return

Просмотреть файл

@ -4,6 +4,7 @@ import argparse
import os
import subprocess
import sys
import platform
from lib.config import get_output_dir
@ -13,9 +14,15 @@ VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor')
TARGETS = ['chromiumcontent_all']
COMPONENTS = ['static_library', 'shared_library', 'ffmpeg']
MIPS64EL_GCC = 'gcc-4.8.3-d197-n64-loongson'
# Whether the host system is a mips64el machine.
IS_MIPS64EL_HOST = platform.uname()[5] == 'mips64'
NINJA = os.path.join(VENDOR_DIR, 'depot_tools', 'ninja')
if sys.platform == 'win32':
NINJA = '{0}.exe'.format(NINJA)
elif IS_MIPS64EL_HOST:
NINJA = os.path.join(VENDOR_DIR, 'depot_tools', 'ninja-build')
def main():
@ -27,10 +34,21 @@ def main():
env['PATH']])
if sys.platform in ['win32', 'cygwin']:
env['DEPOT_TOOLS_WIN_TOOLCHAIN'] = '0'
if target_arch == 'arm64':
elif target_arch == 'arm64':
binutils_dir = os.path.join(VENDOR_DIR, 'binutils-aarch64')
env['LD_LIBRARY_PATH'] = binutils_dir + '/usr/x86_64-linux-gnu/aarch64-linux-gnu/lib'
env['PATH'] = os.pathsep.join([binutils_dir + '/usr/bin', env['PATH']])
elif target_arch == 'mips64el' and not IS_MIPS64EL_HOST:
gcc_dir = os.path.join(VENDOR_DIR, MIPS64EL_GCC)
ldlib_dirs = [
gcc_dir + '/usr/x86_64-unknown-linux-gnu/mips64el-redhat-linux/lib',
gcc_dir + '/usr/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/sysroot/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/sysroot/usr/lib64',
]
env['LD_LIBRARY_PATH'] = os.pathsep.join(ldlib_dirs)
env['PATH'] = os.pathsep.join([gcc_dir + '/usr/bin', env['PATH']])
os.chdir(SOURCE_ROOT)

Просмотреть файл

@ -0,0 +1,5 @@
#!/usr/bin/env bash
export TARGET_ARCH=mips64el
script/cibuild-libchromiumcontent-linux

Просмотреть файл

@ -11,6 +11,7 @@ import shutil
import subprocess
import sys
import zipfile
import platform
from lib.config import get_output_dir
@ -29,9 +30,15 @@ import ninja_syntax
MAIN_DIR = os.path.join(DIST_DIR, 'main')
DIST_SRC_DIR = os.path.join(MAIN_DIR, 'src')
MIPS64EL_GCC = 'gcc-4.8.3-d197-n64-loongson'
# Whether the host system is a mips64el machine.
IS_MIPS64EL_HOST = platform.uname()[5] == 'mips64'
NINJA = os.path.join(VENDOR_DIR, 'depot_tools', 'ninja')
if sys.platform == 'win32':
NINJA = '{0}.exe'.format(NINJA)
elif IS_MIPS64EL_HOST:
NINJA = os.path.join(VENDOR_DIR, 'depot_tools', 'ninja-build')
COPY_PY = os.path.join(TOOLS_DIR, 'copy.py')
LICENSES_PY = os.path.join(TOOLS_DIR, 'licenses.py')
@ -209,6 +216,8 @@ ARCH_BLACKLIST = {
],
'ia32': [
],
'mips64el': [
],
}
SYMBOLS = {
@ -345,13 +354,14 @@ class Ninja(ninja_syntax.Writer):
def main():
args = parse_args()
target_arch = args.target_arch
if args.create_debug_archive:
check_create_debug_archive(args.target_arch)
rm_rf(DIST_DIR)
os.makedirs(MAIN_DIR)
with Ninja(open(os.path.join(MAIN_DIR, 'build.ninja'), 'wb')) as ninja:
generate_ninja(args, ninja)
@ -500,6 +510,11 @@ def copy_binaries(target_arch, component, create_debug_archive,
binaries = [ 'chromedriver', 'clang_x86_v8_arm/mksnapshot' ]
elif target_arch == 'arm64':
binaries = [ 'chromedriver', 'clang_x64_v8_arm64/mksnapshot' ]
elif target_arch == 'mips64el':
if IS_MIPS64EL_HOST:
binaries = [ 'chromedriver', 'mksnapshot' ]
else:
binaries = [ 'chromedriver', 'clang_x64_v8_mips64el/mksnapshot' ]
else:
binaries = [ 'chromedriver', 'mksnapshot' ]
@ -638,6 +653,17 @@ def run_strip(target_arch, filename, create_debug_archive):
binutils_dir = os.path.join(VENDOR_DIR, 'binutils-aarch64')
env['LD_LIBRARY_PATH'] = binutils_dir + '/usr/x86_64-linux-gnu/aarch64-linux-gnu/lib'
env['PATH'] = os.pathsep.join([binutils_dir + '/usr/bin', env['PATH']])
elif target_arch == 'mips64el' and not IS_MIPS64EL_HOST:
gcc_dir = os.path.join(VENDOR_DIR, MIPS64EL_GCC)
ldlib_dirs = [
gcc_dir + '/usr/x86_64-unknown-linux-gnu/mips64el-redhat-linux/lib',
gcc_dir + '/usr/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/sysroot/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/sysroot/usr/lib64',
]
env['LD_LIBRARY_PATH'] = os.pathsep.join(ldlib_dirs)
env['PATH'] = os.pathsep.join([gcc_dir + '/usr/bin', env['PATH']])
if target_arch == 'arm' and filename.endswith(('.so', 'chromedriver')):
strip = 'arm-linux-gnueabihf-strip'
@ -647,6 +673,10 @@ def run_strip(target_arch, filename, create_debug_archive):
strip = 'aarch64-linux-gnu-strip'
objcopy = 'aarch64-linux-gnu--objcopy'
gdb = 'aarch64-linux-gnu-gdb'
elif target_arch == 'mips64el' and filename.endswith(('.so', 'chromedriver')):
strip = 'mips64el-redhat-linux-strip'
objcopy = 'mips64el-redhat-linux--objcopy'
gdb = 'mips64el-redhat-linux-gdb'
else:
strip = 'strip'
objcopy = 'objcopy'

Просмотреть файл

@ -0,0 +1,9 @@
#! /bin/sh
# ninja in depot_tools not support mips64el, So make
# a soft connection to system ninja-build on loongson platform.
cd vendor/depot_tools
if [ ! -f "ninja-build" ]; then
ln -sv /usr/bin/ninja-build .
fi
cd -

Просмотреть файл

@ -0,0 +1,50 @@
#! /bin/sh
# runhooks-mips64el script is doing the operation that "gclient sync --runhooks".
# Since many files do not support mips, for example node.
# get 'src/third_party/node/linux/node-linux-x64.tar.gz.sha1' from "gclient sync --runhooks",
# but is x86, not support mips.
# So Add --nohooks to "gclient sync" on mips, and write the script to get the file
# needed for build chromiumcontent instead of "gclient sync --runhooks".
# Author: Wang Qing
# Email: wangqing-hf@loongson.cn
# setup LASTCHANGE
cd src/build/util
./lastchange.py > LASTCHANGE
./lastchange.py > LASTCHANGE.blink
cd -
# Add node from system
if [ ! -f "src/third_party/node/linux/node-linux-x64/bin/node" ]; then
mkdir -p src/third_party/node/linux/node-linux-x64/bin
ln -s /usr/bin/node src/third_party/node/linux/node-linux-x64/bin/node
fi
# Use npm install the necessary node modules
cd src/third_party/node
if test `uname -m` = "mips64"; then
if [ -f "package.json" ]; then
rm -v package.json
fi
fi
if [ ! -d "node_modules/vulcanize" ]; then
npm install vulcanize
fi
if [ ! -d "node_modules/crisper" ]; then
npm install crisper
fi
if [ ! -d "node_modules/uglify-es" ]; then
npm install uglify-es
ln -s node_modules/uglify-es node_modules/uglifyjs
fi
if [ ! -d "node_modules/polymer-css-build" ]; then
npm install polymer-css-build
fi
cd -
# Get skia/ext/skia_commit_hash.h
python src/build/util/lastchange.py -m SKIA_COMMIT_HASH -s src/third_party/skia --header src/skia/ext/skia_commit_hash.h

Просмотреть файл

@ -8,6 +8,7 @@ import shutil
import subprocess
import sys
import urllib2
import platform
from lib.config import get_output_dir
@ -24,6 +25,14 @@ NINJA = os.path.join(DEPOT_TOOLS, 'ninja')
if sys.platform == 'win32':
NINJA = '{0}.exe'.format(NINJA)
# URL to the mips64el sysroot image.
MIPS64EL_SYSROOT = 'https://github.com/electron/debian-sysroot-image-creator/releases/download/v0.5.0/debian_jessie_mips64-sysroot.tar.bz2'
# URL to the mips64el toolchain.
MIPS64EL_GCC = 'gcc-4.8.3-d197-n64-loongson'
MIPS64EL_GCC_URL = 'http://ftp.loongnix.org/toolchain/gcc/release/' + MIPS64EL_GCC + '.tar.gz'
# Whether the host system is a mips64el machine.
IS_MIPS64EL_HOST = platform.uname()[5] == 'mips64'
DEBIAN_MIRROR = 'http://ftp.jp.debian.org/debian/pool/main/'
BINTOOLS_NAME = 'c/cross-binutils/binutils-aarch64-linux-gnu_2.25-5_amd64.deb'
GCLIENT_CONFIG_PATH = os.path.join(SOURCE_ROOT, '.gclient')
@ -56,24 +65,29 @@ def main():
# to 0.
# More information: https://stackoverflow.com/a/9935126
git_cache = args.git_cache or os.getenv('LIBCHROMIUMCONTENT_GIT_CACHE', '')
target_arch = args.target_arch
nohooks = target_arch == 'mips64el' and IS_MIPS64EL_HOST
if not args.skip_gclient:
if (args.source_only):
return gclient_sync(chromium_version(), args.clean, git_cache)
return gclient_sync(chromium_version(), args.clean, git_cache, nohooks)
else:
gclient_sync(chromium_version(), args.clean, git_cache)
gclient_sync(chromium_version(), args.clean, git_cache, nohooks)
if target_arch == 'mips64el' and IS_MIPS64EL_HOST:
os.system('sh script/mips64el/runhooks-mips64el')
if sys.platform == 'linux2':
install_sysroot()
install_sysroot(target_arch)
elif sys.platform in ['win32', 'cygwin']:
update_toolchain_json()
target_arch = args.target_arch
if target_arch == 'arm64':
install_aarch64_bintools()
return (apply_patches(args.skip_patches) or
return (apply_patches(args.skip_patches, target_arch) or
copy_chromiumcontent_files() or
update_clang() or
setup_mips64el_toolchain(target_arch) or
run_gn(target_arch, args.defines))
@ -102,27 +116,39 @@ def chromium_version():
return f.readline().strip()
def install_sysroot():
def install_sysroot(target_arch):
if target_arch == 'ia32':
target_cpu = 'i386'
elif target_arch == 'x64':
target_cpu = 'amd64'
else:
target_cpu = target_arch
for arch in ('arm', 'arm64', 'amd64', 'i386'):
# Download from chromium's sysroot storage.
install = os.path.join(SRC_DIR, 'build', 'linux', 'sysroot_scripts',
'install-sysroot.py')
subprocess.check_call([sys.executable, install, '--arch', arch])
if target_cpu == 'mips64el':
# Download from our own sysroot storage.
destination = os.path.join(SRC_DIR, 'build', 'linux')
if os.path.exists(os.path.join(destination, 'debian_jessie_mips64-sysroot')):
return
tar_name = 'debian_jessie_mips64-sysroot.tar.bz2'
download(MIPS64EL_SYSROOT, tar_name)
subprocess.call(['tar', '-jxf', tar_name, '-C', destination])
rm_f(tar_name)
def install_aarch64_bintools():
destination = os.path.join(VENDOR_DIR, 'binutils-aarch64')
if os.path.exists(destination):
return
url = DEBIAN_MIRROR + BINTOOLS_NAME
deb_name = 'binutils-aarch64.deb'
with open(deb_name, 'wb+') as f:
with contextlib.closing(urllib2.urlopen(url)) as u:
while True:
chunk = u.read(1024*1024)
if not len(chunk):
break
f.write(chunk)
download(DEBIAN_MIRROR + BINTOOLS_NAME, deb_name)
env = os.environ.copy()
env['DEPOT_TOOLS_WIN_TOOLCHAIN'] = '0'
@ -180,7 +206,7 @@ def ensure_gclient_config(git_cache):
))
def gclient_sync(version, force, git_cache):
def gclient_sync(version, force, git_cache, nohooks):
# Remove untracked files in src.
if os.path.exists(os.path.join(SRC_DIR, '.git')):
with scoped_cwd(SRC_DIR):
@ -200,14 +226,16 @@ def gclient_sync(version, force, git_cache):
args += ['--lock_timeout=15']
if force:
args += ['--force']
if nohooks:
args += ['--nohooks']
subprocess.check_call(args, env=env)
def apply_patches(skip_patches):
return (subprocess.call([sys.executable,
os.path.join(SOURCE_ROOT, 'script', 'apply-patches')])
if not skip_patches
else True)
def apply_patches(skip_patches, target_arch):
ap = os.path.join(SOURCE_ROOT, 'script', 'apply-patches')
return (subprocess.call([sys.executable, ap, target_arch])
if not skip_patches
else True)
def update_clang():
@ -219,6 +247,48 @@ def update_clang():
return subprocess.call([sys.executable, update, '--if-needed'], env=env)
def setup_mips64el_toolchain(target_arch):
if target_arch != 'mips64el':
return
if IS_MIPS64EL_HOST:
# A hack to use the mips64el version of ninja.
subprocess.call(['script/mips64el/ninja-mips64el'])
else:
# Download mips64el toolchains.
if not os.path.exists(os.path.join(VENDOR_DIR, MIPS64EL_GCC)):
tar_name = MIPS64EL_GCC + '.tar.gz'
download(MIPS64EL_GCC_URL, tar_name)
subprocess.check_call(['tar', '-xf', tar_name, '-C', VENDOR_DIR])
rm_f(tar_name)
# Gernerate ffmpeg build config files for mips64el.
env = os.environ.copy()
if not IS_MIPS64EL_HOST:
gcc_dir = os.path.join(VENDOR_DIR, MIPS64EL_GCC)
ldlib_dirs = [
gcc_dir + '/usr/x86_64-unknown-linux-gnu/mips64el-redhat-linux/lib',
gcc_dir + '/usr/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/sysroot/lib64',
gcc_dir + '/usr/mips64el-redhat-linux/sysroot/usr/lib64',
]
env['LD_LIBRARY_PATH'] = os.pathsep.join(ldlib_dirs)
env['PATH'] = os.pathsep.join([gcc_dir + '/usr/bin', env['PATH']])
ffmpeg_dir = os.path.join(SRC_DIR, 'third_party', 'ffmpeg')
subprocess.check_call(['chromium/scripts/build_ffmpeg.py', 'linux', 'mips64el'], cwd=ffmpeg_dir, env=env)
subprocess.check_call(['chromium/scripts/copy_config.sh'], cwd=ffmpeg_dir)
subprocess.check_call(['chromium/scripts/generate_gn.py'], cwd=ffmpeg_dir)
# Build gn with the patch to support mips64el.
gn = os.path.join(SRC_DIR, 'out', 'Release', 'gn')
if not os.path.exists(gn):
env['PATH'] = os.pathsep.join([os.path.join(VENDOR_DIR, 'depot_tools'),
env['PATH']])
bootstrap = os.path.join(SRC_DIR, 'tools', 'gn', 'bootstrap', 'bootstrap.py')
subprocess.check_call([bootstrap, '-s'], cwd=SRC_DIR, env=env)
def run_gn(target_arch, defines):
if sys.platform in ['win32', 'cygwin']:
gn = os.path.join(SRC_DIR, 'buildtools', 'win', 'gn.exe')
@ -242,6 +312,27 @@ def run_gn(target_arch, defines):
args += ' use_experimental_allocator_shim=false'
if sys.platform == 'linux2':
args += ' use_gtk3=false'
if target_arch == 'mips64el':
args += ' clang_use_chrome_plugins=false'
args += ' enable_hangout_services_extension=true'
args += ' enable_nacl_nonsfi=false'
args += ' fatal_linker_warnings=false'
args += ' fieldtrial_testing_like_official_build=true'
args += ' is_clang=false'
args += ' link_pulseaudio=true'
args += ' linux_use_bundled_binutils=false'
args += ' remove_webcore_debug_symbols=true'
args += ' treat_warnings_as_errors=false'
args += ' use_allocator="none"'
args += ' use_cups=true'
args += ' use_gconf=false'
args += ' use_gnome_keyring=false'
args += ' use_gold=false'
args += ' use_kerberos=true'
args += ' use_pulseaudio=true'
if IS_MIPS64EL_HOST:
args += ' use_sysroot=false'
output_dir = get_output_dir(SOURCE_ROOT, target_arch, component)
subprocess.call([gn, 'gen', os.path.relpath(output_dir, SRC_DIR), '--args=' + args],
cwd=SRC_DIR, env=env)
@ -293,6 +384,15 @@ def scoped_cwd(path):
os.chdir(cwd)
def download(url, filename):
with open(filename, 'wb+') as f:
with contextlib.closing(urllib2.urlopen(url)) as u:
while True:
chunk = u.read(1024*1024)
if not len(chunk):
break
f.write(chunk)
if __name__ == '__main__':
import sys
sys.exit(main())