On 21 Aug 2006 at 16:51, Frank Heckenbach wrote:
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. :-)
Well, to be honest, I didn't really know what to expect - but it turned out to be so straightforward :)
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.
This was just an experiment to see if I could add somefunctionality to the router firmware that other routers didn't have, but which I have seen in Smoothwall. In the end all that was required was two small procedures. I would have probably wanted to add more programs - but the router has only limited free space in the flash memory, and so it is not feasible if all programs would be 100kb or more in size.
Of course, "strip"ping the program (or using "-s") will save something, if you haven't already done so.
Yes, I already did that - flags: "-Os -s".
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.).
Indeed.
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 ...
Precisely. But it is one thing worth trying.
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).
[...]
It was okay with trivial stuff - but when I tried it with some more complex code, it all went awry (sometimes ok and sometimes not).
[...]
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. ;-)
Yes, I started off trying to write a shell script (the shell is "ash"). What got me stumped was the equivalent of your "GetVar" function - I could not figure out how to get the variable being sent to the CGI program and its value - so in desperation, I decided to write a pascal program, even though I knew that size would be a problem. If you know how to do a GetVar in bash, that would be an immediate solution, since I could just go back to a shell script. But I would still want to use the GPC option for other things.
Thanks.
Best regards, The Chief --------- Prof. Abimbola Olowofoyeku (The African Chief) Web: http://www.greatchief.plus.com/