OSDN Git Service

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