busybox Digest, Vol 2, Issue 11
Rob Landley
rob at landley.net
Sun Sep 4 11:37:29 UTC 2005
On Sunday 04 September 2005 00:03, Lord Sidiuz wrote:
> > I'm familiar with this sort of thing. We should actually have a message
> > lookup table we index into, because gcc sucks at merging duplicate
> > strings. (The macro can hide that.)
> >
> > That's probably a good idea anyway. :)
>
> actually we could use defines like this, when you do the make
> menuconfig add a new option for configuring the lang, default to
> english of course, and then in the files that contains the actual
> messages
> use something like this:
>
> #if LANG=english
> #define mesage1 "the message"
> ...
> #else if LANG=spanish
> #define mesage1 "el mensaje"
> ...
> #else if LANG=russian
> #define mesage1 "el mensajobski" //sorry if that is offensive I just
> can't help myself
No, the reason I suggested a message lookup table is that the above has a
nasty tendency to copy the string into every .o file that uses it and then
not get merged by the linker, so you wind up with multiple copies of the same
string in your program.
It's possible that gcc 4 or Red Hat's binutils fork (2.14.95.3.14159265...)
has finally started doing something intelligent with this, but string merging
is something at which gcc has historically sucked pretty badly. I know they
were trying to address some stuff with the "unit at a time" changes, but
haven't been following it closely enough.
(This issue falls in the cracks between the compiler and the linker. It's not
something the compiler can optimize because it's not looking at multiple -o
files, and the linker doesn't have the world's greatest idea of what all
these symbols are used for by the code, and expects the compiler to do most
of the optimization anyway...)
With a lookup table, we organize the suckers and make sure there's one copy of
them ourselves. And since we have to move it out to a seperate file for
translation purposes anyway, a lookup table is easy to do. (If all elsefails
it can be built by a script...)
Rob
More information about the busybox
mailing list