This is an archive of the discontinued LLVM Phabricator instance.

gn build: Add support for building scudo and its unit tests.
ClosedPublic

Authored by pcc on Dec 5 2019, 10:59 AM.

Diff Detail

Event Timeline

pcc created this revision.Dec 5 2019, 10:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2019, 10:59 AM
Herald added subscribers: jfb, srhines. · View Herald Transcript

Build result: pass - 60520 tests passed, 0 failed and 726 were skipped.

Log files: console-log.txt, CMakeCache.txt

pcc updated this revision to Diff 232415.Dec 5 2019, 11:29 AM
  • gn format

Build result: FAILURE - Could not check out parent git hash "93bae253ee57aa94241382011f12488eff7d31e6". It was not found in the repository. Did you configure the "Parent Revision" in Phabricator properly? Trying to apply the patch to the master branch instead...

ERROR: arc patch failed with error code 1. Check build log for details.
Log files: console-log.txt, CMakeCache.txt

pcc updated this revision to Diff 232438.Dec 5 2019, 1:06 PM
  • Silence sync_source_lists_from_cmake.py

Build result: FAILURE - Could not check out parent git hash "93bae253ee57aa94241382011f12488eff7d31e6". It was not found in the repository. Did you configure the "Parent Revision" in Phabricator properly? Trying to apply the patch to the master branch instead...

ERROR: arc patch failed with error code 1. Check build log for details.
Log files: console-log.txt, CMakeCache.txt

phosek accepted this revision.Dec 5 2019, 4:49 PM

LGTM

This revision is now accepted and ready to land.Dec 5 2019, 4:49 PM
This revision was automatically updated to reflect the committed changes.
thakis added a comment.Dec 6 2019, 6:06 AM

I think the problem there is that on mac, libc++ headers are supposed to go with the compiler, and the stage1 clang in out/gn doesn't have libc++ headers installed next to it. The stage2_unix toolchain should depend on copying libc++ headers to the build output dir on macOS.

For now I'll disable this on mac, but every other stage2_unix target that uses C++ headers will have the same problem. So hopefully I'll find time to fix this right soon.

thakis added a comment.Dec 6 2019, 7:44 AM

I think the problem there is that on mac, libc++ headers are supposed to go with the compiler, and the stage1 clang in out/gn doesn't have libc++ headers installed next to it. The stage2_unix toolchain should depend on copying libc++ headers to the build output dir on macOS.

For now I'll disable this on mac, but every other stage2_unix target that uses C++ headers will have the same problem. So hopefully I'll find time to fix this right soon.

I looked a this some. It's easy to add a dep on libc++ [1]. However, scudo still fails to build with errors like ../../compiler-rt/lib/scudo/standalone/common.h:155:11: error: unknown type name 'MapPlatformData', and nothing seems to define that type on non-Linux. Is scudo supposed to build on mac in the cmake build?

1:

% git diff
diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn
index b8e46034cca..9ebbe001d0b 100644
--- a/llvm/utils/gn/build/toolchain/BUILD.gn
+++ b/llvm/utils/gn/build/toolchain/BUILD.gn
@@ -183,7 +183,9 @@ template("stage2_unix_toolchain") {
       "//:clang($host_toolchain)",
       "//:lld($host_toolchain)",
     ]
-    if (current_os != "mac") {
+    if (current_os == "mac") {
+      deps += [ "//libcxx/include" ]
+    } else {
       deps += [ "//:llvm-ar($host_toolchain)" ]
     }
   }
diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/scudo/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/scudo/BUILD.gn
index a95613c5bcd..8c658837cd2 100644
--- a/llvm/utils/gn/secondary/compiler-rt/lib/scudo/BUILD.gn
+++ b/llvm/utils/gn/secondary/compiler-rt/lib/scudo/BUILD.gn
@@ -1,11 +1,7 @@
 import("//llvm/utils/gn/build/toolchain/compiler.gni")
 
 supported_toolchains = []
-# FIXME: On macOS, stage2_unix currently doesn't copy libc++ headers to
-# the out dir, but clang relies on them on mac to compile code that uses C++
-# standard library headers. scudo needs C++ standard library headers, so disable
-# this on mac until stage2_unix correctly copies libc++ headers.
-if (target_os != "win" && target_os != "mac")  {
+if (target_os != "win")  {
   supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ]
 }
 if (android_ndk_path != "") {
pcc added a comment.Dec 6 2019, 10:12 AM

Yes, looking through the code as well as the CMake [1], scudo only supports building on Linux, Android and Fuchsia. Most of the code in linux.cpp looks like it would work on non-Linux POSIX, except for the mutex implementation.

It looks like the non-standalone allocator had some level of support for Windows [2] but that wasn't carried over to the standalone allocator.

So we should probably change the blacklist in the supported platforms to a whitelist for now. I'll go ahead and do that.

[1] http://llvm-cs.pcc.me.uk/projects/compiler-rt/cmake/config-ix.cmake#695
[2] http://llvm-cs.pcc.me.uk/projects/compiler-rt/lib/scudo/scudo_allocator_secondary.h#110

pcc added a comment.Dec 6 2019, 10:23 AM
In D71081#1773044, @pcc wrote:

Yes, looking through the code as well as the CMake [1], scudo only supports building on Linux, Android and Fuchsia. Most of the code in linux.cpp looks like it would work on non-Linux POSIX, except for the mutex implementation.

It looks like the non-standalone allocator had some level of support for Windows [2] but that wasn't carried over to the standalone allocator.

So we should probably change the blacklist in the supported platforms to a whitelist for now. I'll go ahead and do that.

[1] http://llvm-cs.pcc.me.uk/projects/compiler-rt/cmake/config-ix.cmake#695
[2] http://llvm-cs.pcc.me.uk/projects/compiler-rt/lib/scudo/scudo_allocator_secondary.h#110

D71131