Skip to content

Commit

Permalink
Merge pull request #325 from PRUNERS/issue308-bisect-extra-link-flags
Browse files Browse the repository at this point in the history
Issue308 bisect extra link flags
  • Loading branch information
JohnJacobsonIII authored Mar 19, 2020
2 parents c5553cc + f942256 commit a008cbc
Show file tree
Hide file tree
Showing 13 changed files with 551 additions and 187 deletions.
5 changes: 5 additions & 0 deletions data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,16 @@ R_DEP := $(R_OBJ:%.o=%.d)

recursion-target: $(R_TARGET)

# By giving "phony-%" as the value to R_TARGET, we only create the object files
ifeq ($(patsubst phony-%,phony,$(R_TARGET)),phony)
$(R_TARGET): $(R_OBJ)
else
$(R_TARGET): $(R_OBJ)
@$(call color_out,BLUE, Creating $(R_TARGET))
@+mkdir -p $(dir $@)
$(R_COMPILER) -o $@ $(R_OPTL) $(R_SWITCHES) $(R_CXXFLAGS) $(CXXFLAGS) \
$(R_OBJ) $(LDFLAGS) $(R_LDFLAGS) $(LDLIBS)
endif

$(R_OBJ_DIR):
+$(MKDIR) $@
Expand Down
61 changes: 13 additions & 48 deletions data/Makefile_bisect_binary.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ TROUBLE_CXX := {trouble_cxx}
TROUBLE_OPTL := {trouble_optl}
TROUBLE_SWITCHES := {trouble_switches}
TROUBLE_CXX_TYPE := {trouble_type}
BISECT_LINK := $(GT_CXX)
BISECT_LINK := {bisect_linker}
RM := rm -f
RMDIR := rm -rf

Expand Down Expand Up @@ -140,6 +140,7 @@ SPLIT_SRC :=

TROUBLE_CXXFLAGS := {trouble_cxxflags}
TROUBLE_LDFLAGS := {trouble_ldflags}
BISECT_LDFLAGS := {bisect_ldflags}

TROUBLE_TARGET_OUT := $(TROUBLE_TARGET:%=%-out)
TROUBLE_TARGET_RESULT := $(TROUBLE_TARGET_OUT:%=%-comparison.csv)
Expand All @@ -161,34 +162,6 @@ else
GT_TARGET_TO_USE := $(GT_TARGET)
endif

# Similar to REC_COMPILE_RULE but has an extra param
# @param 8: directory where a copy may reside. If this directory has the
# desired object file, then copy it instead of compiling one
define REC_COMPILE_OR_COPY_RULE
ifneq ($$(R_TARGET),$1)
.PHONY: $1
$1: Makefile custom.mk $$(MAKEFILE)
+$$(REC_MAKE) R_TYPE=compile-or-copy \
R_TARGET="$1" \
R_COMPILER="$2" \
R_OPTL="$3" \
R_SWITCHES="$4" \
R_CXXFLAGS="$5" \
R_LDFLAGS="$6" \
R_OBJ_DIR="$7" \
R_COPY_DIR="$8"
endif
endef

# Note: trouble-fpic is to create the fpic version of the executable
# it is used to precompile fpic object files if requested for speedier search
# This target is not reentrant, do not have multiple of them running at the
# same time
.PHONY: trouble trouble-out trouble-fpic
trouble: $(TROUBLE_TARGET)
trouble-out: $(TROUBLE_TARGET_RESULT) $(TROUBLE_TARGET_OUT)
trouble-fpic: $(TROUBLE_TARGET)-fpic

.PHONY: bisect
bisect: $(BISECT_TARGET) $(BISECT_RESULT)

Expand All @@ -199,10 +172,6 @@ bisect-smallclean:
$(RM) $(BISECT_TARGET)
$(RM) $(BISECT_OUT)
$(RM) $(addsuffix *.dat,$(BISECT_OUT))
$(RM) $(TROUBLE_TARGET)
$(RM) $(TROUBLE_TARGET)-fpic
$(RM) $(TROUBLE_TARGET_OUT)
$(RM) $(addsuffix *.dat,$(TROUBLE_TARGET_OUT))
$(RMDIR) $(SPLIT_DIR)

bisect-clean: bisect-smallclean
Expand All @@ -215,24 +184,30 @@ bisect-clean: bisect-smallclean

bisect-distclean: bisect-clean
$(RM) bisect.log
$(RM) $(TROUBLE_TARGET_RESULT)
$(RM) $(BISECT_RESULT)
$(RM) $(MAKEFILE)
$(RMDIR) $(SYMBOLS_DIR)
$(RMDIR) $(LOCAL_OBJ_DIR)
-rmdir --ignore-fail-on-non-empty $(BISECT_DIR)

.PHONY: trouble phony-trouble
trouble: phony-trouble
# Note: phony-target here causes no executable to be created
$(eval $(call REC_COMPILE_RULE,\
$(TROUBLE_TARGET),\
phony-trouble,\
$(TROUBLE_CXX),\
$(TROUBLE_OPTL),\
$(TROUBLE_SWITCHES),\
$(TROUBLE_CXXFLAGS),\
$(TROUBLE_LDFLAGS),\
$(BISECT_OBJ_DIR)))

# to create the fpic version of the object files
.PHONY: trouble-fpic phony-trouble-fpic
trouble-fpic: phony-trouble-fpic
# Note: phony-target here causes no executable to be created
$(eval $(call REC_COMPILE_RULE,\
$(TROUBLE_TARGET)-fpic,\
phony-trouble-fpic,\
$(TROUBLE_CXX),\
$(TROUBLE_OPTL),\
$(TROUBLE_SWITCHES),\
Expand Down Expand Up @@ -275,16 +250,6 @@ $(BISECT_RESULT): $(BISECT_OUT) $(GT_RESULT_TO_USE) $(GT_TARGET_TO_USE)
$(RUNWRAP) ./$(GT_TARGET_TO_USE) --compare-mode --compare-gt $(GT_RESULT_TO_USE) \
--suffix "-comparison.csv" $< -o /dev/null

$(TROUBLE_TARGET_OUT): $(TROUBLE_TARGET)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$(TROUBLE_TARGET) --output $(TROUBLE_TARGET_OUT) --no-timing \
--precision "$(PRECISION)" $(TEST_CASE)

$(TROUBLE_TARGET_RESULT): $(TROUBLE_TARGET_OUT) $(GT_RESULT_TO_USE) $(GT_TARGET_TO_USE)
@$(call color_out,CYAN, $< -> $@)
$(RUNWRAP) ./$(GT_TARGET_TO_USE) --compare-mode --compare-gt $(GT_RESULT_TO_USE) \
--suffix "-comparison.csv" $< -o /dev/null

#################################
# *** R_TYPE=bisect-compile *** #
#################################
Expand Down Expand Up @@ -313,8 +278,8 @@ recursion-target: $(BISECT_TARGET)

$(BISECT_TARGET): $(BISECT_OBJ) Makefile custom.mk | $(BISECT_DIR)
@$(call color_out,BLUE, Creating $@)
$(GT_CXX) $(CXXFLAGS) $(GT_CXXFLAGS) -o $@ $(BISECT_OBJ) $(LDFLAGS) \
$(GT_LDFLAGS) $(LDLIBS)
$(BISECT_LINK) $(CXXFLAGS) $(GT_CXXFLAGS) -o $@ $(BISECT_OBJ) $(LDFLAGS) \
$(BISECT_LDFLAGS) $(LDLIBS)

# compile BISECT_GT_OBJ
$(foreach s,$(BISECT_GT_SRC),\
Expand Down
3 changes: 2 additions & 1 deletion documentation/flit-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ Note: if the compiler given (e.g., `g++`) is found in the `compiler` section of
`flit-config.toml`, then the `fixed_compile_flags` specified there will be used
when compiling object files from this compilation under test. However, the
`fixed_link_flags` will not be used since the link step is performed by default
with the baseline compilation's compiler.
with the baseline compilation's compiler. This behavior can be overridden with
the `--ldflags`, `--use-linker`, and `--add-ldflags` options.

And here is an example of giving a full SQLite3 database

Expand Down
5 changes: 4 additions & 1 deletion scripts/bash-completion/flit
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ _flit_bisect()
--compile-only
--precompile-fpic
--skip-verification
-t --compiler-type"
-t --compiler-type
--ldflags
--add-ldflags
--use-linker"

case "${prev}" in

Expand Down
25 changes: 13 additions & 12 deletions scripts/flitcli/experimental/flit_ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,18 +671,19 @@ def main(arguments, prog=None):
args = parser.parse_args(arguments)
arguments = [x for x in arguments if x not in ('-q', '--quiet')]

if not args.quiet:
if os.path.exists(BUILD_FILENAME):
print('Updating', BUILD_FILENAME)
else:
print('Creating', BUILD_FILENAME)

with open(BUILD_FILENAME, 'w') as build_file:
writer = NinjaWriter(build_file, prog, arguments)
writer.load_project_config('flit-config.toml')
if os.path.isfile('custom.mk'):
writer.load_makefile('custom.mk')
writer.write()
with util.pushd(args.directory):
if not args.quiet:
if os.path.exists(BUILD_FILENAME):
print('Updating', BUILD_FILENAME)
else:
print('Creating', BUILD_FILENAME)

with open(BUILD_FILENAME, 'w') as build_file:
writer = NinjaWriter(build_file, prog, arguments)
writer.load_project_config('flit-config.toml')
if os.path.isfile('custom.mk'):
writer.load_makefile('custom.mk')
writer.write()

return 0

Expand Down
Loading

0 comments on commit a008cbc

Please sign in to comment.