[llvm] ead0b76 - [gn build] Make build locally deterministic

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 14 18:56:04 PST 2020


Author: Nico Weber
Date: 2020-02-14T21:55:33-05:00
New Revision: ead0b76382a5a20e8164583d86900de5b3fa9288

URL: https://github.com/llvm/llvm-project/commit/ead0b76382a5a20e8164583d86900de5b3fa9288
DIFF: https://github.com/llvm/llvm-project/commit/ead0b76382a5a20e8164583d86900de5b3fa9288.diff

LOG: [gn build] Make build locally deterministic

This follows http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
to make the GN build locally deterministic.

With this, I've built lld at two different build paths on my Windows box and got
identical binaries. (I'd expect the same to happen on Linux, and with other
binaries.)

This doesn't have the bits to get universal determinism yet.

Differential Revision: https://reviews.llvm.org/D74519

Added: 
    llvm/utils/gn/docs/deterministic.md

Modified: 
    llvm/utils/gn/build/BUILD.gn
    llvm/utils/gn/build/toolchain/BUILD.gn

Removed: 
    


################################################################################
diff  --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index b74268996f15..488e248da3a7 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -11,6 +11,14 @@ declare_args() {
   #        out/gn/bin/llvm-undname ...`
   # to generate a HTML report for the binaries passed in the last line.
   llvm_build_instrumented_coverage = false
+
+  # If set, puts relative paths in debug info.
+  # Makes the build output independent of the build directory, but makes
+  # most debuggers harder to use. See "Getting to local determinism" and
+  # "Getting debuggers to work well with locally deterministic builds" in
+  # http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
+  # for more information.
+  use_relative_paths_in_debug_info = false
 }
 
 assert(!llvm_build_instrumented_coverage || is_clang,
@@ -168,6 +176,37 @@ config("compiler_defaults") {
     ]
     ldflags += [ "-fprofile-instr-generate" ]
   }
+
+  # Deterministic build setup, see
+  # http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html
+  if (current_os == "win") {
+    ldflags += [ "/pdbaltpath:%_PDB%" ]
+  }
+  if (is_clang) {
+    cflags += [
+      "-no-canonical-prefixes",
+      "-Werror=date-time",
+    ]
+    if (current_os == "win") {
+      cflags += [
+        "-fmsc-version=1916",
+        "/X",
+      ]
+    }
+    if (current_os == "win" && use_lld) {
+      cflags += [ "/Brepro" ]
+      ldflags += [
+        "/Brepro",
+        "/lldignoreenv",
+      ]
+    }
+    if (use_relative_paths_in_debug_info) {
+      cflags += [
+        "-fdebug-compilation-dir",
+        ".",
+      ]
+    }
+  }
 }
 
 config("no_exceptions") {

diff  --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index d435d9c97264..453aab572525 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -39,7 +39,7 @@ template("unix_toolchain") {
 
     tool("alink") {
       if (current_os == "mac") {
-        command = "libtool -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
+        command = "libtool -D -static -no_warning_for_no_symbols {{arflags}} -o {{output}} {{inputs}}"
       } else {
         # Remove the output file first so that ar doesn't try to modify the
         # existing file.

diff  --git a/llvm/utils/gn/docs/deterministic.md b/llvm/utils/gn/docs/deterministic.md
new file mode 100644
index 000000000000..36d518576acc
--- /dev/null
+++ b/llvm/utils/gn/docs/deterministic.md
@@ -0,0 +1,18 @@
+Deterministic builds with LLVM's GN build
+=========================================
+
+Summary: Use the following args.gn.
+
+    use_relative_paths_in_debug_info = true
+
+It is possible to produce [locally deterministic][1] builds of LLVM
+with the GN build. It requires some configuration though.
+
+1. Make debug info use relative paths by setting
+   `use_relative_paths_in_debug_info = true` in your `args.gn` file. With this
+   set, current debuggers need minor configuration to keep working.  See
+   "Getting to local determinism" and "Getting debuggers to work well with
+   locally deterministic builds" in the [deterministic builds][1] documentation
+   for details.
+
+1: http://blog.llvm.org/2019/11/deterministic-builds-with-clang-and-lld.html


        


More information about the llvm-commits mailing list