This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
readelf_need_wide
- From: Phil Edwards <phil at jaj dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Tue, 3 Sep 2002 20:30:39 -0400
- Subject: readelf_need_wide
We're checking for whether readelf supports a certain option. But the
method used (feeding grep through system()) doesn't do what we think it
does; system() returns nonzero iff the command dies in some freaky way.
The command's normal exit value has to be extracted with WEXITSTATUS.
So not:
fenric 25% ls --help | grep -- blargle
fenric 26% echo $?
1
fenric 27% cat t.cc
#include <stdlib.h>
int main()
{
return system("ls --help | grep -- blargle > /dev/null");
}
fenric 28% g++ t.cc
fenric 29% ./a.out
fenric 30% echo $?
0
But rather:
fenric 31% cat t2.cc
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
int ret = system("ls --help | grep -- blargle > /dev/null");
return WEXITSTATUS(ret);
}
fenric 32% g++ t2.cc
fenric 33% ./a.out
fenric 34% echo $?
1
fenric 35%
Loren, do you actually get the correct answers using an older readelf that
doesn't have -W/--wide? I would expect that in this code,
bool readelf_need_wide =
(system("readelf --help | grep -- --wide >/dev/null") == 0);
readelf_need_wide should always be zero, unless grep itself segfaults or
otherwise craps out with a signal.
Phil