1# The following variables will likely need to be modified, depending on where 2# and how you built LLVM & Clang. They can be overridden in a command-line 3# invocation of make, like: 4# 5# make LLVM_SRC_PATH=<path> LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \ 6# PNACL_BIN_PATH=<path> ... 7# 8 9# LLVM_SRC_PATH is the path to the root of the checked out source code. This 10# directory should contain the configure script, the include/ and lib/ 11# directories of LLVM, Clang in tools/clang/, etc. 12# Alternatively, if you're building vs. a binary download of LLVM, then 13# LLVM_SRC_PATH can point to the main untarred directory. 14LLVM_SRC_PATH ?= ../llvm 15 16# The x86-32-specific sandboxed translator directory. 17# It holds sandboxed versions of libraries and binaries. 18SB_LLVM_PATH ?= $(shell readlink -e \ 19 ../../out/sandboxed_translators_work/translator-i686/llvm-sb/Release) 20 21# NACL_ROOT is the root of the native client repository. 22NACL_ROOT ?= $(shell python -c "import sys; sys.path.insert(0, 'pydir'); \ 23 import utils; print utils.FindBaseNaCl()") 24 25# TOOLCHAIN_ROOT is the location of NaCl/PNaCl toolchains and other 26# tools like qemu. 27TOOLCHAIN_ROOT ?= $(shell readlink -e $(NACL_ROOT)/toolchain/linux_x86) 28 29# PNACL_TOOLCHAIN_ROOT is the location of the PNaCl toolchain. 30# This is used as the default root for finding binutils, libcxx, etc. 31PNACL_TOOLCHAIN_ROOT ?= $(shell readlink -e $(TOOLCHAIN_ROOT)/pnacl_newlib_raw) 32 33# The location of PNaCl tools (e.g., binutils objdump, pnacl-clang++, etc.). 34PNACL_BIN_PATH ?= $(shell readlink -e $(PNACL_TOOLCHAIN_ROOT)/bin) 35 36# Allow tests to be overridden, e.g.: 37# make -f Makefile.standalone check-lit \ 38# CHECK_LIT_TESTS="tests_lit/llvm2ice_tests/{alloc,arith}.ll" 39# make -f Makefile.standalone check-xtest \ 40# CHECK_XTEST_TESTS=crosstest/Output/simple_loop_x8632_native_O2_sse2.xtest 41CHECK_LIT_TESTS ?= tests_lit 42CHECK_XTEST_TESTS ?= crosstest/Output 43 44# Hack to auto-detect autoconf versus cmake build of LLVM. If the LLVM tools 45# were dynamically linked with something like libLLVM-3.7svn.so, it is an 46# autoconf build, otherwise it is a cmake build. AUTOCONF is set to 0 for 47# cmake, nonzero for autoconf. 48AUTOCONF ?= $(shell ldd $(PNACL_BIN_PATH)/opt | grep -c libLLVM-) 49 50# CLANG_PATH is the location of the clang compiler to use for building 51# the host binaries. 52CLANG_PATH ?= $(shell readlink -e \ 53 $(NACL_ROOT)/../third_party/llvm-build/Release+Asserts/bin) 54 55# LIBCXX_INSTALL_PATH is the directory where libc++ is located. It should 56# contain header files and corresponding libraries. This is used for 57# building the host binaries in conjuction with clang. 58LIBCXX_INSTALL_PATH ?= $(PNACL_TOOLCHAIN_ROOT) 59STDLIB_FLAGS := -stdlib=libc++ -I$(LIBCXX_INSTALL_PATH)/include/c++/v1 60 61HOST_ARCH ?= x86_64 62ifeq ($(HOST_ARCH),x86_64) 63 HOST_FLAGS = -m64 64else 65 ifeq ($(HOST_ARCH),x86) 66 HOST_FLAGS = -m32 67 endif 68endif 69 70ifdef DEBUG 71 OBJDIR = build/Debug 72 OPTLEVEL = -O0 73 LINKOPTLEVEL = -O0 74else 75 OBJDIR = build/Release 76 OPTLEVEL = -O2 -ffunction-sections -fdata-sections 77 LINKOPTLEVEL = -O2 78endif 79 80# The list of CXX defines that are dependent on build parameters. 81BASE_CXX_DEFINES = 82CXX_EXTRA = 83LD_EXTRA = 84 85ifdef MINIMAL 86 NOASSERT = 1 87 NODUMP = 1 88 OBJDIR := $(OBJDIR)+Min 89 BASE_CXX_DEFINES += -DALLOW_LLVM_CL=0 -DALLOW_LLVM_IR=0 \ 90 -DALLOW_LLVM_IR_AS_INPUT=0 -DALLOW_TIMERS=0 -DALLOW_MINIMAL_BUILD=1 91else 92 BASE_CXX_DEFINES += -DALLOW_LLVM_CL=1 -DALLOW_LLVM_IR=1 \ 93 -DALLOW_LLVM_IR_AS_INPUT=1 -DALLOW_TIMERS=1 -DALLOW_MINIMAL_BUILD=0 94endif 95 96ifdef NODUMP 97 OBJDIR := $(OBJDIR)+NoDump 98 BASE_CXX_DEFINES += -DALLOW_DUMP=0 99else 100 BASE_CXX_DEFINES += -DALLOW_DUMP=1 101endif 102 103# Restrict to a single supported target. Current options: 104# SZTARGET=ARM32 105# SZTARGET=MIPS32 106# SZTARGET=X8632 107# SZTARGET=X8664 108ifdef SZTARGET 109 OBJDIR := $(OBJDIR)+T_$(SZTARGET) 110 BASE_CXX_DEFINES += -DSZTARGET=$(SZTARGET) 111endif 112 113BASE_CXX_DEFINES += -DPNACL_LLVM 114SZ_COMMIT_COUNT := $(shell git rev-list --count HEAD) 115SZ_GIT_HASH := $(shell git rev-parse HEAD) 116BASE_CXX_DEFINES += -DSUBZERO_REVISION=$(SZ_COMMIT_COUNT)_$(SZ_GIT_HASH) 117 118CXX_DEFINES := $(BASE_CXX_DEFINES) -DPNACL_BROWSER_TRANSLATOR=0 119 120ifdef NOASSERT 121 ASSERTIONS = -DNDEBUG 122else 123 ASSERTIONS = 124 OBJDIR := $(OBJDIR)+Asserts 125endif 126 127ifdef UBSAN 128 OBJDIR := $(OBJDIR)+UBSan 129 CXX_EXTRA += -fsanitize=undefined -fno-sanitize=vptr \ 130 -fno-sanitize=nonnull-attribute 131 LD_EXTRA += -fsanitize=undefined 132endif 133 134ifdef UBSAN_TRAP 135 OBJDIR := $(OBJDIR)+UBSan_Trap 136 CXX_EXTRA += -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error \ 137 -fno-sanitize=vptr -fno-sanitize=nonnull-attribute 138 LD_EXTRA += -fsanitize=undefined-trap 139endif 140 141ifdef TSAN 142 OBJDIR := $(OBJDIR)+TSan 143 CXX_EXTRA += -fsanitize=thread 144 LD_EXTRA += -fsanitize=thread 145endif 146 147ifdef ASAN 148 OBJDIR := $(OBJDIR)+ASan 149 CXX_EXTRA += -fsanitize=address 150 LD_EXTRA += -fsanitize=address 151endif 152 153ifdef MSAN 154 # TODO(ascull): this has an as yet undiagnosed uninitialized memory access 155 OBJDIR := $(OBJDIR)+MSan 156 CXX_EXTRA += -fsanitize=memory 157 LD_EXTRA += -fsanitize=memory 158endif 159 160ifdef FORCEASM 161 FORCEASM_FLAG = --filetype=asm 162 # With --filetype=asm and --sandbox, the llvm-mc assembler emits the lock and 163 # 16-bit prefixes in the "wrong" order, causing the validator to reject the 164 # resulting nexe. So we just disable those tests for now. 165 FORCEASM_XTEST_EXCLUDES = -e x8632,sandbox,test_sync_atomic 166 FORCEASM_LIT_PARAM = --param=FORCEASM 167 # x86 sandboxing lit tests are disabled because filetype=asm does not 168 # handle bundle_lock pad-to-end correctly. 169 # TODO(jpp): fix this. 170 FORCEASM_LIT_TEST_EXCLUDES = --filter='^(?!.*/x86/sandboxing.ll).*' 171else 172 FORCEASM_FLAG = 173 FORCEASM_XTEST_EXCLUDES = 174 FORCEASM_LIT_PARAM = 175 FORCEASM_LIT_TEST_EXCLUDES = 176endif 177 178ifdef LINUX_MALLOC_PROFILE 179 OBJDIR := $(OBJDIR)+MalProf 180 CXX_EXTRA += -DALLOW_LINUX_MALLOC_PROFILE=1 181 LD_EXTRA += -Wl,--export-dynamic 182endif 183 184SB_OBJDIR := $(OBJDIR)+Sandboxed 185SBB_OBJDIR := $(OBJDIR)+SandboxedBrowser 186 187V8_DIR = $(NACL_ROOT)/../v8 188V8_CXXFLAGS := -I$(V8_DIR) 189 190$(info -----------------------------------------------) 191$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH)) 192$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH)) 193$(info Using NACL_ROOT = $(NACL_ROOT)) 194$(info Using TOOLCHAIN_ROOT = $(TOOLCHAIN_ROOT)) 195$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT)) 196$(info Using PNACL_BIN_PATH = $(PNACL_BIN_PATH)) 197$(info Using CLANG_PATH = $(CLANG_PATH)) 198$(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH)) 199$(info Using HOST_ARCH = $(HOST_ARCH)) 200$(info -----------------------------------------------) 201 202LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags` 203SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS) 204 205# Listing specific libraries that are needed for pnacl-sz 206# and the unittests, since we build "tools-only" for the 207# sandboxed_translators (which doesn't include every library 208# listed by llvm-config). 209 210LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \ 211 -lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \ 212 -lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport 213 214ifeq ($(AUTOCONF), 0) 215 # LLVM cmake build 216 LLVM_LIBS := $(LLVM_LIBS_LIST) 217 # For the cmake build, the gtest libs end up in the same place as the LLVM 218 # libs, so no "-L..." arg is needed. 219 GTEST_LIB_PATH ?= 220 CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH) 221else 222 # LLVM autoconf build 223 LLVM_LIBS := -lLLVM-3.7svn 224 GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib 225 ifneq ($(wildcard \ 226 ../../out/llvm_x86_64_linux_work/Release+Asserts/bin/clang-format),) 227 CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin 228 else 229 CLANG_FORMAT_PATH ?= \ 230 ../../out/llvm_x86_64_linux_debug_work/Debug+Asserts/bin 231 endif 232endif 233 234LLVM_LDFLAGS := $(LLVM_LIBS) \ 235 `$(PNACL_BIN_PATH)/llvm-config --ldflags` \ 236 `$(PNACL_BIN_PATH)/llvm-config --system-libs` 237SB_LLVM_LDFLAGS := -Wl,--start-group $(LLVM_LIBS_LIST) -Wl,--end-group \ 238 -L$(SB_LLVM_PATH)/lib 239 240CCACHE := `command -v ccache` 241CXX := CCACHE_CPP2=yes $(CCACHE) $(CLANG_PATH)/clang++ 242SB_CXX := CCACHE_CPP2=yes $(CCACHE) $(PNACL_BIN_PATH)/pnacl-clang++ 243SB_TRANSLATE := $(PNACL_BIN_PATH)/pnacl-translate 244SB_FINALIZE := $(PNACL_BIN_PATH)/pnacl-finalize --no-strip-syms 245 246# Extra warnings that LLVM's build system adds in addition to -Wall. 247LLVM_EXTRA_WARNINGS := -Wcovered-switch-default 248 249# Use g++ to compile, to check for errors/warnings that clang++ might have 250# missed. It's unlikely to link, unless LLVM was also built with g++, so the 251# compile_only target should be used. Note: This ifdef section is deliberately 252# placed here instead of with the other ifdef sections, so that its redefinition 253# of CXX/STDLIB_FLAGS/LLVM_EXTRA_WARNINGS follows their normal definitions. 254ifdef GPLUSPLUS 255 CXX := CCACHE_CPP2=yes $(CCACHE) g++ 256 STDLIB_FLAGS := 257 LLVM_EXTRA_WARNINGS := \ 258 -Wcast-qual \ 259 -Wno-comment \ 260 -Wno-long-long \ 261 -Wno-maybe-uninitialized \ 262 -Wno-missing-field-initializers \ 263 -Wno-unused-parameter \ 264 -Wwrite-strings 265 OBJDIR := $(OBJDIR)+Gplusplus 266endif 267 268BASE_CXXFLAGS := -std=gnu++11 -Wall -Wextra -fno-rtti \ 269 -fno-exceptions $(OPTLEVEL) $(ASSERTIONS) -g -pedantic \ 270 $(LLVM_EXTRA_WARNINGS) $(CXX_EXTRA) -MP -MD -Werror 271 272ifdef WASM 273 BASE_CXXFLAGS := $(BASE_CXXFLAGS) $(V8_CXXFLAGS) -DALLOW_WASM=1 274 OBJDIR := $(OBJDIR)+Wasm 275else 276 BASE_CXXFLAGS := $(BASE_CXXFLAGS) -DALLOW_WASM=0 277endif 278 279# TODO(stichnot,jpp): Restructure static fields in template classes to avoid 280# needing -Wno-undefined-var-template . 281CXXFLAGS := $(LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(CXX_DEFINES) $(HOST_FLAGS) \ 282 $(STDLIB_FLAGS) -Wno-undefined-var-template 283SB_CXXFLAGS := $(SB_LLVM_CXXFLAGS) $(BASE_CXXFLAGS) $(BASE_CXX_DEFINES) \ 284 -Wno-unknown-pragmas -I$(NACL_ROOT) -I$(NACL_ROOT)/.. 285 286LDFLAGS := $(HOST_FLAGS) -L$(LIBCXX_INSTALL_PATH)/lib -Wl,--gc-sections \ 287 $(LD_EXTRA) $(STDLIB_FLAGS) 288# Not specifying -Wl,--gc-sections but instead doing bitcode linking GC w/ LTO. 289SB_LDFLAGS := $(LINKOPTLEVEL) $(LD_EXTRA) 290 291# List the target-specific source files first, which generally take longer to 292# compile, in the hope of improving parallel build time. 293SRCS = \ 294 IceAssemblerARM32.cpp \ 295 IceAssemblerMIPS32.cpp \ 296 IceInstARM32.cpp \ 297 IceInstMIPS32.cpp \ 298 IceInstX8632.cpp \ 299 IceInstX8664.cpp \ 300 IceTargetLowering.cpp \ 301 IceTargetLoweringARM32.cpp \ 302 IceTargetLoweringMIPS32.cpp \ 303 IceTargetLoweringX86.cpp \ 304 IceTargetLoweringX8632.cpp \ 305 IceTargetLoweringX8664.cpp \ 306 IceAssembler.cpp \ 307 IceBrowserCompileServer.cpp \ 308 IceCfg.cpp \ 309 IceCfgNode.cpp \ 310 IceClFlags.cpp \ 311 IceCompiler.cpp \ 312 IceCompileServer.cpp \ 313 IceELFObjectWriter.cpp \ 314 IceELFSection.cpp \ 315 IceFixups.cpp \ 316 IceGlobalContext.cpp \ 317 IceGlobalInits.cpp \ 318 IceInst.cpp \ 319 IceIntrinsics.cpp \ 320 IceLiveness.cpp \ 321 IceLoopAnalyzer.cpp \ 322 IceMangling.cpp \ 323 IceMemory.cpp \ 324 IceOperand.cpp \ 325 IceRangeSpec.cpp \ 326 IceRegAlloc.cpp \ 327 IceRevision.cpp \ 328 IceRNG.cpp \ 329 IceSwitchLowering.cpp \ 330 IceThreading.cpp \ 331 IceTimerTree.cpp \ 332 IceTranslator.cpp \ 333 IceTypes.cpp \ 334 IceVariableSplitting.cpp \ 335 LinuxMallocProfiling.cpp \ 336 main.cpp \ 337 PNaClTranslator.cpp 338 339ifndef MINIMAL 340 SRCS += \ 341 IceASanInstrumentation.cpp \ 342 IceConverter.cpp \ 343 IceInstrumentation.cpp \ 344 IceTypeConverter.cpp 345endif 346 347ifdef WASM 348 SRCS += \ 349 WasmTranslator.cpp 350endif 351 352OBJS=$(patsubst %.cpp, $(OBJDIR)/%.o, $(SRCS)) 353SB_OBJS=$(patsubst %.cpp, $(SB_OBJDIR)/%.o, $(SRCS)) 354SBB_OBJS=$(patsubst %.cpp, $(SBB_OBJDIR)/%.o, $(SRCS)) 355 356UNITTEST_SRCS = \ 357 BitcodeMunge.cpp \ 358 IceELFSectionTest.cpp \ 359 IceParseInstsTest.cpp 360 361# The X86 assembler tests take too long to compile. Given how infrequently the 362# assembler will change, we disable them. 363ifdef CHECK_X86_ASM 364 ifndef DEBUG 365 $(error Run check-unit with DEBUG=1 lest your machine perish) 366 endif 367 UNITTEST_SRCS += AssemblerX8632/LowLevel.cpp \ 368 AssemblerX8632/DataMov.cpp \ 369 AssemblerX8632/Locked.cpp \ 370 AssemblerX8632/GPRArith.cpp \ 371 AssemblerX8632/XmmArith.cpp \ 372 AssemblerX8632/ControlFlow.cpp \ 373 AssemblerX8632/Other.cpp \ 374 AssemblerX8632/X87.cpp \ 375 AssemblerX8664/LowLevel.cpp \ 376 AssemblerX8664/DataMov.cpp \ 377 AssemblerX8664/Locked.cpp \ 378 AssemblerX8664/GPRArith.cpp \ 379 AssemblerX8664/XmmArith.cpp \ 380 AssemblerX8664/ControlFlow.cpp \ 381 AssemblerX8664/Other.cpp 382endif 383 384UNITTEST_OBJS = $(patsubst %.cpp, $(OBJDIR)/unittest/%.o, $(UNITTEST_SRCS)) 385UNITTEST_LIB_OBJS = $(filter-out $(OBJDIR)/main.o,$(OBJS)) 386 387NEXES = $(SB_OBJDIR)/pnacl-sz.x8632.nexe \ 388 $(SB_OBJDIR)/pnacl-sz.x8664.nexe \ 389 $(SBB_OBJDIR)/pnacl_public_x86_32_pnacl_sz_nexe \ 390 $(SBB_OBJDIR)/pnacl_public_x86_64_pnacl_sz_nexe 391NEXES_LITE = $(SB_OBJDIR)/pnacl-sz.x8664.nexe 392 393# Keep all the first target so it's the default. 394all: $(OBJDIR)/pnacl-sz make_symlink runtime 395 396ifdef TSAN 397sb sb-lite: 398 @echo "Skipping pnacl-sz.*.nexe: TSAN isn't supported under NaCl." 399else 400sb: $(NEXES) sb_make_symlink exists-sbtc 401sb-lite: $(NEXES_LITE) exists-sbtc 402endif 403 404# SHOW_BUILD_ATTS is an executable that is run to show what build 405# attributes were used to build pnacl-sz. 406SHOW_BUILD_ATTS = $(OBJDIR)/pnacl-sz --build-atts 407 408# Creates symbolic link so that testing is easier. Also runs 409# pnacl-sz to verify that the defines flags have valid values, 410# as well as describe the corresponding build attributes. 411make_symlink: $(OBJDIR)/pnacl-sz 412 rm -rf pnacl-sz 413 ln -s $(OBJDIR)/pnacl-sz 414 @echo "Build Attributes:" 415 @$(SHOW_BUILD_ATTS) 416 417sb_make_symlink: $(NEXES) 418 $(foreach nexe,$(NEXES),rm -rf $(notdir $(nexe)); ln -s $(nexe);) 419 420%.pexe : %.nonfinal.pexe 421 $(SB_FINALIZE) -o $@ $< 422 423.PHONY: all compile_only make_symlink runtime bloat sb docs help \ 424 help-check-lit help-check-xtest exists-nonsfi-x8632 \ 425 exists-nonsfi-arm32 exists-sbtc exists-spec 426 427compile_only: $(OBJS) 428 429V8_LIBDIR=$(V8_DIR)/out/native/lib.target 430 431ifdef WASM 432 V8_LIBS := \ 433 $(V8_LIBDIR)/libv8.so \ 434 $(V8_LIBDIR)/libicuuc.so \ 435 $(V8_LIBDIR)/libicui18n.so 436endif 437 438$(OBJDIR)/pnacl-sz: $(OBJS) 439 $(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \ 440 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) $(V8_LIBS) 441 442$(SB_OBJDIR)/pnacl-sz.nonfinal.pexe: $(SB_OBJS) 443 $(SB_CXX) $(SB_LDFLAGS) -o $@ $^ $(SB_LLVM_LDFLAGS) 444 445$(SBB_OBJDIR)/pnacl-sz.nonfinal.pexe: $(SBB_OBJS) 446 $(SB_CXX) $(SB_LDFLAGS) -o $@ $^ $(SB_LLVM_LDFLAGS) \ 447 --pnacl-disable-abi-check 448 449$(SB_OBJDIR)/pnacl-sz.x8632.nexe: $(SB_OBJDIR)/pnacl-sz.pexe 450 $(SB_TRANSLATE) -arch x86-32 $^ -o $@ 451 452$(SB_OBJDIR)/pnacl-sz.x8664.nexe: $(SB_OBJDIR)/pnacl-sz.pexe 453 $(SB_TRANSLATE) -arch x86-64 $^ -o $@ 454 455$(SBB_OBJDIR)/pnacl_public_x86_32_pnacl_sz_nexe: $(SBB_OBJDIR)/pnacl-sz.pexe 456 $(SB_TRANSLATE) -arch x86-32 $^ -o $@ 457 458$(SBB_OBJDIR)/pnacl_public_x86_64_pnacl_sz_nexe: $(SBB_OBJDIR)/pnacl-sz.pexe 459 $(SB_TRANSLATE) -arch x86-64 $^ -o $@ 460 461src/IceRegistersARM32.def: pydir/gen_arm32_reg_tables.py 462 python $< > $@ 463 464-include $(foreach dep,$(SRCS:.cpp=.d),$(OBJDIR)/$(dep)) 465$(OBJS): $(OBJDIR)/%.o: src/%.cpp 466 $(CXX) -c $(CXXFLAGS) $< -o $@ 467 468-include $(foreach dep,$(SRCS:.cpp=.d),$(SB_OBJDIR)/$(dep)) 469$(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp 470 $(SB_CXX) -c $(SB_CXXFLAGS) -DPNACL_BROWSER_TRANSLATOR=0 $< -o $@ 471 472-include $(foreach dep,$(SRCS:.cpp=.d),$(SBB_OBJDIR)/$(dep)) 473$(SBB_OBJS): $(SBB_OBJDIR)/%.o: src/%.cpp 474 $(SB_CXX) -c $(SB_CXXFLAGS) -DPNACL_BROWSER_TRANSLATOR=1 $< -o $@ 475 476$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS) 477 $(CXX) $(GTEST_LIB_PATH) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \ 478 -lgtest -lgtest_main -ldl \ 479 -Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib) 480 481-include $(foreach dep,$(UNITTEST_SRCS:.cpp=.d),$(OBJDIR)/unittest/$(dep)) 482$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp 483 $(CXX) -c $(CXXFLAGS) \ 484 -Isrc/ \ 485 -Iunittest/ \ 486 -I$(LLVM_SRC_PATH)/utils/unittest/googletest/include \ 487 -I$(LLVM_SRC_PATH) \ 488 -DGTEST_HAS_RTTI=0 -DGTEST_USE_OWN_TR1_TUPLE \ 489 -Wno-expansion-to-defined \ 490 $< -o $@ 491 492$(OBJS): | $(OBJDIR) 493$(SB_OBJS): | $(SB_OBJDIR) 494$(SBB_OBJS): | $(SBB_OBJDIR) 495 496$(UNITTEST_OBJS): | $(OBJDIR)/unittest $(OBJDIR)/unittest/AssemblerX8632 \ 497 $(OBJDIR)/unittest/AssemblerX8664 498 499$(OBJDIR): 500 @mkdir -p $@ 501$(SB_OBJDIR): 502 @mkdir -p $@ 503$(SBB_OBJDIR): 504 @mkdir -p $@ 505 506$(OBJDIR)/unittest: $(OBJDIR) 507 @mkdir -p $@ 508 509$(OBJDIR)/unittest/AssemblerX8632: $(OBJDIR)/unittest 510 @mkdir -p $@ 511$(OBJDIR)/unittest/AssemblerX8664: $(OBJDIR)/unittest 512 @mkdir -p $@ 513 514RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c \ 515 runtime/szrt_asm_x8632.s runtime/szrt_asm_x8664.s \ 516 runtime/szrt_asm_arm32.s runtime/szrt_asan.c 517RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \ 518 build/runtime/szrt_nonsfi_x8632.o \ 519 build/runtime/szrt_native_x8664.o build/runtime/szrt_sb_x8664.o \ 520 build/runtime/szrt_nonsfi_x8664.o \ 521 build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o \ 522 build/runtime/szrt_nonsfi_arm32.o \ 523 build/runtime/szrt_asan_x8632.o build/runtime/szrt_asan_x8664.o \ 524 build/runtime/szrt_asan_arm32.o 525 526EXCLUDED_RT := 527ifdef MIPS 528RT_SRC += runtime/szrt_asm_mips32.s 529RT_OBJ += build/runtime/szrt_native_mips32.o build/runtime/szrt_sb_mips32.o 530else 531EXCLUDED_RT += --exclude-target=mips32 532endif 533 534runtime: $(RT_OBJ) 535 536# Use runtime.is.built so that build-runtime.py is invoked only once 537# even in a parallel build. 538.INTERMEDIATE: runtime.is.built 539$(RT_OBJ): runtime.is.built 540runtime.is.built: $(RT_SRC) pydir/build-runtime.py 541 @echo ================ Building Subzero runtime ================ 542 ./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT) \ 543 $(EXCLUDED_RT) 544 545check-lit: $(OBJDIR)/pnacl-sz make_symlink runtime 546 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \ 547 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_LIT_TESTS) \ 548 $(FORCEASM_LIT_TEST_EXCLUDES) $(FORCEASM_LIT_PARAM) 549 550ifdef MINIMAL 551check-xtest check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime 552 @echo "Crosstests disabled, minimal build" 553else 554ifdef MIPS 555check-xtest check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime \ 556 crosstest/test_arith_ll.ll 557 # Do all x8664/native/sse2 tests as a smoke test. 558 # Add in mips32 tests as they come online. 559 ./pydir/crosstest_generator.py -v --lit \ 560 --toolchain-root $(TOOLCHAIN_ROOT) \ 561 $(FORCEASM_FLAG) \ 562 $(FORCEASM_XTEST_EXCLUDES) \ 563 -i x8664,native,sse2 \ 564 -i mips32,native,Om1,simple_loop \ 565 -i mips32,native,Om1,test_strengthreduce 566 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \ 567 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS) 568else 569check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime \ 570 exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll 571 # Do all native/sse2 tests, but only test_vector_ops for native/sse4.1. 572 # For (slow) sandboxed tests, limit to Om1/sse4.1. 573 # run.py (used to run the sandboxed xtests) does not support 574 # specifying -cpu cortex-a15 to qemu, hence we disable the 575 # hwdiv-arm tests. 576 ./pydir/crosstest_generator.py -v --lit \ 577 --toolchain-root $(TOOLCHAIN_ROOT) \ 578 $(FORCEASM_FLAG) \ 579 $(FORCEASM_XTEST_EXCLUDES) \ 580 -i x8632,native,sse2 \ 581 -i x8632,native,sse4.1,test_vector_ops \ 582 -i x8632,sandbox,sse4.1,Om1 \ 583 -i x8632,nonsfi,sse2,O2 \ 584 -i x8664,native,sse2 \ 585 -i x8664,native,sse4.1,test_vector_ops \ 586 -i x8664,sandbox,sse4.1,Om1 \ 587 -i arm32 \ 588 -e arm32,sandbox,hwdiv-arm 589 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \ 590 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS) 591check-xtest-lite: $(OBJDIR)/pnacl-sz make_symlink runtime \ 592 exists-nonsfi-x8632 exists-nonsfi-arm32 crosstest/test_arith_ll.ll 593 # Do all native/sse2/neon tests, which are relatively fast. 594 # Limit to test_global+mem_intrin for sandbox+nonsfi because sandbox and 595 # nonsfi builds are slow, and test_global and mem_intrin are the most 596 # common sources of problems. 597 ./pydir/crosstest_generator.py -v --lit \ 598 --toolchain-root $(TOOLCHAIN_ROOT) \ 599 $(FORCEASM_FLAG) \ 600 $(FORCEASM_XTEST_EXCLUDES) \ 601 -i x8632,native,sse2,O2 \ 602 -i x8664,native,sse2,O2 \ 603 -i arm32,native,neon,O2 \ 604 -i x8632,sse2,O2,test_global \ 605 -i x8632,sse2,O2,mem_intrin \ 606 -i x8664,sse2,O2,test_global \ 607 -i x8664,sse2,O2,mem_intrin \ 608 -i arm32,neon,O2,test_global \ 609 -i arm32,neon,O2,mem_intrin \ 610 -e x8664,nonsfi 611 PNACL_BIN_PATH=$(PNACL_BIN_PATH) \ 612 $(LLVM_SRC_PATH)/utils/lit/lit.py -sv $(CHECK_XTEST_TESTS) 613crosstest/test_arith_ll.ll: pydir/gen_test_arith_ll.py 614 python $< > $@ 615endif 616endif 617 618check-unit: $(OBJDIR)/run_unittests 619 $(OBJDIR)/run_unittests 620 621# List the spec2k components in roughly reverse order of runtime, to help with 622# parallel execution speed. 623ALLSPEC := 253.perlbmk 177.mesa 188.ammp 256.bzip2 164.gzip 179.art 183.equake \ 624 175.vpr 176.gcc 181.mcf 186.crafty 197.parser 254.gap 255.vortex \ 625 300.twolf 252.eon 626.PHONY: $(ALLSPEC) 627 628TARGET := x8632 629ifeq ($(TARGET),x8632) 630 TARGETFLAG=x8632 631 SETUP=SetupGccX8632Opt 632 SPEC := --filetype=obj 633endif 634ifeq ($(TARGET),x8664) 635 TARGETFLAG=x8664 636 SETUP=SetupGccX8664Opt 637 SPEC := --filetype=obj 638endif 639ifeq ($(TARGET),arm32) 640 TARGETFLAG=arm32 641 SETUP=SetupGccArmOpt 642 SPEC := --filetype=obj 643endif 644ifeq ($(TARGET),mips32) 645 # native_client/tests/spec2k/{Makefile.common,run_all.sh} do not currently 646 # have MIPS configs, so those would need to be added for proper Subzero 647 # testing. 648 TARGETFLAG=mips32 649 SETUP=SetupGccMipsOpt 650 SPEC := --filetype=asm 651endif 652SPECFLAGS := -O2 653SPECRUN := --run 654%.spec2k: % $(OBJDIR)/pnacl-sz make_symlink runtime 655 ./pydir/szbuild_spec2k.py -v \ 656 $(SPECFLAGS) --target=$(TARGETFLAG) $(SPEC) $< $(SPECRUN) 657 658ifdef MIPS 659# Don't test spec2k on mips32, at least not yet. 660check-spec: 661else 662check-spec: exists-spec $(ALLSPEC:=.spec2k) 663endif 664 665check: check-lit check-unit check-xtest 666 667NONSFI_LOADER_X8632 = \ 668 $(NACL_ROOT)/scons-out/opt-linux-x86-32/obj/src/nonsfi/loader/nonsfi_loader 669NONSFI_LOADER_ARM32 = \ 670 $(NACL_ROOT)/scons-out/opt-linux-arm/obj/src/nonsfi/loader/nonsfi_loader 671SBTC_LIBFILE = $(SB_LLVM_PATH)/lib/libLLVMSupport.a 672SPEC_SAMPLE_PEXE = $(NACL_ROOT)/tests/spec2k/176.gcc/gcc.opt.stripped.pexe 673 674exists-nonsfi-x8632: 675 @if [ ! -f $(NONSFI_LOADER_X8632) ] ; then \ 676 echo "Missing file $(NONSFI_LOADER_X8632)"; \ 677 echo "Consider running './scons nonsfi_loader'" \ 678 "in the native_client directory."; \ 679 exit 1 ; \ 680 fi 681 682exists-nonsfi-arm32: 683 @if [ ! -f $(NONSFI_LOADER_ARM32) ] ; then \ 684 echo "Missing file $(NONSFI_LOADER_ARM32)"; \ 685 echo "Consider running './scons platform=arm nonsfi_loader'" \ 686 "in the native_client directory."; \ 687 exit 1 ; \ 688 fi 689 690exists-sbtc: 691 @if [ ! -f $(SBTC_LIBFILE) ] ; then \ 692 echo "Missing file $(SBTC_LIBFILE)"; \ 693 echo "Consider running 'toolchain_build_pnacl.py --build-sbtc'."; \ 694 exit 1 ; \ 695 fi 696 697exists-spec: 698 @if [ ! -f $(SPEC_SAMPLE_PEXE) ] ; then \ 699 echo "Missing file $(SPEC_SAMPLE_PEXE)"; \ 700 echo "Consider running" \ 701 "'./run_all.sh BuildBenchmarks 0 SetupPnaclX8632Opt'" \ 702 "in the native_client/tests/spec2k directory."; \ 703 exit 1 ; \ 704 fi 705 706ifdef MIPS 707check-presubmit presubmit: exists-sbtc 708# Make sure clang-format gets run. 709 +make -f Makefile.standalone format 710# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests. 711 +make -f Makefile.standalone \ 712 MINIMAL=1 check 713# Check that there are no g++ build errors or warnings. 714 +make -f Makefile.standalone \ 715 GPLUSPLUS=1 compile_only 716# Run lit tests, cross tests, and unit tests. 717 +make -f Makefile.standalone \ 718 check 719# Check a sandboxed translator build. 720 +make -f Makefile.standalone \ 721 DEBUG=1 sb 722# Provide validation of user awesomeness! 723 echo Success 724else 725check-presubmit presubmit: exists-nonsfi-x8632 exists-nonsfi-arm32 \ 726 exists-sbtc exists-spec 727# Make sure clang-format gets run. 728 +make -f Makefile.standalone format 729# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests. 730 +make -f Makefile.standalone \ 731 MINIMAL=1 check 732# Check that there are no g++ build errors or warnings. 733 +make -f Makefile.standalone \ 734 GPLUSPLUS=1 compile_only 735# Check the x86 assembler unit tests. 736 +make -f Makefile.standalone \ 737 DEBUG=1 CHECK_X86_ASM=1 check-unit sb 738# Run lit tests, cross tests, unit tests, and spec2k/x86-32. 739 +make -f Makefile.standalone \ 740 check check-spec 741# Run spec2k/x86-64. 742 +make -f Makefile.standalone \ 743 TARGET=x8664 check-spec 744# Run spec2k/x86-64 with sandboxing. 745 +make -f Makefile.standalone \ 746 SPECFLAGS='-O2 --sandbox' TARGET=x8664 check-spec 747# Build spec2k under -Om1/x86-32, to check for liveness errors. 748 +make -f Makefile.standalone \ 749 SPECFLAGS='-Om1' SPECRUN= check-spec 750# Build spec2k under -Om1/x86-64, to check for liveness errors. 751 +make -f Makefile.standalone \ 752 SPECFLAGS='-Om1' TARGET=x8664 SPECRUN= check-spec 753# Run spec2k for x86-32 without advanced phi lowering. 754 +make -f Makefile.standalone \ 755 SPECFLAGS='-O2 --sz=--phi-edge-split=0' check-spec 756# Run spec2k for x86-64 without advanced phi lowering. 757 +make -f Makefile.standalone \ 758 SPECFLAGS='-O2 --sz=--phi-edge-split=0' TARGET=x8664 check-spec 759# Run cross tests and lit tests to validate filetype=asm output. 760 +make -f Makefile.standalone \ 761 FORCEASM=1 check-xtest check-lit 762# Build spec2k for arm32. 763 +make -f Makefile.standalone \ 764 TARGET=arm32 SPECRUN= check-spec 765# Build spec2k under -Om1/arm32. 766 +make -f Makefile.standalone \ 767 TARGET=arm32 SPECFLAGS='-Om1' SPECRUN= check-spec 768# Run a few spec2k tests for arm32 using qemu. Keep the list sorted in 769# roughly reverse order of runtime. 770 +make -f Makefile.standalone \ 771 TARGET=arm32 ALLSPEC='252.eon 254.gap 176.gcc 181.mcf' check-spec 772# Provide validation of user awesomeness! 773 echo Success 774endif 775 776presubmit-lite: exists-nonsfi-x8632 exists-nonsfi-arm32 \ 777 exists-sbtc exists-spec 778# Make sure clang-format gets run. 779 +make -f Makefile.standalone format 780# Verify MINIMAL build, plus proper usage of REQUIRES in lit tests. 781 +make -f Makefile.standalone \ 782 MINIMAL=1 check sb-lite 783# Check that there are no g++ build errors or warnings. 784 +make -f Makefile.standalone \ 785 GPLUSPLUS=1 compile_only 786# Run lit tests, cross tests, unit tests, and spec2k/x86-32. 787 +make -f Makefile.standalone \ 788 check-lit check-unit check-spec 789 +make -f Makefile.standalone \ 790 check-xtest-lite 791# Run spec2k/x86-64. 792 +make -f Makefile.standalone \ 793 TARGET=x8664 check-spec 794# Build spec2k under -Om1/x86-32, to check for liveness errors. 795 +make -f Makefile.standalone \ 796 SPECFLAGS='-Om1' SPECRUN= check-spec 797# Build spec2k under -Om1/x86-64, to check for liveness errors. 798 +make -f Makefile.standalone \ 799 SPECFLAGS='-Om1' TARGET=x8664 SPECRUN= check-spec 800# Run cross tests and lit tests to validate filetype=asm output. 801 +make -f Makefile.standalone \ 802 FORCEASM=1 check-lit 803 +make -f Makefile.standalone \ 804 FORCEASM=1 check-xtest-lite 805# Build spec2k under -Om1/arm32. 806 +make -f Makefile.standalone \ 807 TARGET=arm32 SPECFLAGS='-Om1' SPECRUN= check-spec 808# Run a few spec2k tests for arm32 using qemu. Keep the list sorted in 809# roughly reverse order of runtime. 810 +make -f Makefile.standalone \ 811 TARGET=arm32 ALLSPEC='254.gap 176.gcc 181.mcf' check-spec 812# Provide validation of user awesomeness! 813 echo Success 814 815FORMAT_BLACKLIST = 816# Add one of the following lines for each source file to ignore. 817FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp 818FORMAT_BLACKLIST += ! -name IceParseTypesTest.cpp 819FORMAT_BLACKLIST += ! -name assembler_arm.h 820FORMAT_BLACKLIST += ! -name assembler_arm.cc 821FORMAT_BLACKLIST += ! -path "./wasm-install/*" 822FORMAT_BLACKLIST += ! -path "./pnacl-llvm/*" 823format: 824 $(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \ 825 `find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)` 826 827format-diff: 828 git diff -U0 `git merge-base HEAD master` | \ 829 PATH=$(PNACL_BIN_PATH):$(PATH) \ 830 $(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \ 831 -p1 -style=LLVM -i 832 833bloat: make_symlink 834 nm -C -S -l pnacl-sz | \ 835 bloat/bloat.py --nm-output=/dev/stdin syms > build/pnacl-sz.bloat.json 836 @echo See Subzero size breakdown in bloat/pnacl-sz.bloat.html 837 838bloat-sb: sb_make_symlink 839 $(foreach nexe,$(NEXES),nm -C -S -l $(nexe) | bloat/bloat.py \ 840 --nm-output=/dev/stdin syms > build/$(notdir $(nexe)).bloat.json;) 841 @echo "See Subzero size breakdown in:" 842 @$(foreach nexe,$(NEXES),echo " bloat/$(notdir $(nexe)).bloat.html";) 843 844docs: 845 make -C docs -f Makefile.standalone 846 847help: 848 @cat Makefile.standalone-help/help.txt 849 850help-check-lit: 851 @cat Makefile.standalone-help/check-lit.txt 852 853help-check-xtest: 854 @cat Makefile.standalone-help/check-xtest.txt 855 856clean: 857 rm -rf pnacl-sz *.o $(foreach nexe,$(NEXES),$(notdir $(nexe))) \ 858 $(OBJDIR) $(SB_OBJDIR) $(SBB_OBJDIR) build/*.bloat.json 859 860clean-all: clean 861 rm -rf build/ crosstest/Output/ 862