summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDale Curtis <dalecurtis@chromium.org>2018-10-31 14:25:55 -0700
committerDale Curtis <dalecurtis@chromium.org>2018-10-31 14:25:55 -0700
commit9596cc0f7bf15a421347556407f9b7a5197e911f (patch)
treeb3f596bddac1828e24b3661347d5fa79b834575f
parent5f133c41699007ba0794608ed630a54fe763dda2 (diff)
downloadnasm-9596cc0f7bf15a421347556407f9b7a5197e911f.tar.gz
Add all the chromium stuff necessary to build nasm.
This adds the BUILD file and configuration davidben at chromium.org wrote originally on https://chromium-review.googlesource.com/c/chromium/src/+/1119211 This is the last CL enabling nasm usage in Chromium (fingers crossed), but may need some tweaks to build on Windows mac. A subsequent Chromium CL adding the DEP will test this theory. BUG=766721 Change-Id: I481fc8d7f1747dad74cd0a02a251a65cfd78a134
-rw-r--r--BUILD.gn80
-rw-r--r--OWNERS2
-rw-r--r--README.chromium29
-rwxr-xr-xgenerate_nasm_sources.py69
-rw-r--r--nasm_assemble.gni168
-rw-r--r--nasm_sources.gni89
6 files changed, 437 insertions, 0 deletions
diff --git a/BUILD.gn b/BUILD.gn
new file mode 100644
index 00000000..7ad21b7a
--- /dev/null
+++ b/BUILD.gn
@@ -0,0 +1,80 @@
+# Copyright 2018 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.
+
+import("//build/config/compiler/compiler.gni")
+import("nasm_sources.gni")
+
+configs_to_delete = [
+ # Don't enable sanitizers for build tools. They slow down the overall build.
+ "//build/config/sanitizers:default_sanitizer_flags",
+]
+
+configs_to_add = []
+if (is_debug) {
+ configs_to_delete += [
+ # Build with full optimizations even on debug configurations, because some
+ # yasm build steps (highbd_sad4d_sse2.asm) can take ~33 seconds or more in
+ # debug component builds on Windows. Enabling compiler optimizations saves
+ # ~5 seconds.
+ "//build/config/compiler:default_optimization",
+
+ # Don't define _DEBUG. Modest savings, but good for consistency.
+ "//build/config:debug",
+ ]
+
+ configs_to_add += [
+ "//build/config:release",
+ "//build/config/compiler:optimize_max",
+ ]
+ if (is_win) {
+ # This switches to using the release CRT. For yasm debug component builds
+ # of highbd_sad4d_sse2.asm on Windows this saved about 15 s.
+ configs_to_delete += [ "//build/config/win:default_crt" ]
+ configs_to_add += [ "//build/config/win:release_crt" ]
+ }
+}
+
+config("nasm_config") {
+ include_dirs = [
+ ".",
+ "asm",
+ "config",
+ "disasm",
+ "include",
+ "output",
+ "x86",
+ ]
+
+ # TODO(dalecurtis): Try using a common config.h for now, but Mac may need its
+ # own and Windows may need to use the pregenerated msvc.h one.
+ defines = [ "HAVE_CONFIG_H" ]
+
+ if (is_clang) {
+ cflags = [
+ # The inline functions in NASM's headers flag this.
+ "-Wno-unused-function",
+
+ # NASM writes nasm_assert(!"some string literal").
+ "-Wno-string-conversion",
+
+ # NASM sometimes redefines macros from its config.h.
+ "-Wno-macro-redefined",
+ ]
+ }
+}
+
+if (current_toolchain == host_toolchain) {
+ executable("nasm") {
+ sources = nasmlib_sources + nasm_sources
+
+ configs -= configs_to_delete
+ configs += configs_to_add
+ configs += [ ":nasm_config" ]
+
+ deps = [
+ # Default manifest on Windows (a no-op elsewhere).
+ "//build/win:default_exe_manifest",
+ ]
+ }
+}
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 00000000..b7260f5e
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,2 @@
+dalecurtis@chromium.org
+davidben@chromium.org
diff --git a/README.chromium b/README.chromium
new file mode 100644
index 00000000..cedfdc54
--- /dev/null
+++ b/README.chromium
@@ -0,0 +1,29 @@
+Name: Netwide Assembler
+Short Name: nasm
+URL: https://www.nasm.us/
+Version: bfa1ed0ae9cb15b54b008431d122db3c22cd45eb
+License: 2-Clause BSD
+License File: src/LICENSE
+Security Critical: no
+Source: https://repo.or.cz/nasm.git
+
+Description:
+This contains the source to NASM, the assembler used for parts of Chromium.
+
+Local Modifications:
+* Applied deterministic.diff to make nasm deterministic.
+* Modified .gitignore not to hide generated files Chromium needs.
+
+To update, have clang in your system path (from //third_party/llvm-
+build/Release+Asserts/bin) then do the following:
+
+git remote add upstream https://repo.or.cz/nasm.git
+git fetch upstream
+git merge upstream/master
+CC=clang CXX=clang++ ./autogen.sh
+CC=clang CXX=clang++ ./configure
+make perlreq
+./generate_nasm_sources.py
+git add <any new .c/.h files which show up>
+git commit -a
+
diff --git a/generate_nasm_sources.py b/generate_nasm_sources.py
new file mode 100755
index 00000000..2b7bc59e
--- /dev/null
+++ b/generate_nasm_sources.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+#
+# Copyright 2018 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.
+
+"""A script to parse nasm's file lists out of Makefile.in."""
+
+import os
+import sys
+
+def ParseFileLists(path):
+ ret = {}
+ with open(path) as f:
+ in_file_list = False
+ split_line = ""
+ for line in f:
+ line = line.rstrip()
+ if not in_file_list:
+ if "-- Begin File Lists --" in line:
+ in_file_list = True
+ continue
+ if "-- End File Lists --" in line:
+ if split_line:
+ raise ValueError("End comment was preceded by split line")
+ break
+ line = split_line + line
+ split_line = ""
+ if line.endswith('\\'):
+ split_line = line[:-1]
+ continue
+ line = line.strip()
+ if not line:
+ continue
+ name, value = line.split('=')
+ name = name.strip()
+ value = value.replace("$(O)", "c")
+ files = value.split()
+ files.sort()
+ files = [file for file in files]
+ ret[name] = files
+ return ret
+
+def PrintFileList(out, name, files):
+ if len(files) == 0:
+ print >>out, "%s = []" % (name,)
+ elif len(files) == 1:
+ print >>out, "%s = [ \"%s\" ]" % (name, files[0])
+ else:
+ print >>out, "%s = [" % (name,)
+ for f in files:
+ print >>out, " \"%s\"," % (f,)
+ print >>out, "]"
+
+def main():
+ file_lists = ParseFileLists("Makefile.in")
+ with open("nasm_sources.gni", "w") as out:
+ print >>out, """# Copyright (c) 2018 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.
+
+# This file is created by generate_nasm_sources.py. Do not edit manually.
+"""
+ PrintFileList(out, "ndisasm_sources", file_lists['NDISASM'])
+ PrintFileList(out, "nasmlib_sources", file_lists['LIBOBJ'])
+ PrintFileList(out, "nasm_sources", file_lists['NASM'])
+
+if __name__ == "__main__":
+ main()
diff --git a/nasm_assemble.gni b/nasm_assemble.gni
new file mode 100644
index 00000000..2ed54491
--- /dev/null
+++ b/nasm_assemble.gni
@@ -0,0 +1,168 @@
+# Copyright 2018 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.
+
+# This provides the nasm_assemble() template which uses NASM to assemble
+# assembly files.
+#
+# Files to be assembled with NASM should have an extension of .asm.
+#
+# Parameters
+#
+# nasm_flags (optional)
+# [list of strings] Pass additional flags into NASM. These are appended
+# to the command line. Note that the output format is already set up
+# based on the current toolchain so you don't need to specify these
+# things (see below).
+#
+# Example: nasm_flags = [ "-Wall" ]
+#
+# include_dirs (optional)
+# [list of dir names] List of additional include dirs. Note that the
+# source root and the root generated file dir is always added, just like
+# our C++ build sets up.
+#
+# Example: include_dirs = [ "//some/other/path", target_gen_dir ]
+#
+# defines (optional)
+# [list of strings] List of defines, as with the native code defines.
+#
+# Example: defines = [ "FOO", "BAR=1" ]
+#
+# inputs, deps, visibility (optional)
+# These have the same meaning as in an action.
+#
+# Example
+#
+# nasm_assemble("my_nasm_target") {
+# sources = [
+# "ultra_optimized_awesome.asm",
+# ]
+# include_dirs = [ "assembly_include" ]
+# }
+
+import("//build/compiled_action.gni")
+
+if (is_mac || is_ios) {
+ if (current_cpu == "x86") {
+ _nasm_flags = [ "-fmacho32" ]
+ } else if (current_cpu == "x64") {
+ _nasm_flags = [ "-fmacho64" ]
+ }
+} else if (is_posix || is_fuchsia) {
+ if (current_cpu == "x86") {
+ _nasm_flags = [ "-felf32" ]
+ } else if (current_cpu == "x64") {
+ _nasm_flags = [
+ "-DPIC",
+ "-felf64",
+ ]
+ }
+} else if (is_win) {
+ if (current_cpu == "x86") {
+ _nasm_flags = [
+ "-DPREFIX",
+ "-fwin32",
+ ]
+ } else if (current_cpu == "x64") {
+ _nasm_flags = [ "-fwin64" ]
+ }
+}
+
+if (is_win) {
+ asm_obj_extension = "obj"
+} else {
+ asm_obj_extension = "o"
+}
+
+template("nasm_assemble") {
+ assert(defined(invoker.sources), "Need sources defined for $target_name")
+
+ # Only depend on NASM on x86 systems. Force compilation of .asm files for
+ # ARM to fail.
+ assert(current_cpu == "x86" || current_cpu == "x64")
+
+ action_name = "${target_name}_action"
+ source_set_name = target_name
+
+ compiled_action_foreach(action_name) {
+ # Only the source set can depend on this.
+ visibility = [ ":$source_set_name" ]
+
+ tool = "//third_party/nasm"
+
+ forward_variables_from(invoker,
+ [
+ "sources",
+ "inputs",
+ "deps",
+ ])
+
+ # Flags.
+ args = _nasm_flags
+ if (defined(invoker.nasm_flags)) {
+ args += invoker.nasm_flags
+ }
+
+ # User defined include dirs go first.
+ if (defined(invoker.include_dirs)) {
+ foreach(include, invoker.include_dirs) {
+ # NASM does not append path separators when processing the -I flags, so
+ # -Ifoo means includes of bar look up "foobar" rather than "foo/bar".
+ # Add the trailing slash for it.
+ args += [ "-I" + rebase_path(include, root_build_dir) + "/" ]
+ }
+ }
+
+ # Default nasm include dirs. Make it match the native build (source root and
+ # root generated code directory).
+ # This goes to the end of include list. Note that, as above, we must append
+ # path separators because NASM does not do it itself.
+ args += [
+ "-I./",
+
+ # rebase_path("//") already includes a trailing slash.
+ "-I" + rebase_path("//", root_build_dir),
+ "-I" + rebase_path(root_gen_dir, root_build_dir) + "/",
+ ]
+
+ # Extra defines.
+ if (defined(invoker.defines)) {
+ foreach(def, invoker.defines) {
+ args += [ "-D$def" ]
+ }
+ }
+
+ # Output file.
+ outputs = [
+ "$target_out_dir/$source_set_name/{{source_name_part}}.o",
+ ]
+ args += [
+ "-MD",
+ rebase_path(outputs[0] + ".d", root_build_dir),
+ "-o",
+ rebase_path(outputs[0], root_build_dir),
+ "{{source}}",
+ ]
+
+ depfile = outputs[0] + ".d"
+ }
+
+ # Gather the .o files into a linkable thing. This doesn't actually link
+ # anything (a source set just compiles files to link later), but will pass
+ # the object files generated by the action up the dependency chain.
+ static_library(source_set_name) {
+ if (defined(invoker.visibility)) {
+ visibility = invoker.visibility
+ }
+
+ sources = get_target_outputs(":$action_name")
+
+ # Do not publicize any header to remove build dependency.
+ public = []
+
+ deps = [
+ ":$action_name",
+ ]
+ }
+}
diff --git a/nasm_sources.gni b/nasm_sources.gni
new file mode 100644
index 00000000..93742d82
--- /dev/null
+++ b/nasm_sources.gni
@@ -0,0 +1,89 @@
+# Copyright (c) 2018 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.
+
+# This file is created by generate_nasm_sources.py. Do not edit manually.
+
+ndisasm_sources = [ "disasm/ndisasm.c" ]
+nasmlib_sources = [
+ "asm/assemble.c",
+ "asm/directbl.c",
+ "asm/directiv.c",
+ "asm/error.c",
+ "asm/eval.c",
+ "asm/exprdump.c",
+ "asm/exprlib.c",
+ "asm/float.c",
+ "asm/labels.c",
+ "asm/listing.c",
+ "asm/parser.c",
+ "asm/pptok.c",
+ "asm/pragma.c",
+ "asm/preproc-nop.c",
+ "asm/preproc.c",
+ "asm/quote.c",
+ "asm/rdstrnum.c",
+ "asm/segalloc.c",
+ "asm/stdscan.c",
+ "asm/strfunc.c",
+ "asm/tokhash.c",
+ "common/common.c",
+ "disasm/disasm.c",
+ "disasm/sync.c",
+ "macros/macros.c",
+ "nasmlib/badenum.c",
+ "nasmlib/bsi.c",
+ "nasmlib/crc64.c",
+ "nasmlib/file.c",
+ "nasmlib/filename.c",
+ "nasmlib/hashtbl.c",
+ "nasmlib/ilog2.c",
+ "nasmlib/malloc.c",
+ "nasmlib/md5c.c",
+ "nasmlib/mmap.c",
+ "nasmlib/path.c",
+ "nasmlib/perfhash.c",
+ "nasmlib/raa.c",
+ "nasmlib/rbtree.c",
+ "nasmlib/readnum.c",
+ "nasmlib/realpath.c",
+ "nasmlib/saa.c",
+ "nasmlib/srcfile.c",
+ "nasmlib/string.c",
+ "nasmlib/strlist.c",
+ "nasmlib/ver.c",
+ "nasmlib/zerobuf.c",
+ "output/codeview.c",
+ "output/legacy.c",
+ "output/nulldbg.c",
+ "output/nullout.c",
+ "output/outaout.c",
+ "output/outas86.c",
+ "output/outbin.c",
+ "output/outcoff.c",
+ "output/outdbg.c",
+ "output/outelf.c",
+ "output/outform.c",
+ "output/outieee.c",
+ "output/outlib.c",
+ "output/outmacho.c",
+ "output/outobj.c",
+ "output/outrdf2.c",
+ "output/strtbl.c",
+ "stdlib/snprintf.c",
+ "stdlib/strlcpy.c",
+ "stdlib/strnlen.c",
+ "stdlib/strrchrnul.c",
+ "stdlib/vsnprintf.c",
+ "x86/disp8.c",
+ "x86/iflag.c",
+ "x86/insnsa.c",
+ "x86/insnsb.c",
+ "x86/insnsd.c",
+ "x86/insnsn.c",
+ "x86/regdis.c",
+ "x86/regflags.c",
+ "x86/regs.c",
+ "x86/regvals.c",
+]
+nasm_sources = [ "asm/nasm.c" ]