This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]