Boost logo

Boost Users :

Subject: Re: [Boost-users] [program-options] static linked example segfaults for exception
From: Neetu Garg (garg_neetu_at_[hidden])
Date: 2010-03-22 14:17:01


Hi,

Can I please get some input on this issue.

Thanks for your help

Regards,

NG

----- Original Message ----
From: Neetu Garg <garg_neetu_at_[hidden]>
To: boost-users_at_[hidden]
Sent: Fri, March 19, 2010 11:08:43 AM
Subject: Re: program option library segfaults for exception

I did little more digging into the issue

If I compile and link following sample on Linux dynamically using following command
g++ -c -I. -I/usr/local/include/boost-1_38 -I/usr/include testprogramoptions.cpp -o testprogramoptions.o

g++ testprogramoptions.o -static-libgcc -L/u/neetug/Projects/performance/perfstat_cluster/lib -lboost_program_options-gcc41-mt -lpthread -o testprogramoptions

[root_at_perf-tools-7 src]# ./testprogramoptions --o
ERROR unknown option o
ERROR Error while parsing CLI options Exiting

Here "--o" is unknown option
=======================================================================

If I compile and link following sample on Linux statically using following command
g++ -c -I. -I/usr/local/include/boost-1_38 -I/usr/include testprogramoptions.cpp -o testprogramoptions.o

g++ testprogramoptions.o -static-libgcc
-Wl,-Bstatic -L/u/neetug/Projects/performance/perfstat_cluster/lib
-lboost_program_options-gcc41-mt -lpthread -o testprogramoptions

[root_at_perf-tools-7 src]# ./testprogramoptions --o
Aborted

Here "--o" is unknown option
========================================================================
I am not sure why the behavior is different with different linking option why I am not getting exception for static linking.

Really appreciate any help in this issue.

Here in the test program

#include <iostream>
#include <boost/program_options.hpp>
namespace boostOptions = boost::program_options;
using namespace std;

int main(int argCount, char* argList[])
{
        try {

                boostOptions::options_description commonOpt("Options (common)");
                commonOpt.add_options()
                        ("help,h", "Produce help message.")
                        ("version,v", "Prints perfstat version, and supported ONTAP versions.")
                ;

                boostOptions::options_description runModeOpt("Options ('run' mode)");
                runModeOpt.add_options()
                        ("clusterinfo", boostOptions::value<string>(), "cluster IP.")
                        ("sample-interval", boostOptions::value<int>(), "Specifies statit/sysstat frequency")
                ;

                boostOptions::positional_options_description posOption;
                posOption.add("clusterinfo", -1);

                boostOptions::options_description allOptDesc("Allowed options :");
                allOptDesc.add(commonOpt).add(runModeOpt);

                boostOptions::variables_map varMap;
                boostOptions::store(boostOptions::command_line_parser(argCount, argList).
                  options(allOptDesc).positional(posOption).run(), varMap);
                boostOptions::notify(varMap);

        }
        catch(std::exception &e)
        {
                cout << "ERROR " << e.what() << "\n";
                cout << "ERROR " << "Error while parsing CLI options Exiting" << "\n";
                exit(0);
        }
        catch(...)
        {
                 cout << "ERROR 1 " << "\n";
                cout << "ERROR 1 " << "Error while parsing CLI options Exiting" << "\n";
                exit(0);
        }
}

Regards,

NG

----- Original Message ----
From: Neetu Garg <garg_neetu_at_[hidden]>
To: boost-users_at_[hidden]
Sent: Wed, March 17, 2010 1:17:07 PM
Subject: program option library segfaults for exception

Sorry for the duplicate post, I think my message posted under different conversation.

Hi,

I have application that is using boost program option
library. If I provide unknown option via CLI it should throw exception.
The library is statically linked on windows and Linux environment. It works fine on windows platform I do get exception for
unknown CLI option. On Linux platform I get "segfault" in place of
exception for unknown CLI option.

It is s a multi-threaded
application and it also uses boost thread library. Application does
throw exception on Linux also if I link dynamically.

I am using following flags to link the library statically:

LDFLAGS=
-fexceptions -static-libgcc -Wl,-static -L/usr/lib
-lboost_program_options-gcc41-mt -lboost_filesystem-gcc41-mt
-lboost_thread-gcc41-mt -lboost_system-gcc41-mt -lnet7ssh -lbotan -ltar
-lz -lrt -lpthread

I am using following version of gcc:
# g++ --version
g++ (GCC) 4.1.1
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Here is the core dump for the segfault:

(gdb) backtrace
#0 __gnu_internal::get_global () at /usr/software/src/gcc-4.1.1/libstdc++-v3/libsupc++/eh_globals.cc:58
#1 0x082c0f67 in __cxa_get_globals () at /usr/software/src/gcc-4.1.1/libstdc++-v3/libsupc++/eh_globals.cc:71
#2
0x082c0b3f in __cxa_allocate_exception (thrown_size=32) at
/usr/software/src/gcc-4.1.1/libstdc++-v3/libsupc++/eh_alloc.cc:154
#3 0x080a71f8 in boost::program_options::detail::cmdline::finish_option ()
#4 0x080a77eb in boost::program_options::detail::cmdline::run ()
#5 0x0806f3aa in boost::program_options::basic_command_line_parser<char>::run ()
#6 0x080660e9 in CLIHandler::collectCLIOptions ()
#7 0x0808a0d1 in perfstat::runPerfstat ()
#8 0x0808af3d in main ()
Current language: auto; currently c++

Appreciate your help

Regards,

NG

      


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net