4
4
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
# SPDX-License-Identifier: MIT-0
6
6
7
- CBMC_STARTER_KIT_VERSION = CBMC starter kit 2.4
7
+ CBMC_STARTER_KIT_VERSION = CBMC starter kit 2.5
8
8
9
9
# ###############################################################
10
10
# The CBMC Starter Kit depends on the files Makefile.common and
@@ -309,6 +309,7 @@ NONDET_STATIC ?=
309
309
# Flags to pass to goto-cc for compilation and linking
310
310
COMPILE_FLAGS ?= -Wall
311
311
LINK_FLAGS ?= -Wall
312
+ EXPORT_FILE_LOCAL_SYMBOLS ?= --export-file-local-symbols
312
313
313
314
# Preprocessor include paths -I...
314
315
INCLUDES ?=
@@ -439,6 +440,7 @@ CBMC ?= cbmc
439
440
GOTO_ANALYZER ?= goto-analyzer
440
441
GOTO_CC ?= goto-cc
441
442
GOTO_INSTRUMENT ?= goto-instrument
443
+ CRANGLER ?= crangler
442
444
VIEWER ?= cbmc-viewer
443
445
MAKE_SOURCE ?= make-source
444
446
VIEWER2 ?= cbmc-viewer
@@ -484,14 +486,92 @@ endif
484
486
CBMC_REMOVE_FUNCTION_BODY := $(patsubst % ,--remove-function-body % , $(REMOVE_FUNCTION_BODY ) )
485
487
CBMC_RESTRICT_FUNCTION_POINTER := $(patsubst % ,--restrict-function-pointer % , $(RESTRICT_FUNCTION_POINTER ) )
486
488
489
+ # ###############################################################
490
+ # Targets for rewriting source files with crangler
491
+
492
+ # Construct crangler configuration files
493
+ #
494
+ # REWRITTEN_SOURCES is a list of crangler output files source.i.
495
+ # This target assumes that for each source.i
496
+ # * source.i_SOURCE is the path to a source file,
497
+ # * source.i_FUNCTIONS is a list of functions (may be empty)
498
+ # * source.i_OBJECTS is a list of variables (may be empty)
499
+ # This target constructs the crangler configuration file source.i.json
500
+ # of the form
501
+ # {
502
+ # "sources": [ "/proj/code.c" ],
503
+ # "includes": [ "/proj/include" ],
504
+ # "defines": [ "VAR=1" ],
505
+ # "functions": [ {"function_name": ["remove static"]} ],
506
+ # "objects": [ {"variable_name": ["remove static"]} ],
507
+ # "output": "source.i"
508
+ # }
509
+ # to remove the static attribute from function_name and variable_name
510
+ # in the source file source.c and write the result to source.i.
511
+ #
512
+ # This target assumes that filenames include no spaces and that
513
+ # the INCLUDES and DEFINES variables include no spaces after -I
514
+ # and -D. For example, use "-DVAR=1" and not "-D VAR=1".
515
+ #
516
+ # Define *_SOURCE, *_FUNCTIONS, and *_OBJECTS in the proof Makefile.
517
+ # The string source.i is usually an absolute path $(PROOFDIR)/code.i
518
+ # to a file in the proof directory that contains the proof Makefile.
519
+ # The proof Makefile usually includes the definitions
520
+ # $(PROOFDIR)/code.i_SOURCE = /proj/code.c
521
+ # $(PROOFDIR)/code.i_FUNCTIONS = function_name
522
+ # $(PROOFDIR)/code.i_OBJECTS = variable_name
523
+ # Because these definitions refer to PROOFDIR that is defined in this
524
+ # Makefile.common, these definitions must appear after the inclusion
525
+ # of Makefile.common in the proof Makefile.
526
+ #
527
+ $(foreach rs,$(REWRITTEN_SOURCES ) ,$(eval $(rs ) .json : $($(rs ) _SOURCE) ))
528
+ $(foreach rs,$(REWRITTEN_SOURCES ) ,$(rs ) .json) :
529
+ echo ' {' \
530
+ ' "sources": [' \
531
+ ' "$($(@:.json=)_SOURCE)"' \
532
+ ' ],' \
533
+ ' "includes": [' \
534
+ ' $(subst $(SPACE),$(COMMA),$(patsubst -I%,"%",$(strip $(INCLUDES))))' \
535
+ ' ],' \
536
+ ' "defines": [' \
537
+ ' $(subst $(SPACE),$(COMMA),$(patsubst -D%,"%",$(subst ",\",$(strip $(DEFINES)))))' \
538
+ ' ],' \
539
+ ' "functions": [' \
540
+ ' {' \
541
+ ' $(subst ~, ,$(subst $(SPACE),$(COMMA),$(patsubst %,"%":["remove~static"],$($(@:.json=)_FUNCTIONS))))' \
542
+ ' }' \
543
+ ' ],' \
544
+ ' "objects": [' \
545
+ ' {' \
546
+ ' $(subst ~, ,$(subst $(SPACE),$(COMMA),$(patsubst %,"%":["remove~static"],$($(@:.json=)_OBJECTS))))' \
547
+ ' }' \
548
+ ' ],' \
549
+ ' "output": "$(@:.json=)"' \
550
+ ' }' > $@
551
+
552
+ # Rewrite source files with crangler
553
+ #
554
+ $(foreach rs,$(REWRITTEN_SOURCES ) ,$(eval $(rs ) : $(rs ) .json))
555
+ $(REWRITTEN_SOURCES ) :
556
+ $(LITANI ) add-job \
557
+ --command \
558
+
559
+ --inputs $($@ _SOURCE) \
560
+ --outputs $@ \
561
+ --stdout-file $(LOGDIR ) /crangler-$(subst /,_,$(subst .,_,$@ ) ) -log.txt \
562
+ --interleave-stdout-stderr \
563
+ --pipeline-name " $( PROOF_UID) " \
564
+ --ci-stage build \
565
+ --description " $( PROOF_UID) : removing static"
566
+
487
567
# ###############################################################
488
568
# Build targets that make the relevant .goto files
489
569
490
570
# Compile project sources
491
- $(PROJECT_GOTO ) 1.goto : $(PROJECT_SOURCES )
571
+ $(PROJECT_GOTO ) 1.goto : $(PROJECT_SOURCES ) $( REWRITTEN_SOURCES )
492
572
$(LITANI ) add-job \
493
573
--command \
494
- ' $(GOTO_CC) $(CBMC_VERBOSITY) --export-file-local-symbols $(COMPILE_FLAGS) $(INCLUDES) $(DEFINES) $^ -o $@' \
574
+ ' $(GOTO_CC) $(CBMC_VERBOSITY) $(COMPILE_FLAGS) $(EXPORT_FILE_LOCAL_SYMBOLS ) $(INCLUDES) $(DEFINES) $^ -o $@' \
495
575
--inputs $^ \
496
576
--outputs $@ \
497
577
--stdout-file $(LOGDIR ) /project_sources-log.txt \
@@ -503,7 +583,7 @@ $(PROJECT_GOTO)1.goto: $(PROJECT_SOURCES)
503
583
$(PROOF_GOTO ) 1.goto : $(PROOF_SOURCES )
504
584
$(LITANI ) add-job \
505
585
--command \
506
- ' $(GOTO_CC) $(CBMC_VERBOSITY) --export-file-local-symbols $(COMPILE_FLAGS) $(INCLUDES) $(DEFINES) $^ -o $@' \
586
+ ' $(GOTO_CC) $(CBMC_VERBOSITY) $(COMPILE_FLAGS) $(EXPORT_FILE_LOCAL_SYMBOLS ) $(INCLUDES) $(DEFINES) $^ -o $@' \
507
587
--inputs $^ \
508
588
--outputs $@ \
509
589
--stdout-file $(LOGDIR ) /proof_sources-log.txt \
@@ -836,6 +916,7 @@ clean:
836
916
-$(RM ) $(DEPENDENT_GOTOS )
837
917
-$(RM ) TAGS*
838
918
-$(RM ) * ~ \# *
919
+ -$(RM ) $(REWRITTEN_SOURCES ) $(foreach rs,$(REWRITTEN_SOURCES ) ,$(rs ) .json)
839
920
840
921
veryclean : clean
841
922
-$(RM ) -r html report
0 commit comments