Path: utzoo!attcan!uunet!samsung!usc!ucsd!ucbvax!MATHEMATIK.UNI-ULM.DE!borchert From: borchert@MATHEMATIK.UNI-ULM.DE (Andreas Borchert) Newsgroups: comp.lang.modula2 Subject: Re: How to make libraries smaller? Message-ID: <9005281240.AA07902@mathematik.uni-ulm.de> Date: 28 May 90 12:40:56 GMT Sender: daemon@ucbvax.BERKELEY.EDU Reply-To: Modula2 List Organization: The Internet Lines: 63 Tom Tkacik writes: > I am working on a convoluted method of making smaller executables. > I I could get it to work, I should be able to have Modula-2 executables > as small a C executables. I need help. Can it be done? > > What I was thinking of doing is to remove all but a single procedure from > a source library file (perhaps using the C preprocessor and its > #ifdef directive) and compile the file. > Then do this for each procedure in the file. All of the compiled > files would be given different names, (the linker does not > care what the file is called), and collected into a single library. > > This seems all well and good, execpt for global variables. > If a global variable is used by two procedures, it would have to remain in > the source file twice, and be compiled twice. The result would be a > multipy defined variable. But if I left it out during one of the compiles, > the compiler would complain. I can't IMPORT it from another file, because > then the compiler would give it the wrong name. > What is needed is some way to simulate C's extern. I need to declare a > variable as external, but with a local name. Is this at all possible? You cannot simulate C's extern in Modula-2. C externals do not have a "local name". They are simply common variables, i.e. one or more declarations of the same variable identifier refer to the same variable. > Is there another solution to the problem? I am fairly new to Modula-2, > (does my C background show? :-) There are at least two ways to solve this problem: on the level of the original Modula-2 source and on the level of the compiler output. If you want to be free of dependencies to your compiler and to your environment you are enforced to produce a set of modules out of the big one (that's what you've tried). But this implies that every global variable is declared once and only once. Modula-2 doesn't support common variables in the sense of Fortran or C. Simply collect all global types and variables into one module and import all that stuff in each of the other partitions. If your Modula-2 compiler generates assembly output it should be rather easy (using awk) to cut it into a set of smaller entities. Global variables in Modula-2 are part of the bss segment (they cannot be initialized). Variables in the bss segment are declared as common (or at least can be declared to be common). So you simply need to repeat the code for the variables for each procedure of the module. Some pitfalls if you are cutting the assembly text: (1) Don't separate local procedures from the procedures they belong to. It should be easy to distinguish local procedures from global procedures: the symbol of the local procedure is not extern. (2) Check how floating point constants are generated. Not every machine accepts immediate floating point values. In this case the constants are generated elsewhere. (3) String constants have local symbols and are part of the text segment. Simply copy them like global variables. (4) Don't separate the initialization part from the initialization flag. Andreas Borchert