[Boost-bugs] [Boost C++ Libraries] #10228: boost::filesystem::path::parent_path crashes with static link

Subject: [Boost-bugs] [Boost C++ Libraries] #10228: boost::filesystem::path::parent_path crashes with static link
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-07-23 05:12:25

#10228: boost::filesystem::path::parent_path crashes with static link
 Reporter: hzj_jie@… | Type: Bugs
   Status: new | Milestone: To Be Determined
Component: None | Version: Boost 1.55.0
 Severity: Problem | Keywords:
 with following code

 #include <string>
 #include <boost/filesystem.hpp>
 #include <stdint.h>
 #include <locale>
 #include <limits.h>
 #include <unistd.h>
 #include <sys/types.h>
 using namespace std;
 using namespace boost::filesystem;

 namespace __exeinfo_private
     static std::string getexepath()
         char result[PATH_MAX];
         ssize_t count = readlink("/proc/self/exe", result, PATH_MAX);
         return std::string(result, count > 0 ? count : 0);

     static int64_t get_current_process_id()
         // from int32_t to int64_t
         return getpid();

 static void run()
     string _path = __exeinfo_private::getexepath();
     path p(_path);
     if(!p.empty() && p.has_filename() && !p.parent_path().empty())
         cout << p.filename().string() << endl << p.parent_path().string()
 << endl;

 const static class ABC

     static const ABC& instance()
         static const ABC i;
         return i;
 }& instance = ABC::instance();

 int main()
 compile with g++ exeinfo.cpp -lboost_filesystem -lboost_system, everything
 is ok, the output is expected as <the second and fourth lines are the path
 where the binary exists>

 compile with g++ exeinfo.cpp -lboost_filesystem -lboost_system -static,
 static link with boost, the line 41, which is the constructor of ABC class
 will crash. the call stack is,
 #0 0x0000000000433455 in std::locale::locale(std::locale const&) ()
 #1 0x000000000040223c in boost::filesystem::path::codecvt() ()
 #2 0x0000000000403927 in boost::filesystem::path::parent_path() const ()
 #3 0x00000000004015d9 in run () at exeinfo.cpp:32
 #4 0x0000000000401a77 in ABC::ABC (this=0x74ee60 <ABC::instance()::i>) at
 #5 0x0000000000401aaf in ABC::instance () at exeinfo.cpp:47
 #6 0x00000000004017a5 in __static_initialization_and_destruction_0
 (__initialize_p=1, __priority=65535) at exeinfo.cpp:50
 #7 0x00000000004017c1 in _GLOBAL__sub_I_main () at exeinfo.cpp:55
 #8 0x000000000045f5d7 in __libc_csu_init ()
 #9 0x000000000045f079 in __libc_start_main ()
 #10 0x00000000004013a7 in _start ()

 according to some basic investigation, the trouble is coming from
 libs/filesystem/src/path.cpp, while the path_locale has not been
 initialized before ABC::ABC() running.
 because of the difference of implementation, in windows, no matter static
 or dynamic link, will not cause crash.
 please kindly let me know if this is by design, or has been fixed in the
 coming release, or if there were some work around.

 thank you in advanced.

 the environment i am now using is,
 Linux hzj-jie-x61t 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08
 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
 gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
 but i have tried this on an x86 machine, which has the same experience.

Ticket URL: <https://svn.boost.org/trac/boost/ticket/10228>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC