Is there a possibility for "intelligent" linking?
Christof Eb.
Posts: 1,237
Hi,
in my first PropGcc- Projekt I want to include some floating point math. Therefore I include math.lib.
The linker seems to include very much or even the whole of the library. The code is now 12kBytes longer. :-(
Is there a possibility that the linker will link only what is really needed?
Thanks!
Christof
in my first PropGcc- Projekt I want to include some floating point math. Therefore I include math.lib.
The linker seems to include very much or even the whole of the library. The code is now 12kBytes longer. :-(
Is there a possibility that the linker will link only what is really needed?
Thanks!
Christof
Comments
Linking is "intelligent." Please post your example.
Propeller GCC floating point is emulated via the generic BSD library.
The 64bit double library is used by default. Use 32bit doubles if you can.
Any time you use printf, code size blossoms. The Simple printf alternative is smaller.
If you need a full 64bit double solution, there are better choices.
--Steve
The linker does try to link only what is really needed. If you include the -Xlinker -Map=a.map in the second blank box in the lower left corner of the IDE, it should produce a load map into a file named a.map. This map would show you exactly what files are loaded and exactly what routine first caused each file to be needed. More information about this option can be found in the wiki at http://code.google.com/p/propgcc/wiki/PropGccMaps.
Unfortunately, while the SimpleIDE seems to pay attention to both of those "extra flags" boxes, it doesn't actually seem to use the them (the problem is the exact same as you ran into with the --save-temps flag). So, if you want the map you need to run the compiler yourself from a command line. To do this, bring up a command prompt (see for example http://www.computerhope.com/issues/chdos.htm), cd to your project directory, make sure your path includes the actual compiler (probably something like c:\propgcc\bin), copy the compile/link command the IDE seemed to use from the build window, paste this command into the command prompt window, make sure it includes the "-Xlinker -Map=a.map" flags, then run it.
Otherwise, you'll just have to trust that PropGCC does the right thing and only links in the routines it needs. The floating point routines are very big, and probably are not terribly useful for LMM mode programs.
The SimpleIDE project option boxes are only used to give compiler flags and linker options to the final build step which compiles and links all .c and generated .o files.
All variables are int. There is only one line with float within (simple) printf. Only multiply, divide and "%8f" is used.
The two versions of this line are:
....
//printf("%8d %8d Mass: %8f grams\n", actfreq, (minfreq-actfreq), 1.0*actfreq*actfreq/2736750);
printf("%8d %8d Mass: %8d /10 grams\n", actfreq, (minfreq-actfreq), actfreq*actfreq/273675);
...
It is interesting, that the second version, which can be compiled and runs without math.lib (9072bytes), still is very much larger(19400bytes), if you don't switch off math.lib and 32bit double!
Christof
By the way: "-save-temps" works, without "--".
I still think there's a problem. Here's the repro steps:
1) Create a new project in SIDE 0.5.0 on Windows using Project | New Project. I called my project "Hallo". (This should create a Hallo.c with an empty main(); this is enough for the test.)
2) Change the first empty box in the lower-left "Compiler" area to hold "--save-temps -g"
3) Change the second empty box in the lower-left "Compiler" area to hold "-Xlinker -Map=a.map"
4) Choose Debug | Build, or hit <f9>
5) Inspect your project directory (using File | Open, or directly browse to it using Windows Explorer)
Expected to see: Hallo.s, Hallo.o, and a.map
Found instead: none of these files
If you look in the build window at the bottom right of SIDE, you'll notice the following compile/link line:
Notice this line does include --save-temps -g and -Xlinker -Map=a.map, even though those options seemed to have no effect.
Further evidence:
A) Next, open a command window.
Cd to your project directory.
C) Make sure your path includes PropGcc's bin directory.
D) Paste the exact same command as shown above in that window, and run it.
Notice you now have the .s, .i, and.map files, as expected.
When I use -save-temps instead of --save-temps, only the .i file appears, but I still don't see the .s file.
try compiling this with and without mathlib:
// TestMath_A.c
#include <stdio.h>
#include <propeller.h>
#include <math.h>
main()
{
printf("Hello \n");
}
10kByte for nothing?
Regards Christof
Not really. The -lm library includes a different printf with support for floats/doubles (depending on the 32-bit doubles setting). So, the 10K is for floating point support in printf.
6,600 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -fno-exceptions add.c -s
6,600 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -fno-exceptions add.c -lm -s
6,600 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -m32bit-doubles -fno-exceptions add.c -lm -s
7,328 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -fno-exceptions -Dprintf=__simple_printf add.c -s
7,328 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -m32bit-doubles -fno-exceptions -Dprintf=__simple_printf add.c -s
17,656 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -m32bit-doubles -fno-exceptions -Dprintf=__simple_printf add.c -lm -s
22,000 propeller-elf-gcc.exe -o a.out -O0 -mlmm -Wall -fno-exceptions -Dprintf=__simple_printf add.c -lm -s
Interesting side note: Some of these numbers go up considerably if you change the printf line to this:
printf("Hello %d\n", 1);
or to this:
printf("Hello");
The reason is the GCC optimizes the printf to a puts (even with -O0). And, it doesn't use puts unless the string ends in "\n", so for printf("Hello"), the numbers you get are: 14312 and 31128 for your first two test cases, the second number being larger because the library includes support for floating point.
It's always helpful to look at the generated assembly and maps to tell exactly what is going on.
I totally agree - Steve do you want to add buttons in SimpleIde for an asm output with source included and for map output?
Back to the original question. Do I understand it right, that the linker cannot be more intelligent, because printf must interpret the
format string at execution time and there might be a float or other things? If this is the case, then there should exist some solution
for a more basic printf or so.
Christof
Yes, this is the case. If you use printf (and GCC doesn't convert your printf() to an equivalent puts()), then you link in everything that printf needs, even if you're not using those features of printf.
This solution does exist: in the IDE, make sure "Simple printf" is checked - this roughly halves the size of printf.
Or, you can use your define your own version of printf. Check out this thread for a version of printf that uses only 1.5K: http://forums.parallax.com/showthread.php?137928-PropGCC-SimpleIDE&p=1076114&highlight=printf#post1076114
Making a status tab at the bottom would be easy. I guess a separate dialog popup window would be more convenient though.
We will provide integer only "SPIN-like" character input/output tools in a separate library.
We could make the integer only tinyprintf mentioned by denominator a library. Ted TODO?
Indeed, my plan is to have a separate library, -ltiny, that would include small printf, sprintf, fprintf, scanf, etc., along with the smaller memory allocators and anything else that comes along that needs a smaller size. Soon.
the question to add a button was just a proposal - my English is not so good. I am not sure about the right tone. This simpleIDE and its easy installation gives an easy entry to guys like me. That is great!
When I work with PropBasic the I like to have a look into the asm-code, it is interesting, to learn, what the compiler did. So this is a little bit for education.
Christof
Hi denominator,
I will have a look at tinyprintf.c thanks!
Christof