今天我已阅读{{3>}关于 GCC Undefined Behavior Sanitizer(ubsan)的信息。但是,当我按照那里的步骤(将-fsanitize=undefined
添加到我的代码中)时,编译器(UCCntu 15.04上的GCC 4.9.2)表示某些引用未定义:
||=== Build: Debug in Entangle (compiler: GNU GCC Compiler) ===|
obj/Debug/EntangleApp.o||In function `EntangleApp::OnInit()':|
/home/ilya/Projects/Entangle/EntangleApp.cpp|31|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|31|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|32|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|34|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|35|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|37|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|37|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|43|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|43|undefined reference to `__ubsan_handle_load_invalid_value'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|52|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|52|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `EntangleApp::OnCmdLineParsed(wxCmdLineParser&)':|
/home/ilya/Projects/Entangle/EntangleApp.cpp|75|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `EntangleApp::OnRun()':|
/home/ilya/Projects/Entangle/EntangleApp.cpp|128|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.cpp|128|undefined reference to `__ubsan_handle_load_invalid_value'|
obj/Debug/EntangleApp.o||In function `wxPrivate::UntypedBufferData::~UntypedBufferData()':|
/usr/include/wx-3.0/wx/buffer.h|43|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/wx-3.0/wx/buffer.h|43|undefined reference to `__ubsan_handle_load_invalid_value'|
/usr/include/wx-3.0/wx/buffer.h|44|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `std::exception::exception()':|
/usr/include/c++/4.9/exception|63|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `wxCriticalSectionLocker::wxCriticalSectionLocker(wxCriticalSection&)':|
/usr/include/wx-3.0/wx/thread.h|305|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/wx-3.0/wx/thread.h|307|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `wxCriticalSectionLocker::~wxCriticalSectionLocker()':|
/usr/include/wx-3.0/wx/thread.h|312|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o:/usr/include/wx-3.0/wx/thread.h|767|more undefined references to `__ubsan_handle_type_mismatch' follow|
obj/Debug/EntangleApp.o||In function `wxThreadHelperThread::Entry()':|
/usr/include/wx-3.0/wx/thread.h|775|undefined reference to `__ubsan_handle_load_invalid_value'|
/usr/include/wx-3.0/wx/thread.h|776|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/wx-3.0/wx/thread.h|776|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `std::type_info::name() const':|
/usr/include/c++/4.9/typeinfo|100|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/c++/4.9/typeinfo|100|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/c++/4.9/typeinfo|100|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o:/usr/include/c++/4.9/typeinfo|100|more undefined references to `__ubsan_handle_type_mismatch' follow|
obj/Debug/EntangleApp.o||In function `wxObjectEventFunctor::operator()(wxEvtHandler*, wxEvent&)':|
/usr/include/wx-3.0/wx/event.h|3757|undefined reference to `__ubsan_handle_add_overflow'|
/usr/include/wx-3.0/wx/event.h|3757|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/wx-3.0/wx/event.h|3757|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `wxLocale::wxLocale()':|
/usr/include/wx-3.0/wx/intl.h|154|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `wxAppConsoleBase::CallOnInit()':|
/usr/include/wx-3.0/wx/app.h|93|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/wx-3.0/wx/app.h|93|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o:/usr/include/wx-3.0/wx/app.h|592|more undefined references to `__ubsan_handle_type_mismatch' follow|
obj/Debug/EntangleApp.o||In function `wxAppBase::IsActive() const':|
/usr/include/wx-3.0/wx/app.h|592|undefined reference to `__ubsan_handle_load_invalid_value'|
obj/Debug/EntangleApp.o||In function `wxAppBase::SetTopWindow(wxWindow*)':|
/usr/include/wx-3.0/wx/app.h|595|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `EntangleApp::EntangleApp()':|
/home/ilya/Projects/Entangle/EntangleApp.h|19|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.h|19|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.h|19|undefined reference to `__ubsan_handle_type_mismatch'|
/home/ilya/Projects/Entangle/EntangleApp.h|19|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o:/home/ilya/Projects/Entangle/EntangleFrame.h|32|more undefined references to `__ubsan_handle_type_mismatch' follow|
obj/Debug/EntangleApp.o||In function `std::_Vector_base<unsigned long long, std::allocator<unsigned long long> >::~_Vector_base()':|
/usr/include/c++/4.9/bits/stl_vector.h|161|undefined reference to `__ubsan_handle_sub_overflow'|
/usr/include/c++/4.9/bits/stl_vector.h|161|undefined reference to `__ubsan_handle_type_mismatch'|
obj/Debug/EntangleApp.o||In function `std::_Vector_base<unsigned long long, std::allocator<unsigned long long> >::_Vector_impl::_Vector_impl()':|
/usr/include/c++/4.9/bits/stl_vector.h|87|undefined reference to `__ubsan_handle_type_mismatch'|
/usr/include/c++/4.9/bits/stl_vector.h|87|undefined reference to `__ubsan_handle_type_mismatch'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 23 second(s)) ===|
我该如何解决这个问题?
答案 0 :(得分:16)
我已安装<repositories>
<repository>
<id>wso2-maven2-repository</id>
<name>WSO2 Maven2 Repository</name>
<url>http://dist.wso2.org/maven2</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
</repositories>
和libubsan0
并添加了lib64ubsan0
选项,我的应用程序已成功编译!
答案 1 :(得分:0)
您在its new home看到的同一篇文章已经提供了答案,但是您没有注意到它……粗体:
GCC最近(版本4.9)获得了 Undefined Behavior Sanitizer (ubsan),这是C和C ++语言的运行时检查器。为了使用ubsan检查您的程序,请使用
-fsanitize=undefined
选项编译并链接该程序。
我认为解决此问题的正确方法不是手动链接ubsan
,而是简单地还将-fsanitize=undefined
传递给链接器,而不仅仅是编译器。当然,重新设计轮子可能对您有用,但这不是必需的,并且可能有一个原因是为此有一个特定的链接器标志。
可以肯定的是:我突然遇到了很多未定义的参考错误,yugr's answer here放弃了几个月之后就没有使用它,向我指出了正确的方向:我只是通过了{{1} }到-fsanitize=undefined
,但这些仅交给编译器;我还需要将其传递给meson.add_project_arguments()
。添加完之后,错误消失了,程序链接了。