Prof. A Olowofoyeku (The African Chief) wrote:
I have downloaded Frank's cgiprogs package, for the purpose of building a cgi program for an adsl router (running MontaVista Linux on a mipsfple processor). First, hats off to Frank. The program compiled and runs fine on the router.
Well, thanks. I've never tested the unit on such a machine, glad to know it works out of the box. :-)
The problem is the size of the compiled program (320kb when statically linked with libgpc.a, and 250kb when linked to libgpc.so, which itself is 320kb). This is a significant amount of space for a single program to take on a router.
Are you planning to have multiple programs? In this case, dynamic linking of libgpc.so (and possibly the CGI unit and the units it uses in turn) should be worthwile. Otherwise, of course, for a single program, dynamic linking doesn't gain anything filesize-wise.
Of course, "strip"ping the program (or using "-s") will save something, if you haven't already done so.
My question (and probably only Frank can answer this) is, how can one reduce the size of this program? The program uses the gpc and cgi units only. From the GPC unit it calls "Execute" and "GetTempDirectory",
Of course, it needs other parts of the RTS by implicit calls, directly or via the CGI unit (much of the string and file stuff, e.g.).
and from the cgi unit it calls: GetVar IsCGI CGIInitVars
You could rip out the parts of the source not needed, but I doubt this would really save much, since the biggest part of the size probably comes from the RTS anyway ...
As you might remember, we talked about "smart-linking" a log time ago. I haven't found the time to pursue it further or automate it, but you might try it manually.
You might still have the old mails around -- you mentioned a suggestion from someone from RedHat to use "--function-sections" when compiling (this would also apply to building the RTS), and objcopy with the options "--only-section" and/or "--strip-symbol".
Your last paragraph in that mail looked quite optimistic. If it works here as well (parts may be platform-specific, though I hope not), and if it's only a problem due to the number of symbols, I suppose I can help turning it into a shell script (for version 0.1; later it may become integrated in gp or such).
: The stuff with gpc/gcc '-ffunction-sections' and objcopy : '--only-section' works! I did it all wrong and wrote to the RedHat guy, : who sent me an example (see below). I can get it working correctly now. : Does this mean that there is now hope for smart linking (at least with : libgpc.a)?
Also "--gc-sections" might be worth looking at.
Perhaps there is a C cgi library?
I suppose there are quite a few actually, but I don't have any first-hand experience with of them, as I've written all my CGI programs in Pascal and bash. ;-)
Frank