Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue239 clang nopie #242

Merged
merged 10 commits into from
Dec 4, 2018
68 changes: 41 additions & 27 deletions data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ UNAME_S := $(shell uname -s)
CLANG := {clang_compiler}
INTEL := {intel_compiler}
GCC := {gcc_compiler}
CLANG_TYPE := clang
INTEL_TYPE := intel
GCC_TYPE := gcc

# keep only the compilers that are not None and are in the path
COMPILERS := {compilers}
Expand All @@ -102,11 +105,13 @@ FLIT_LIB_DIR := {flit_lib_dir}
FLIT_DATA_DIR := {flit_data_dir}
FLIT_SCRIPT_DIR := {flit_script_dir}

DEV_CC ?= {dev_compiler}
DEV_CXX ?= {dev_compiler}
DEV_CXX_TYPE ?= {dev_type}
DEV_OPTL ?= {dev_optl}
DEV_SWITCHES ?= {dev_switches}

GT_CC := {ground_truth_compiler}
GT_CXX := {ground_truth_compiler}
GT_CXX_TYPE := {ground_truth_type}
GT_OPTL := {ground_truth_optl}
GT_SWITCHES := {ground_truth_switches}

Expand All @@ -122,7 +127,6 @@ LD_REQUIRED :=

RUNWRAP = $(RUN_WRAPPER)
ifeq ($(ENABLE_MPI),yes) # If we are using MPI
$(info MPI is enabled)
RUNWRAP += mpirun $(MPIRUN_ARGS)
CC_REQUIRED += -DFLIT_USE_MPI
CC_REQUIRED += $(shell mpic++ --showme:compile)
Expand Down Expand Up @@ -163,11 +167,6 @@ endif
# @param 1: executable name or path to compiler
GET_COMPILER = $(shell $1 --version | head -n 1 | awk '{{ print $$1 }}')

# Returns 1 if the given compiler is GCC, else 0
# @param 1: executable name or path to compiler
IS_GCC = $(shell expr $(call GET_COMPILER,$(1)) = gcc \| \
$(call GET_COMPILER,$1) = g++)

# Returns the version of the compiler as returned by -dumpversion
# @param 1: executable name or path to compiler
GET_COMPILER_VER = $(shell $1 -dumpversion)
Expand All @@ -179,9 +178,8 @@ IS_MAJOR_VER = $(shell expr substr $(call GET_COMPILER_VER,$1) 1 1 = $2)

# Returns 1 if the compiler is GCC version 4 or version 5
# @param 1: executable name or path to compiler
IS_GCC_4_OR_5 = $(shell expr $(call IS_GCC,$1) \& \
\( $(call IS_MAJOR_VER,$1,4) \| \
$(call IS_MAJOR_VER,$1,5) \))
IS_VER_4_OR_5 = $(shell expr $(call IS_MAJOR_VER,$1,4) \| \
$(call IS_MAJOR_VER,$1,5))

DEV_LDFLAGS =
GT_LDFLAGS =
Expand Down Expand Up @@ -395,10 +393,16 @@ R_DEP := $(R_OBJ:%.o=%.d)
.PHONY: rec
rec: $(R_TARGET)

# if the current compiler is not GCC 4 or 5, then enable -no-pie
ifeq ($(call IS_GCC_4_OR_5,$($(R_CUR_COMPILER))),0)
# clang's flag is -nopie
# else if the current compiler is not GCC 4 or 5, then enable -no-pie
# GCC 4 and 5 do not need -no-pie since that is the default
ifeq ($($(R_CUR_COMPILER)_TYPE),clang)
LD_REQUIRED += -nopie
else ifeq ($($(R_CUR_COMPILER)_TYPE), gcc)
ifeq ($(call IS_VER_4_OR_5,$($(R_CUR_COMPILER))),0)
LD_REQUIRED += -no-pie
endif
endif

$(R_TARGET): $(R_OBJ)
$($(R_CUR_COMPILER)) $($(R_CUR_OPTL)) $($(R_CUR_SWITCHES)) \
Expand All @@ -420,15 +424,25 @@ $(OBJ_DIR)/%_$(R_ID).o: %.cpp Makefile custom.mk | $(OBJ_DIR)
# Otherwise, we're not in a recursion.
else # ifndef R_IS_RECURSED

# if the dev compiler is not an old version of GCC
ifeq ($(call IS_GCC_4_OR_5,$(DEV_CC)),0)
# clang's flag is -nopie
# else if the current compiler is not GCC 4 or 5, then enable -no-pie
# GCC 4 and 5 do not need -no-pie since that is the default
ifeq ($(DEV_CXX_TYPE),clang)
DEV_LDFLAGS += -nopie
else ifeq ($(DEV_CXX_TYPE), gcc)
ifeq ($(call IS_VER_4_OR_5,$(DEV_CXX)),0)
DEV_LDFLAGS += -no-pie
endif
endif

# if the gt compiler is not an old version of GCC
ifeq ($(call IS_GCC_4_OR_5,$(GT_CC)),0)
# same for the gt compiler
ifeq ($(GT_CXX_TYPE),clang)
GT_LDFLAGS += -nopie
else ifeq ($(GT_CXX_TYPE), gcc)
ifeq ($(call IS_VER_4_OR_5,$(GT_CXX)),0)
GT_LDFLAGS += -no-pie
endif
endif

$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
Expand All @@ -441,13 +455,13 @@ $(RESULTS_DIR):

# Set these as empty "simply-expanded variables". This affects the "+=" operator.
# see https://ftp.gnu.org/old-gnu/Manuals/make-3.79.1/html_chapter/make_6.html
TARGET_OUTS :=
TARGET_OUTS :=

# @param 1: compiler variable name (e.g. CLANG)
# @param 2: optimization level variable name (e.g. O2)
# @param 3: switches variable name (e.g. USEFASTM)
define RECURSION_RULE
TARGETS += $$(RESULTS_DIR)/$(strip $1)_$$(HOSTNAME)_$(strip $3)_$(strip $2)
TARGETS += $$(RESULTS_DIR)/$(strip $1)_$$(HOSTNAME)_$(strip $3)_$(strip $2)

# TODO: use the variable $$(MAKECMDGOALS) to get the original make target
# TODO- or see if it is even necessary
Expand Down Expand Up @@ -560,13 +574,13 @@ endif # ifeq ($(UNAME_S),Darwin): meaning, we are on a mac

# Dev compilation rules first (easier to understand)
$(DEV_TARGET): $(DEV_OBJ) Makefile custom.mk
$(DEV_CC) $(CC_REQUIRED) $(DEV_CFLAGS) \
$(DEV_CXX) $(CC_REQUIRED) $(DEV_CFLAGS) \
-o $@ $(DEV_OBJ) $(LD_REQUIRED) $(DEV_LDFLAGS)

$(OBJ_DIR)/%_dev.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(DEV_CC) $(DEV_OPTL) $(DEV_SWITCHES) $(CC_REQUIRED) $(DEV_CFLAGS) $(DEPFLAGS) -c $< -o $@ \
$(DEV_CXX) $(DEV_OPTL) $(DEV_SWITCHES) $(CC_REQUIRED) $(DEV_CFLAGS) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(DEV_CC)"' \
-DFLIT_COMPILER='"$(DEV_CXX)"' \
-DFLIT_OPTL='"$(DEV_OPTL)"' \
-DFLIT_SWITCHES='"$(DEV_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(DEV_TARGET))"'
Expand All @@ -576,20 +590,20 @@ $(GT_OUT): $(GT_TARGET)
$(RUNWRAP) ./$(GT_TARGET) --output $(GT_OUT) --no-timing

$(GT_TARGET): $(GT_OBJ) Makefile custom.mk
$(GT_CC) $(CC_REQUIRED) -o $@ $(GT_OBJ) $(LD_REQUIRED) $(GT_LDFLAGS)
$(GT_CXX) $(CC_REQUIRED) -o $@ $(GT_OBJ) $(LD_REQUIRED) $(GT_LDFLAGS)

$(OBJ_DIR)/%_gt.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(GT_CC) -g $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -c $< -o $@ \
$(GT_CXX) -g $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CC)"' \
-DFLIT_COMPILER='"$(GT_CXX)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'

$(OBJ_DIR)/%_gt_fPIC.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(GT_CC) -g $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
$(GT_CXX) -g $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CC)"' \
-DFLIT_COMPILER='"$(GT_CXX)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'
Expand Down
28 changes: 14 additions & 14 deletions data/Makefile_bisect_binary.in
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@
PRECISION := {precision}
TEST_CASE := {test_case}

TROUBLE_CC := {trouble_cc}
TROUBLE_CXX := {trouble_cc}
TROUBLE_OPTL := {trouble_optl}
TROUBLE_SWITCHES := {trouble_switches}
BISECT_LINK := $(GT_CC)
BISECT_LINK := $(GT_CXX)

TROUBLE_ID := {trouble_id}

Expand All @@ -127,7 +127,7 @@ SPLIT_SRC :=
TROUBLE_LDFLAGS =

# if the trouble compiler is not GCC 4 or 5, then add -no-pie
ifeq ($(call IS_GCC_4_OR_5,$(TROUBLE_CC)),0)
ifeq ($(call IS_GCC_4_OR_5,$(TROUBLE_CXX)),0)
TROUBLE_LDFLAGS += -no-pie
endif

Expand Down Expand Up @@ -194,7 +194,7 @@ $(GT_LIB_OUT): $(GT_LIB_TARGET)
$(RUNWRAP) ./$(GT_LIB_TARGET) --output $(GT_LIB_OUT) --no-timing --precision "$(PRECISION)" $(TEST_CASE)

$(GT_LIB_TARGET): $(GT_OBJ) Makefile custom.mk $(MAKEFILE)
$(GT_CC) $(CC_REQUIRED) -o $@ $(GT_OBJ) $(LD_REQUIRED)
$(GT_CXX) $(CC_REQUIRED) -o $@ $(GT_OBJ) $(LD_REQUIRED)

$(BISECT_RESULT): $(BISECT_OUT) $(GT_LIB_OUT) $(GT_LIB_TARGET)
$(RUNWRAP) ./$(GT_LIB_TARGET) --compare-mode --compare-gt $(GT_LIB_OUT) --suffix "-comparison.csv" $< -o /dev/null
Expand All @@ -212,10 +212,10 @@ $(TROUBLE_TARGET_OUT): $(TROUBLE_TARGET) | $(BISECT_DIR)
$(RUNWRAP) ./$< --precision "$(PRECISION)" --output $@ $(TEST_CASE) --no-timing

$(BISECT_TARGET): $(BISECT_OBJ) $(SPLIT_OBJ) Makefile custom.mk | $(BISECT_DIR)
$(GT_CC) $(CC_REQUIRED) -o $@ $(BISECT_OBJ) $(SPLIT_OBJ) $(LD_REQUIRED) $(GT_LDFLAGS)
$(GT_CXX) $(CC_REQUIRED) -o $@ $(BISECT_OBJ) $(SPLIT_OBJ) $(LD_REQUIRED) $(GT_LDFLAGS)

$(TROUBLE_TARGET): $(TROUBLE_TARGET_OBJ) Makefile custom.mk | $(BISECT_DIR)
$(TROUBLE_CC) $(CC_REQUIRED) -o $@ $(TROUBLE_TARGET_OBJ) $(LD_REQUIRED) $(TROUBLE_LDFLAGS)
$(TROUBLE_CXX) $(CC_REQUIRED) -o $@ $(TROUBLE_TARGET_OBJ) $(LD_REQUIRED) $(TROUBLE_LDFLAGS)

.PHONY: trouble trouble-out trouble-fpic
trouble: $(TROUBLE_TARGET)
Expand Down Expand Up @@ -270,9 +270,9 @@ $(BISECT_OBJ_DIR)/%_gt_fPIC.o: %.cpp Makefile custom.mk | $(BISECT_OBJ_DIR)
if [ -f "$(OBJ_DIR)/$*_gt_fPIC.o" ]; then \
ln -s "../../$(OBJ_DIR)/$*_gt_fPIC.o" "$@"; \
else \
$(GT_CC) $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
$(GT_CXX) $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CC)"' \
-DFLIT_COMPILER='"$(GT_CXX)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'; \
Expand All @@ -281,9 +281,9 @@ $(BISECT_OBJ_DIR)/%_gt_fPIC.o: %.cpp Makefile custom.mk | $(BISECT_OBJ_DIR)

# specify how to build the troublesome ones
$(OBJ_DIR)/%_bisect_$(TROUBLE_ID).o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(TROUBLE_CC) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -c $< -o $@ \
$(TROUBLE_CXX) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(TROUBLE_CC)"' \
-DFLIT_COMPILER='"$(TROUBLE_CXX)"' \
-DFLIT_OPTL='"$(TROUBLE_OPTL)"' \
-DFLIT_SWITCHES='"$(TROUBLE_SWITCHES)"' \
-DFLIT_FILENAME='"bisect-default-out"'
Expand All @@ -293,19 +293,19 @@ $(BISECT_OBJ_DIR)/%_bisect_$(TROUBLE_ID)_fPIC.o: %.cpp Makefile custom.mk | $(BI
if [ -f "$(OBJ_DIR)/$*_bisect_$(TROUBLE_ID)_fPIC.o" ]; then \
ln -s "../../$(OBJ_DIR)/$*_bisect_$(TROUBLE_ID)_fPIC.o" "$@"; \
else \
$(TROUBLE_CC) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
$(TROUBLE_CXX) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(TROUBLE_CC)"' \
-DFLIT_COMPILER='"$(TROUBLE_CXX)"' \
-DFLIT_OPTL='"$(TROUBLE_OPTL)"' \
-DFLIT_SWITCHES='"$(TROUBLE_SWITCHES)"' \
-DFLIT_FILENAME='"bisect-default-out"'; \
fi

# and the fPIC variant
$(OBJ_DIR)/%_bisect_$(TROUBLE_ID)_fPIC.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(TROUBLE_CC) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
$(TROUBLE_CXX) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(TROUBLE_CC)"' \
-DFLIT_COMPILER='"$(TROUBLE_CXX)"' \
-DFLIT_OPTL='"$(TROUBLE_OPTL)"' \
-DFLIT_SWITCHES='"$(TROUBLE_SWITCHES)"' \
-DFLIT_FILENAME='"bisect-default-out"'
Expand Down
42 changes: 41 additions & 1 deletion documentation/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Instruction Contents:

* [Prerequisites](#prerequisites)
* [Compilers](#compilers)
* [Clang Only](#clang-only)
* [Optional Dependencies](#optional-dependencies)
* [FLiT Setup](#flit-setup)
* [Database Setup](#database-setup)
Expand All @@ -32,7 +33,8 @@ Stuff you may need to get
parsing ELF files. This is used for `flit bisect`; all other functionality
will work without it.
* [make](https://www.gnu.org/software/make)
* [gcc](https://gcc.gnu.org) version 4.9 or higher
* [gcc](https://gcc.gnu.org) version 4.9 or higher (or
[clang](https://clang.llvm.org), see section [Clang Only](#clang-only))
* [sqlite3](https://sqlite.org) version 3.0 or higher.
You can use the one that comes with python, or install as a standalone.

Expand Down Expand Up @@ -76,6 +78,44 @@ install another version of GCC, as well as Clang and the Intel compiler. If
you are missing either Clang or the Intel compiler, FLiT will still work as
expected.

The supported compiler versions are:

| Compiler Type | Minimum Supported Version |
|:-------------:|:-------------------------:|
| gcc | 4.9.0 |
| clang | 3.4.0 |
| intel | 16.0 |

If your compiler version is below those on this list and you want FLiT to
support it, please create an [issue](https://github.com/PRUNERS/FLiT/issues)
and we may be able to add support for you. Otherwise, you are on your own.

Likewise, if you want support added for other types of compilers, such as the
PGI compiler or the IBM compiler, please create an
[issue](https://github.com/PRUNERS/FLiT/issues).


### Clang Only

FLiT is mostly geared around having at least GCC around, however, users may
want to skip using GCC and use Clang instead. If this is your use case, this
can be done.

To compile FLiT using Clang, set the `CXX` environment variable to the
executable for Clang you wish to use. For example:

```bash
git clone https://github.com/PRUNERS/FLiT.git
cd FLiT
export CXX=clang
make
sudo make install
```

Then when creating your environment, simply provide only a Clang compiler.
This setup is largely untested, so if you have trouble, please submit an
[issue](https://github.com/PRUNERS/FLiT/issues).

### Optional Dependencies

FLiT has [MPI support](mpi-support.md) which you may want to use. To compile
Expand Down
4 changes: 4 additions & 0 deletions scripts/flitcli/flit_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def main(arguments, prog=sys.argv[0]):
assert len(matching_dev_compilers) < 2, \
'Multiple compilers with name {0} found'.format(dev_compiler_name)
dev_compiler_bin = matching_dev_compilers[0]['binary']
dev_compiler_type = matching_dev_compilers[0]['type']
#if '/' in dev_compiler_bin:
# dev_compiler_bin = os.path.realpath(dev_compiler_bin)

Expand All @@ -150,6 +151,7 @@ def main(arguments, prog=sys.argv[0]):
'Multiple compilers with name {0} found'.format(gt_compiler_name)
# TODO: use the compiler mnemonic rather than the path
gt_compiler_bin = matching_gt_compilers[0]['binary']
gt_compiler_type = matching_gt_compilers[0]['type']
#if '/' in dev_compiler_bin:
# gt_compiler_bin = os.path.realpath(gt_compiler_bin)

Expand All @@ -175,9 +177,11 @@ def main(arguments, prog=sys.argv[0]):
if val is not None]
replacements = {
'dev_compiler': dev_compiler_bin,
'dev_type': dev_compiler_type,
'dev_optl': dev_optl,
'dev_switches': dev_switches,
'ground_truth_compiler': gt_compiler_bin,
'ground_truth_type': gt_compiler_type,
'ground_truth_optl': gt_optl,
'ground_truth_switches': gt_switches,
'flit_include_dir': conf.include_dir,
Expand Down
18 changes: 11 additions & 7 deletions tests/flit_cli/flit_bisect/tst_bisect.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,24 @@
>>> with th.tempdir() as temp_dir:
... with StringIO() as ostream:
... retval = th.flit.main(['init', '-C', temp_dir], outstream=ostream)
... if retval != 0:
... raise BisectTestError(
... 'Could not initialize (retval={0}):\\n'.format(retval) +
... ostream.getvalue())
... init_out = ostream.getvalue().splitlines()
... if retval != 0:
... raise BisectTestError('Main #1 returned {}'.format(retval))
... shutil.rmtree(os.path.join(temp_dir, 'tests'))
... _ = shutil.copytree(os.path.join('data', 'tests'),
... os.path.join(temp_dir, 'tests'))
... with StringIO() as ostream:
... retval = th.flit.main(['bisect', '-C', temp_dir,
... '--precision', 'double',
... 'g++ -O3', 'BisectTest'],
... outstream=ostream)
... '--precision', 'double',
... 'g++ -O3', 'BisectTest'],
... outstream=ostream)
... if retval != 0:
... raise BisectTestError(
... 'Could not bisect (retval={0}):\\n'.format(retval) +
... ostream.getvalue())
... bisect_out = ostream.getvalue().splitlines()
... if retval != 0:
... raise BisectTestError('Main #2 returned {}'.format(retval))
... with open(os.path.join(temp_dir, 'bisect-01', 'bisect.log')) as fin:
... raw_log = fin.readlines()
... stripped_log = [line[line.index(' bisect:')+8:].rstrip()
Expand Down
Loading