Home › Forum › SOFA › Programming with SOFA › Segmentation fault with clang and libc++
Tagged: 64_bits, Linux_ubuntu, SOFA_other
- This topic has 6 replies, 3 voices, and was last updated 3 years, 2 months ago by Hugo.
-
AuthorPosts
-
6 April 2020 at 12:59 #15651bobikoBlocked
Hi all,
I am difficulties compiling a project with clang. This project also uses other framework which has its own dependencies, so it must be compiled with clang and linked against libc++ and libc++abi. The project compiles okay, but when I try to run it I get a segfault. Here is the traceback:
1 __cxxabiv1::__si_class_type_info::__do_dyncast(long, __cxxabiv1::__class_type_info::__sub_kind, __cxxabiv1::__class_type_info const *, void const *, __cxxabiv1::__class_type_info const *, void const *, __cxxabiv1::__class_type_info::__dyncast_result&) const 0x7f55964c89fb 2 ?? 0x7f55967e125e 3 ?? 0x7f55967e349e 4 __gxx_personality_v0 0x7f55967e3010 5 _Unwind_RaiseException 0x7f5595e8f96b 6 __cxa_throw 0x7f55967e2a07 7 std::__throw_ios_failure(const char *) 0x7f55964f8fe8 8 std::basic_filebuf<char, std::char_traits<char>>::underflow() 0x7f5596523a4a 9 std::basic_istream<char, std::char_traits<char>>& std::getline<char, std::char_traits<char>, std::allocator<char>>(std::basic_istream<char, std::char_traits<char>>&, std::string&, char) 0x7f55964e1079 10 sofa::helper::Utils::readBasicIniFile(std::string const&) 0x7f5595351d74 11 sofa::helper::system::FileRepository::FileRepository(const char *, const char *, std::map<std::string, std::list<std::string>> const&) 0x7f55953b8d7b 12 _GLOBAL__sub_I_FileRepository.cpp 0x7f55952d9c24 13 call_init dl-init.c 72 0x7f55981af733 14 _dl_init dl-init.c 119 0x7f55981af733 15 _dl_start_user 0x7f55981a00ca 16 ?? 0x1 17 ?? 0x7ffebb3aa75a 18 ??
It seems that the problem arises when trying to init FileRepositories, but I am not really sure if it’s just a buggy library or something else. Have anyone encountered similar behaviour? I am using SOFA v19.12, Ubuntu 18 and clang 6.0
Best regards,
Vlad6 April 2020 at 17:18 #15654bobikoBlockedIt seems that these difficulties are caused by initialization of DataRepository:
FileRepository DataRepository( "SOFA_DATA_PATH", 0, { { Utils::getSofaPathTo("etc/sofa.ini"), {"SHARE_DIR", "EXAMPLES_DIR"} } });
When I change it to:
FileRepository DataRepository( "SOFA_DATA_PATH", ".");
Everything works without segfaults. It seems that the problem is related to the zero in char* argument, but I am not entirely sure to what it should be changed.
15 April 2020 at 09:26 #15763GuillaumeKeymasterHi,
Does the problem persist if you replace the
0
withnullptr
?10 May 2020 at 22:21 #1614210 May 2020 at 23:05 #16149bobikoBlockedHi @Hugo, Hi @Guillaume,
Sorry, I haven’t tried it yet, but I am pretty sure it will do the trick. Thanks a lot!
Best regards,
Vlad7 September 2021 at 12:08 #20318bobikoBlockedHi @Hugo,
It’s been a while since I returned to this problem, but here is what I found. The bug arises from the fact that
Utils::getSofaPathTo(const std::string& pathFromBuildDir)
returns the path to the current dir if a file does not exist (including the situations whencomputeSofaPathPrefix()
returns the current path):const std::string Utils::getSofaPathTo(const std::string& pathFromBuildDir) { std::string path = Utils::getSofaPathPrefix() + "/" + pathFromBuildDir; if(FileSystem::exists(path)) { return path; } else { return Utils::getSofaPathPrefix(); } }
What happens then in the
readBasicIniFile
is that it receives the path to the current dir as the input, callsiniFile.good()
, which returns success, and then tries to read from it (the directory, not a file), which is where an exception arises:std::map<std::string, std::string> Utils::readBasicIniFile(const std::string& path) { std::map<std::string, std::string> map; std::ifstream iniFile(path.c_str()); if (!iniFile.good()) { msg_error("Utils::readBasicIniFile()") << "Error while trying to read file (" << path << ")"; } std::string line; while (std::getline(iniFile, line)) { size_t equalPos = line.find_first_of('='); if (equalPos != std::string::npos) { const std::string key = line.substr(0, equalPos); const std::string value = line.substr(equalPos + 1, std::string::npos); map[key] = value; } } return map; }
In my case,
path
is equal to/home/user/some-project-build-dir/
. What I did to solve the problem was commenting out the following lines inUtils::getSofaPathTo()
:const std::string Utils::getSofaPathTo(const std::string& pathFromBuildDir) { std::string path = Utils::getSofaPathPrefix() + "/" + pathFromBuildDir; // if(FileSystem::exists(path)) // { return path; // } // else // { // return Utils::getSofaPathPrefix(); // } }
Hope what I wrote makes sense to you 🙂
Best regards,
Vlad7 October 2021 at 11:03 #20549HugoKeymaster -
AuthorPosts
- You must be logged in to reply to this topic.