Lichen

Changeset

614:5dfbfa8e2288
2017-02-24 Paul Boddie raw files shortlog changelog graph Introduced support for removing superfluous executable sections via an option. method-wrapper-for-context
docs/lplc.1 (file) generator.py (file) lplc (file) templates/gc_sections.mk (file)
     1.1 --- a/docs/lplc.1	Fri Feb 24 00:02:46 2017 +0100
     1.2 +++ b/docs/lplc.1	Fri Feb 24 13:25:05 2017 +0100
     1.3 @@ -33,6 +33,11 @@
     1.4  .BR \-g ", " \-\-debug
     1.5  Generate debugging information for the built executable
     1.6  .TP
     1.7 +.BR \-G ", " \-\-gc\-sections
     1.8 +Remove superfluous sections of the built executable by applying the
     1.9 +.B \-\-gc\-sections
    1.10 +linker option and associated compiler options
    1.11 +.TP
    1.12  .BR \-P ", " \-\-show\-path
    1.13  Show the module search path
    1.14  .TP
     2.1 --- a/generator.py	Fri Feb 24 00:02:46 2017 +0100
     2.2 +++ b/generator.py	Fri Feb 24 13:25:05 2017 +0100
     2.3 @@ -78,13 +78,13 @@
     2.4          self.optimiser = optimiser
     2.5          self.output = output
     2.6  
     2.7 -    def to_output(self, debug=False):
     2.8 +    def to_output(self, debug=False, gc_sections=False):
     2.9  
    2.10          "Write the generated code."
    2.11  
    2.12          self.check_output()
    2.13          self.write_structures()
    2.14 -        self.write_scripts(debug)
    2.15 +        self.write_scripts(debug, gc_sections)
    2.16          self.copy_templates()
    2.17  
    2.18      def copy_templates(self):
    2.19 @@ -418,7 +418,7 @@
    2.20              f_signatures.close()
    2.21              f_code.close()
    2.22  
    2.23 -    def write_scripts(self, debug):
    2.24 +    def write_scripts(self, debug, gc_sections):
    2.25  
    2.26          "Write scripts used to build the program."
    2.27  
    2.28 @@ -429,6 +429,9 @@
    2.29              if debug:
    2.30                  print >>f_options, "CFLAGS = -g"
    2.31  
    2.32 +            if gc_sections:
    2.33 +                print >>f_options, "include gc_sections.mk"
    2.34 +
    2.35              # Identify modules used by the program.
    2.36  
    2.37              native_modules = [join("native", "common.c")]
     3.1 --- a/lplc	Fri Feb 24 00:02:46 2017 +0100
     3.2 +++ b/lplc	Fri Feb 24 13:25:05 2017 +0100
     3.3 @@ -115,6 +115,8 @@
     3.4  --no-env    Equivalent to -E
     3.5  -g          Generate debugging information for the built executable
     3.6  --debug     Equivalent to -g
     3.7 +-G          Remove superfluous sections of the built executable
     3.8 +--gc-sections Equivalent to -G
     3.9  -P          Show the module search path
    3.10  --show-path Equivalent to -P
    3.11  -q          Silence messages produced when building an executable
    3.12 @@ -170,6 +172,7 @@
    3.13      # Determine the options and arguments.
    3.14  
    3.15      debug = False
    3.16 +    gc_sections = False
    3.17      ignore_env = False
    3.18      make = True
    3.19      make_verbose = True
    3.20 @@ -192,6 +195,7 @@
    3.21          if arg in ("-c", "--compile"): make = False
    3.22          elif arg in ("-E", "--no-env"): ignore_env = True
    3.23          elif arg in ("-g", "--debug"): debug = True
    3.24 +        elif arg in ("-G", "--gc-sections"): gc_sections = True
    3.25          elif arg in ("-q", "--quiet"): make_verbose = False
    3.26          elif arg in ("-r", "--reset"): reset = True
    3.27          elif arg in ("-R", "--reset-all"): reset_all = True
    3.28 @@ -284,7 +288,7 @@
    3.29          if timings: now = stopwatch("Optimisation", now)
    3.30  
    3.31          g = generator.Generator(i, o, generated_dir)
    3.32 -        g.to_output(debug)
    3.33 +        g.to_output(debug, gc_sections)
    3.34  
    3.35          if timings: now = stopwatch("Generation", now)
    3.36  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/templates/gc_sections.mk	Fri Feb 24 13:25:05 2017 +0100
     4.3 @@ -0,0 +1,2 @@
     4.4 +CFLAGS += -fdata-sections -ffunction-sections
     4.5 +LDFLAGS += -Wl,--gc-sections