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
diff --git a/Makefile.standalone b/Makefile.standalone
index 4c369d2..b98e047 100644
--- a/Makefile.standalone
+++ b/Makefile.standalone
@@ -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 @@
# 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 @@
$(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 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_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 @@
./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 @@
./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 @@
# 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
diff --git a/crosstest/lit.cfg b/crosstest/lit.cfg
index b6a4b3b..6dad168 100644
--- a/crosstest/lit.cfg
+++ b/crosstest/lit.cfg
@@ -8,16 +8,16 @@
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))
diff --git a/pydir/run-pnacl-sz.py b/pydir/run-pnacl-sz.py
index 2c0b03c..2d86a35 100755
--- a/pydir/run-pnacl-sz.py
+++ b/pydir/run-pnacl-sz.py
@@ -40,13 +40,10 @@
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 @@
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 @@
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 @@
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 @@
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])
diff --git a/tests_lit/lit.cfg b/tests_lit/lit.cfg
index 78566c4..10d1df1 100644
--- a/tests_lit/lit.cfg
+++ b/tests_lit/lit.cfg
@@ -62,12 +62,9 @@
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 @@
# 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(('%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 @@
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)