sed breaks when statically linked against glibc?

Rob Landley rob at landley.net
Wed Oct 28 17:47:23 UTC 2009


On Wednesday 28 October 2009 08:40:02 Denys Vlasenko wrote:
> > How about a config options GLIBC_STATIC_WORKAROUND that adds an atexit()
> > call to the busybox applet multiplexer?  I.E. adding this to libbb:
>
> Well, if you are ok with switching on this option then you are equally ok
> with switching on CONFIG_STATIC, which already exists and makes
> this problem go away.

Personally I'd just switch the workaround on and leave it even in the dynamic 
case (shouldn't hurt anything and the dozen or so bytes is worth it for me), 
but I see your point.

It was more that I was looking for a way to keep doing the --gc-sections, 
which is likely to save more space than the workaround eats.  But I haven't 
measured it to see, and I admit trying to optimize static glibc linking is 
silly.

> > void xflush(void)
> > {
> >        fflush(NULL);
> > }
> >
> > (Which seems potentially useful from a bunch of places, saving 4
> > bytes/call for flushes since there's seldom any case where we _don't_
> > want to flush all pending ANSI output streams.)
> >
> > And then somewhere in busybox_main (wherever it's got to, somewhere under
> > libbb these days I think):
> >
> >  if (ENABLE_GLIBC_STATIC_WORKAROUND) atexit(xflush);
>
> Unfortunately, (1) we use _exit() a lot, and

Which means you already don't get fflush(stdout) called in those cases, even 
when it's not statically linked, so this would make no difference.

Although now that I look at a quick grep, I really don't understand this bit 
in tar.c:

                vfork_exec_errno = errno;
                _exit(EXIT_FAILURE);

> (2) atexit machinery itself may similarly be affected by -static

The atexit machinery shouldn't be, the bug was that there are functions marked 
"atexit" by linker magic (not by being called from the atexit() function at 
runtime), and those sections are being stripped by --gc-sections if they're 
not directly called from any function.

The applet in question (sed) looks like it's already using atexit() twice.  So 
if atexit isn't working, neither is sed -i.

> I can throw a fflush(NULL) into main() _after_ we call <applet>_main(),
> if there is no way for you to force CONFIG_STATIC on.

Mostly just looking for a more elegant solution.  I already have a workaround 
(which treats "building on the host" as a special case rather than treating 
busybox as a special case).

The LDFLAGS=--static looked like it should work, and did sort of work even on 
glibc, and still works fine with uClibc.  Bit of a trap for the unwary that, 
but not exactly a new one.

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds


More information about the busybox mailing list