Funkiness in getopt_long().

Rob Landley rob at landley.net
Tue Nov 15 01:54:07 UTC 2005


On Monday 14 November 2005 18:01, Mike Frysinger wrote:
> On Mon, Nov 14, 2005 at 04:36:55PM -0600, Rob Landley wrote:
> > On Monday 14 November 2005 08:05, Mike Frysinger wrote:
> > > On Mon, Nov 14, 2005 at 12:04:53AM -0600, Rob Landley wrote:
> > > > Busybox, linked against glibc, can handle "tar xvjCf directory
> > > > filename.tbz" Linked against uclibc, the optarg fetched by C isn't
> > > > "directory", it's "f".
> > >
> > > could you try the getopt tests in test/unistd/ and see if they work ? 
> > > if they do, can you update them to reproduce this bug and post the
> > > patch ?
> >
> > I wandered into test/unistd and all I saw were .c files, so I ran make,
> > and it did lots of things verbosely with no obvious way to tell if any of
> > them failed.  I'm assuming that since the build didn't stop, it didn't
> > fail.  At the end, $? was 0...
>
> run `make <test>` and `make <test>_glibc`
> in this case, `make getopt_long` will test against uclibc while
> `make getopt_long_glibc` will test against glibc

Uh-huh...

Ok, standard uClibc build setup looks something like:
$ tar xvjf ~elsewhere/uClibc-0.9.28.tar.bz2
$ cd uClibc-0.9.28
$ cp ~elsewhere/uClibc-config .config
$ tar xvjf ~elsewhere/linux-libc-headers*.tar.bz2
$ cat > extra/scripts/fix_includes.sh
$ mv linux-libc-headers*/include/{asm-i386,linux} include
$ mv include/{asm-i386,asm}
$ make

Here's what I tried then...
========
...
ln -sf librt-0.9.28.so ../lib/librt.so
ln -sf librt-0.9.28.so ../lib/librt.so.0
make[1]: Leaving directory `/home/landley/uClibc-0.9.28/librt'

Finally finished compiling ...

landley at driftwood:~/uClibc-0.9.28$ make getopt_long_glibc
make: *** No rule to make target `getopt_long_glibc'.  Stop.
landley at driftwood:~/uClibc-0.9.28$ make test
make: Nothing to be done for 'test'.
landley at driftwood:~/uClibc-0.9.28$ make help
make: *** No rule to make target `help'.  Stop.
landley at driftwood:~/uClibc-0.9.28$ cd test/
landley at driftwood:~/uClibc-0.9.28/test$ make getopt_long_glibc
make: *** No rule to make target `getopt_long_glibc'.  Stop.
landley at driftwood:~/uClibc-0.9.28/test$ cd unistd/
landley at driftwood:~/uClibc-0.9.28/test/unistd$ make getopt_long_glibc
----------------------------
Compiling getopt_long_glibc vs glibc:

gcc  -Wall -Wstrict-prototypes -Os -c getopt_long.c -o getopt_long_glibc.o
gcc -s -Wl,-warn-common getopt_long_glibc.o -o getopt_long_glibc
strip -x -R .note -R .comment getopt_long_glibc
$WRAPPER_getopt_long ./getopt_long_glibc $OPTS_getopt_long ; \
        ret=$? ; \
        test -z "$RET_getopt_long" && export RET_getopt_long=0 ; \
        test $ret -eq $RET_getopt_long
option add with arg XXX
option delete with arg YYY
option verbose

landley at driftwood:~/uClibc-0.9.28/test/unistd$ make getopt_long
----------------------------
Compiling getopt_long vs uClibc:

gcc  -Wall -Wstrict-prototypes -Os   -c getopt_long.c -o getopt_long.o
gcc  -s -Wl,-warn-common -Wl,-dynamic-linker,../../lib/ld-uClibc.so.0 
getopt_long.o -o getopt_long
$WRAPPER_getopt_long ./getopt_long $OPTS_getopt_long ; \
        ret=$? ; \
        test -z "$RET_getopt_long" && export RET_getopt_long=0 ; \
        test $ret -eq $RET_getopt_long
libc.so.6: aborted attempt to load ./getopt_long!
make: *** [getopt_long] Error 1
landley at driftwood:~/uClibc-0.9.28/test/unistd$   

Is there, perchance, documentation on how to use this test suite anywhere?  
There are no obvious documentation files in the "test" directory.  "grep -i 
test README" produces no hits.  "Find . | xargs grep -i test" doesn't 
produces a lot of noise, but nothing immediately useful...

Darn it, I thought this thing was simple.  I previously ran the make in the 
test/unistd directory under a chroot environment where uClibc was the only 
library available, so I thought it was just linking against whatever libc was 
installed.  Not only is that not the case, but I can't figure out what the 
point of the new complications are if simply building the sucker and then 
trying to test it without installing it on the parent system doesn't seem to 
work...

> > I'll take a look at reproducing it with a stripped-down C snippet.
>
> i was looking for a patch against getopt_long.c which would reproduce
> the bug :)

Ok, so you're not interested in a stripped-down C snippet reproducing the bug.  
I'm not interested in spending my evening focusing on getting the code that's 
already in your test suite to do something useful, let alone extending it.

I currently find it somewhat non-obvious to figure out how to even _run_ the 
uClibc test suite.  It's more complicated than I thought, it doesn't work for 
me, and if I was going to do anything to it I'd write documentation on how to 
use it.  But first I'd have to figure out what to _put_ in such 
documentation, which I don't currently know and am not particularly 
interested in spending a lot of effort finding out just now because I already 
have the to-do list of doom and this is another time-sink.

I just want it to work.  My standard approach to debugging this sort of 
problem involves sticking printfs into uClibc and running the existing 
failing uber-complicated test (the failing busybox tar invocation) against it 
until I understand the behavior well enough to to produce a patch fixing 
uClibc.  (The stripped-down reproduction sequence would have been entirely 
for your benefit, not mine.  I _have_ a reliable reproduction sequence, 
thanks.)  I just posted the bug here first in case it was obvious to somebody 
already familiar with this part of the uClibc codebase.  Not because I can't 
fix it.

I am also currently extending the busybox testsuite (which is documented: 
either read testsuite/README or run "make help" at the root level to find out 
about "make check" which runs everything), and I will indeed be adding tar 
tests that exercise exactly this case, and trying it under both glibc and 
uClibc.  And if anything else breaks, I'll send a patch. :)

> -mike

Rob



More information about the uClibc mailing list