Commit 0a9e1261 by Jim Stichnoth

Subzero: Auto-detect cmake versus autoconf LLVM build.

The CMAKE=1 option is no longer needed. Pretty much all the tools we need are now in pnacl_newlib_raw/bin, so use PNACL_BIN_PATH set to that instead of using LLVM_BIN_PATH and BINUTILS_BIN_PATH. However, for the autoconf build, libgtest and libtest_main and clang-format are only under the llvm_x86_64_linux_work directory, so they need special casing. This also means that you have to actually do an LLVM build and not blow away the work directory in order to "make check-unit" or "make format". BUG= none R=jvoung@chromium.org Review URL: https://codereview.chromium.org/1085733002
parent d8b32896
......@@ -2,8 +2,7 @@
# and how you built LLVM & Clang. They can be overridden in a command-line
# invocation of make, like:
#
# make LLVM_SRC_PATH=<path> LLVM_BIN_PATH=<path> \
# LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \
# make LLVM_SRC_PATH=<path> LIBCXX_INSTALL_PATH=<path> CLANG_PATH=<path> \
# PNACL_BIN_PATH=<path> ...
#
......@@ -14,17 +13,6 @@
# LLVM_SRC_PATH can point to the main untarred directory.
LLVM_SRC_PATH ?= ../llvm
# LLVM_BIN_PATH is the directory where binaries are placed by the LLVM build
# process. It should contain the tools like clang, clang-format, llc,
# llvm-as, llvm-config, llvm-mc, pnacl-bcdis, and pnacl-freeze.
ifdef CMAKE
# LLVM cmake build
LLVM_BIN_PATH ?= ../../out/llvm_x86_64_linux_work/bin
else
# LLVM autoconf build
LLVM_BIN_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
endif
# The x86-32-specific sandboxed translator directory.
# It holds sandboxed versions of libraries and binaries.
SB_LLVM_PATH ?= $(shell readlink -e \
......@@ -37,11 +25,17 @@ NACL_ROOT ?= $(shell python -c "import sys; sys.path.insert(0, 'pydir'); \
# PNACL_TOOLCHAIN_ROOT is the location of the PNaCl toolchain.
# This is used as the default root for finding binutils, libcxx, etc.
PNACL_TOOLCHAIN_ROOT ?= $(shell readlink -e \
$(NACL_ROOT)/toolchain/linux_x86/pnacl_newlib)
$(NACL_ROOT)/toolchain/linux_x86/pnacl_newlib_raw)
# The location of PNaCl tools (e.g., binutils objdump, pnacl-clang++, etc.).
PNACL_BIN_PATH ?= $(shell readlink -e $(PNACL_TOOLCHAIN_ROOT)/bin)
# Hack to auto-detect autoconf versus cmake build of LLVM. If the LLVM tools
# were dynamically linked with something like libLLVM-3.6svn.so, it is an
# autoconf build, otherwise it is a cmake build. AUTOCONF is set to 0 for
# cmake, nonzero for autoconf.
AUTOCONF ?= $(shell ldd $(PNACL_BIN_PATH)/opt | grep -c libLLVM-)
# CLANG_PATH is the location of the clang compiler to use for building
# the host binaries.
CLANG_PATH ?= $(shell readlink -e \
......@@ -109,7 +103,6 @@ SB_OBJDIR := $(OBJDIR)+Sandboxed
$(info -----------------------------------------------)
$(info Using LLVM_SRC_PATH = $(LLVM_SRC_PATH))
$(info Using LLVM_BIN_PATH = $(LLVM_BIN_PATH))
$(info Using SB_LLVM_PATH = $(SB_LLVM_PATH))
$(info Using NACL_ROOT = $(NACL_ROOT))
$(info Using PNACL_TOOLCHAIN_ROOT = $(PNACL_TOOLCHAIN_ROOT))
......@@ -119,20 +112,36 @@ $(info Using LIBCXX_INSTALL_PATH = $(LIBCXX_INSTALL_PATH))
$(info Using HOST_ARCH = $(HOST_ARCH))
$(info -----------------------------------------------)
LLVM_CXXFLAGS := `$(LLVM_BIN_PATH)/llvm-config --cxxflags`
LLVM_CXXFLAGS := `$(PNACL_BIN_PATH)/llvm-config --cxxflags`
SB_LLVM_CXXFLAGS := $(LLVM_CXXFLAGS)
# Listing specific libraries that are needed for pnacl-sz
# and the unittests, since we build "tools-only" for the
# sandboxed_translators (which doesn't include every library
# listed by llvm-config).
LLVM_LIBS := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
-lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
-lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
LLVM_LIBS_LIST := -lLLVMIRReader -lLLVMBitReader -lLLVMNaClBitTestUtils \
-lLLVMNaClBitReader -lLLVMNaClBitAnalysis -lLLVMNaClBitWriter \
-lLLVMAsmParser -lLLVMNaClAnalysis -lLLVMCore -lLLVMSupport
ifeq ($(AUTOCONF), 0)
# LLVM cmake build
LLVM_LIBS := $(LLVM_LIBS_LIST)
# For the cmake build, the gtest libs end up in the same place as the LLVM
# libs, so no "-L..." arg is needed.
GTEST_LIB_PATH ?=
CLANG_FORMAT_PATH ?= $(PNACL_BIN_PATH)
else
# LLVM autoconf build
LLVM_LIBS := -lLLVM-3.6svn
GTEST_LIB_PATH ?= -L../../out/llvm_x86_64_linux_work/Release+Asserts/lib
CLANG_FORMAT_PATH ?= ../../out/llvm_x86_64_linux_work/Release+Asserts/bin
endif
LLVM_LDFLAGS := $(LLVM_LIBS) \
`$(LLVM_BIN_PATH)/llvm-config --ldflags` \
`$(LLVM_BIN_PATH)/llvm-config --system-libs`
SB_LLVM_LDFLAGS := $(LLVM_LIBS) \
`$(PNACL_BIN_PATH)/llvm-config --ldflags` \
`$(PNACL_BIN_PATH)/llvm-config --system-libs`
SB_LLVM_LDFLAGS := $(LLVM_LIBS_LIST) \
-L$(SB_LLVM_PATH)/lib
CCACHE := `command -v ccache`
......@@ -239,7 +248,8 @@ $(SB_OBJS): $(SB_OBJDIR)/%.o: src/%.cpp src/*.h src/*.def
$(SB_CXX) -c $(SB_CXXFLAGS) $< -o $@
$(OBJDIR)/run_unittests: $(UNITTEST_OBJS) $(UNITTEST_LIB_OBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) -lgtest -lgtest_main -ldl \
$(CXX) $(LDFLAGS) -o $@ $^ $(LLVM_LDFLAGS) \
$(GTEST_LIB_PATH) -lgtest -lgtest_main -ldl \
-Wl,-rpath=$(abspath $(LIBCXX_INSTALL_PATH)/lib)
$(UNITTEST_OBJS): $(OBJDIR)/unittest/%.o: unittest/%.cpp \
......@@ -277,8 +287,7 @@ runtime.is.built: $(RT_SRC)
./pydir/build-runtime.py -v --pnacl-root $(PNACL_TOOLCHAIN_ROOT)
check-lit: $(OBJDIR)/pnacl-sz make_symlink
LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
BINUTILS_BIN_PATH=$(PNACL_BIN_PATH) \
PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv tests_lit
ifdef MINIMAL
......@@ -291,7 +300,7 @@ check-xtest: $(OBJDIR)/pnacl-sz make_symlink runtime
./pydir/crosstest_generator.py -v --lit \
-i native,sse2 -i native,sse4.1,test_vector_ops \
-i sandbox,sse4.1,Om1
LLVM_BIN_PATH=$(LLVM_BIN_PATH) \
PNACL_BIN_PATH=$(PNACL_BIN_PATH) \
$(LLVM_SRC_PATH)/utils/lit/lit.py -sv crosstest/Output
endif
......@@ -304,12 +313,12 @@ FORMAT_BLACKLIST =
# Add one of the following lines for each source file to ignore.
FORMAT_BLACKLIST += ! -name IceParseInstsTest.cpp
format:
$(LLVM_BIN_PATH)/clang-format -style=LLVM -i \
$(CLANG_FORMAT_PATH)/clang-format -style=LLVM -i \
`find . -regex '.*\.\(c\|h\|cpp\)' $(FORMAT_BLACKLIST)`
format-diff:
git diff -U0 `git merge-base HEAD master` | \
PATH=$(LLVM_BIN_PATH):$(PATH) \
PATH=$(PNACL_BIN_PATH):$(PATH) \
$(LLVM_SRC_PATH)/../clang/tools/clang-format/clang-format-diff.py \
-p1 -style=LLVM -i
......
......@@ -8,16 +8,16 @@ config.suffixes = ['.xtest']
config.test_source_root = os.path.dirname(__file__)
config.test_exec_root = config.test_source_root
llvmbintools = [r"\bFileCheck\b"]
llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH'))
pnaclbintools = [r"\bFileCheck\b"]
pnaclbinpath = os.path.abspath(os.environ.get('PNACL_BIN_PATH'))
for tool in llvmbintools:
for tool in pnaclbintools:
# The re.sub() line is adapted from one of LLVM's lit.cfg files.
# Extract the tool name from the pattern. This relies on the tool
# name being surrounded by \b word match operators. If the
# pattern starts with "| ", include it in the string to be
# substituted.
substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
r"\2" + llvmbinpath + "/" + r"\4",
r"\2" + pnaclbinpath + "/" + r"\4",
tool)
config.substitutions.append((tool, substitution))
......@@ -40,13 +40,10 @@ def main():
argparser.add_argument(
'--pnacl-sz', required=False, default='./pnacl-sz', metavar='PNACL-SZ',
help="Subzero translator 'pnacl-sz'")
argparser.add_argument('--llvm-bin-path', required=False,
default=None, metavar='LLVM_BIN_PATH',
help='Path to LLVM executables ' +
'(for building PEXE files)')
argparser.add_argument('--binutils-bin-path', required=False,
default=None, metavar='BINUTILS_BIN_PATH',
help='Path to Binutils executables')
argparser.add_argument('--pnacl-bin-path', required=False,
default=None, metavar='PNACL_BIN_PATH',
help='Path to LLVM & Binutils executables ' +
'(e.g. for building PEXE files)')
argparser.add_argument('--assemble', required=False,
action='store_true',
help='Assemble the output')
......@@ -67,8 +64,7 @@ def main():
help='Remaining arguments are passed to pnacl-sz')
args = argparser.parse_args()
llvm_bin_path = args.llvm_bin_path
binutils_bin_path = args.binutils_bin_path
pnacl_bin_path = args.pnacl_bin_path
llfile = args.input
if args.llvm and args.llvm_source:
......@@ -80,8 +76,8 @@ def main():
cmd = []
if not args.llvm_source:
cmd = [os.path.join(llvm_bin_path, 'llvm-as'), llfile, '-o', '-', '|',
os.path.join(llvm_bin_path, 'pnacl-freeze')]
cmd = [os.path.join(pnacl_bin_path, 'llvm-as'), llfile, '-o', '-', '|',
os.path.join(pnacl_bin_path, 'pnacl-freeze')]
if not args.no_local_syms:
cmd += ['--allow-local-symbol-tables']
cmd += ['|']
......@@ -111,7 +107,7 @@ def main():
asm_temp = tempfile.NamedTemporaryFile(delete=False)
asm_temp.close()
if args.assemble and args.filetype != 'obj':
cmd += ['|', os.path.join(llvm_bin_path, 'llvm-mc'),
cmd += ['|', os.path.join(pnacl_bin_path, 'llvm-mc'),
# TODO(stichnot): -triple=i686-nacl should be used for a
# sandboxing test. This means there should be an args.sandbox
# argument that also gets passed through to pnacl-sz.
......@@ -121,7 +117,7 @@ def main():
cmd += ['-o', asm_temp.name]
if args.disassemble:
# Show wide instruction encodings, diassemble, and show relocs.
cmd += (['&&', os.path.join(binutils_bin_path, 'le32-nacl-objdump')] +
cmd += (['&&', os.path.join(pnacl_bin_path, 'le32-nacl-objdump')] +
args.dis_flags +
['-w', '-d', '-r', '-Mintel', asm_temp.name])
......
......@@ -62,12 +62,9 @@ config.substitutions.append(('%{python}', sys.executable))
pydir = os.path.join(bin_root, 'pydir')
# Finding LLVM binary tools. Tools used in the tests must be listed in
# the llvmbintools list or binutilsbintools.
llvmbinpath = os.path.abspath(os.environ.get('LLVM_BIN_PATH'))
# Find binutils tools. This is used for objdump.
binutilsbinpath = os.path.abspath(os.environ.get('BINUTILS_BIN_PATH'))
# Finding PNaCl binary tools. Tools used in the tests must be listed in the
# pnaclbintools list.
pnaclbinpath = os.path.abspath(os.environ.get('PNACL_BIN_PATH'))
# Define the location of the pnacl-sz tool.
pnacl_sz_tool = os.path.join(bin_root, 'pnacl-sz')
......@@ -91,8 +88,7 @@ iflc2i_atts_cmd = if_atts + [if_cond_flag('allow_llvm_ir_as_input'
# Base command for running pnacl-sz
pnacl_sz_cmd = [os.path.join(pydir, 'run-pnacl-sz.py'),
'--pnacl-sz', pnacl_sz_tool,
'--llvm-bin-path', llvmbinpath,
'--binutils-bin-path', binutilsbinpath]
'--pnacl-bin-path', pnaclbinpath]
# Run commands only if corresponding build attributes apply, including
# for each compiler setup.
......@@ -110,32 +106,23 @@ config.substitutions.append(('%lc2i', ' '.join(iflc2i_atts_cmd + pnacl_sz_cmd
config.substitutions.append(('%pnacl_sz', pnacl_sz_tool))
llvmbintools = [r"\bFileCheck\b",
r"\bllvm-as\b",
r"\bllvm-mc\b",
r"\bllvm-readobj\b",
r"\bnot\b",
r"\bpnacl-freeze\b",
r"\bpnacl-bcdis\b"]
pnaclbintools = [r"\bFileCheck\b",
r"\ble32-nacl-objdump\b",
r"\bllvm-as\b",
r"\bllvm-mc\b",
r"\bllvm-readobj\b",
r"\bnot\b",
r"\bpnacl-freeze\b",
r"\bpnacl-bcdis\b"]
for tool in llvmbintools:
for tool in pnaclbintools:
# The re.sub() line is adapted from one of LLVM's lit.cfg files.
# Extract the tool name from the pattern. This relies on the tool
# name being surrounded by \b word match operators. If the
# pattern starts with "| ", include it in the string to be
# substituted.
substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
r"\2" + llvmbinpath + "/" + r"\4",
tool)
config.substitutions.append((tool, substitution))
binutilsbintools = [r"\ble32-nacl-objdump\b",]
for tool in binutilsbintools:
# The re.sub() line is adapted from one of LLVM's lit.cfg files.
# Similar to the llvmbintools.
substitution = re.sub(r"^(\\)?((\| )?)\W+b([0-9A-Za-z-_]+)\\b\W*$",
r"\2" + binutilsbinpath + "/" + r"\4",
r"\2" + pnaclbinpath + "/" + r"\4",
tool)
config.substitutions.append((tool, substitution))
......@@ -148,6 +135,5 @@ def dbg(s):
print '[DBG] %s' % s
dbg('bin_root = %s' % bin_root)
dbg('llvmbinpath = %s' % llvmbinpath)
dbg('binutilsbinpath = %s' % binutilsbinpath)
dbg('pnaclbinpath = %s' % pnaclbinpath)
dbg("Build attributes = %s" % pnacl_sz_atts)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment