# HG changeset patch # User Paul Boddie # Date 1487939105 -3600 # Node ID 5dfbfa8e22880f14f24e2a1ee88c23a758b5adc7 # Parent 96e7d83d8d83a856df6de13ccce68b4a1157885f Introduced support for removing superfluous executable sections via an option. diff -r 96e7d83d8d83 -r 5dfbfa8e2288 docs/lplc.1 --- a/docs/lplc.1 Fri Feb 24 00:02:46 2017 +0100 +++ b/docs/lplc.1 Fri Feb 24 13:25:05 2017 +0100 @@ -33,6 +33,11 @@ .BR \-g ", " \-\-debug Generate debugging information for the built executable .TP +.BR \-G ", " \-\-gc\-sections +Remove superfluous sections of the built executable by applying the +.B \-\-gc\-sections +linker option and associated compiler options +.TP .BR \-P ", " \-\-show\-path Show the module search path .TP diff -r 96e7d83d8d83 -r 5dfbfa8e2288 generator.py --- a/generator.py Fri Feb 24 00:02:46 2017 +0100 +++ b/generator.py Fri Feb 24 13:25:05 2017 +0100 @@ -78,13 +78,13 @@ self.optimiser = optimiser self.output = output - def to_output(self, debug=False): + def to_output(self, debug=False, gc_sections=False): "Write the generated code." self.check_output() self.write_structures() - self.write_scripts(debug) + self.write_scripts(debug, gc_sections) self.copy_templates() def copy_templates(self): @@ -418,7 +418,7 @@ f_signatures.close() f_code.close() - def write_scripts(self, debug): + def write_scripts(self, debug, gc_sections): "Write scripts used to build the program." @@ -429,6 +429,9 @@ if debug: print >>f_options, "CFLAGS = -g" + if gc_sections: + print >>f_options, "include gc_sections.mk" + # Identify modules used by the program. native_modules = [join("native", "common.c")] diff -r 96e7d83d8d83 -r 5dfbfa8e2288 lplc --- a/lplc Fri Feb 24 00:02:46 2017 +0100 +++ b/lplc Fri Feb 24 13:25:05 2017 +0100 @@ -115,6 +115,8 @@ --no-env Equivalent to -E -g Generate debugging information for the built executable --debug Equivalent to -g +-G Remove superfluous sections of the built executable +--gc-sections Equivalent to -G -P Show the module search path --show-path Equivalent to -P -q Silence messages produced when building an executable @@ -170,6 +172,7 @@ # Determine the options and arguments. debug = False + gc_sections = False ignore_env = False make = True make_verbose = True @@ -192,6 +195,7 @@ if arg in ("-c", "--compile"): make = False elif arg in ("-E", "--no-env"): ignore_env = True elif arg in ("-g", "--debug"): debug = True + elif arg in ("-G", "--gc-sections"): gc_sections = True elif arg in ("-q", "--quiet"): make_verbose = False elif arg in ("-r", "--reset"): reset = True elif arg in ("-R", "--reset-all"): reset_all = True @@ -284,7 +288,7 @@ if timings: now = stopwatch("Optimisation", now) g = generator.Generator(i, o, generated_dir) - g.to_output(debug) + g.to_output(debug, gc_sections) if timings: now = stopwatch("Generation", now) diff -r 96e7d83d8d83 -r 5dfbfa8e2288 templates/gc_sections.mk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/gc_sections.mk Fri Feb 24 13:25:05 2017 +0100 @@ -0,0 +1,2 @@ +CFLAGS += -fdata-sections -ffunction-sections +LDFLAGS += -Wl,--gc-sections