2013-09-21 35 views
6

我有一個安裝了Boost C++庫的最新SVN版本的Ubuntu 13.04系統。 Boost安裝使用系統的本地版本gcc版本v4.7.3構建。我非常廣泛地使用Boost,當我使用gcc編譯時,它工作得非常好;我已經使用了其中的很多,包括Boost.Thread(我將在下面討論更多),沒有任何問題。在將gcc構建的Boost鏈接到Intel C++編譯的程序時進行靜態初始化時的Segfault

如果我嘗試使用英特爾C++編譯器(我個人使用v13.x系列中的幾個不同版本)與已安裝的Boost庫鏈接來構建程序,則會出現此問題。當我這樣做時,程序啓動後立即出現分段錯誤;它似乎發生在Boost.Thread庫的靜態初始化期間。這裏有一個簡單的例子程序:

#include <boost/version.hpp> 
#include <boost/thread.hpp> 

int main() 
{ 
    boost::this_thread::sleep(boost::posix_time::seconds(1)); 
} 

我編譯它採用了Intel C++:

icpc test.cc -lboost_thread -lboost_system -I/path/to/boost/inc/dir -L/path/to/boost/lib/dir 

正如我所說的,當我運行生成的程序,我得到一個近乎即時段錯誤。通過gdb,從段錯誤點的堆棧跟蹤如下:

#0 0x00007ffff79b6351 in boost::exception_ptr boost::exception_detail::get_static_exception_object<boost::exception_detail::bad_exception_>()() from ./libboost_thread.so.1.55.0 
#1 0x00007ffff79b02e1 in _GLOBAL__sub_I_thread.cpp() from ./libboost_thread.so.1.55.0 
#2 0x00007ffff7de9876 in call_init ([email protected]=0x7ffff7ff9a10, [email protected]=1, 
    [email protected]=0x7fffffffe0b8, [email protected]=0x7fffffffe0c8) at dl-init.c:84 
#3 0x00007ffff7de9930 in call_init (env=<optimized out>, argv=<optimized out>, 
    argc=<optimized out>, l=0x7ffff7ff9a10) at dl-init.c:55 
#4 _dl_init (main_map=0x7ffff7ffe268, argc=1, argv=0x7fffffffe0b8, env=0x7fffffffe0c8) 
    at dl-init.c:133 
#5 0x00007ffff7ddb68a in _dl_start_user() from /lib64/ld-linux-x86-64.so.2 
#6 0x0000000000000001 in ??() 
#7 0x00007fffffffe391 in ??() 
#8 0x0000000000000000 in ??() 

不是很有啓發性,但它的libboost_thread.so初始化過程中清楚地死去。如果我重建加速,包括調試符號,然後我得到一個稍微好一點的畫面:

#0 shared_count (r=..., this=0x7ffff7bbc5f8 <boost::exception_ptr boost::exception_detail::get_static_exception_object<boost::exception_detail::bad_exception_>()::ep+8>) 
    at ./boost/smart_ptr/shared_ptr.hpp:328 
#1 shared_ptr (this=0x7ffff7bbc5f0 <boost::exception_ptr boost::exception_detail::get_static_exception_object<boost::exception_detail::bad_exception_>()::ep>) at ./boost/smart_ptr/shared_ptr.hpp:328 
#2 exception_ptr (ptr=..., this=0x7ffff7bbc5f0 <boost::exception_ptr boost::exception_detail::get_static_exception_object<boost::exception_detail::bad_exception_>()::ep>) 
    at ./boost/exception/detail/exception_ptr.hpp:53 
#3 boost::exception_detail::get_static_exception_object<boost::exception_detail::bad_exception_>() at ./boost/exception/detail/exception_ptr.hpp:130 
#4 0x00007ffff79b02e1 in __static_initialization_and_destruction_0 (__initialize_p=<optimized out>, __priority=<optimized out>) at ./boost/exception/detail/exception_ptr.hpp:143 
#5 _GLOBAL__sub_I_thread.cpp(void)() at libs/thread/src/pthread/thread.cpp:767 
#6 0x00007ffff7de9876 in call_init ([email protected]=0x7ffff7ff9a10, [email protected]=1, [email protected]=0x7fffffffe0b8, [email protected]=0x7fffffffe0c8) at dl-init.c:84 
#7 0x00007ffff7de9930 in call_init (env=<optimized out>, argv=<optimized out>, argc=<optimized out>, l=0x7ffff7ff9a10) at dl-init.c:55 
#8 _dl_init (main_map=0x7ffff7ffe268, argc=1, argv=0x7fffffffe0b8, env=0x7fffffffe0c8) at dl-init.c:133 
#9 0x00007ffff7ddb68a in _dl_start_user() from /lib64/ld-linux-x86-64.so.2 
#10 0x0000000000000001 in ??() 
#11 0x00007fffffffe391 in ??() 
#12 0x0000000000000000 in ??() 

這是我不清楚什麼靜態/全局對象是導致發生問題,所以我不知道如何着手。我在v13.x系列中使用了許多Boost版本和幾個不同版本的Intel C++編譯器,這是我目前唯一可以訪問的版本。我已經嘗試了每個編譯器的排列(即我已經用gccicpc構建了Boost,並且我也構建了我的測試應用程序);唯一的排列失敗的地方是使用gcc構建Boost,而我的測試應用程序使用icpc構建。在其他情況下,測試應用程序運行成功。

雖這麼說,你可能會導致明顯的答案:

  • 爲什麼不直接使用重建和icpc收工加速?鑑於我的實驗,這種方法似乎很有效,但我有客戶喜歡使用icpc來構建我的軟件。這些相同的客戶可能會安裝Linux發行版提供的Boost軟件包;他們無法控制用於生成該程序包的構建環境(而且,很可能無論如何它都是使用gcc編譯的)。因此,如果可以支持這種混合編譯器配置,那將是最佳的。

有沒有人有任何關於如何解決這個靜態初始化問題的建議?

+0

我真的不知道icpc,但你有沒有嘗試與pthread鏈接?只是一個瘋狂的猜測。 – PeterT

回答

4

這是一個長鏡頭,但...如果你有一個不同的g++PATH比用於構建Boost庫,擺脫它或通過-gxx-name /usr/bin/g++icpc之一。 (英特爾編譯器自行適應它認爲您正在使用的GCC版本。-gxx-name可讓您強制執行該問題。)

好吧,可能沒有幫助。

Ubuntu 13.04在英特爾Composer XE 2013 SP1之前不受支持。編譯器版本14.0.0。請參閱"System Requirements" section of the Release Notes並將其與same section for the last 13.x release進行比較。

英特爾絕對的目標是與GCC鏈接兼容。如果您可以在全新安裝的受支持版本的Linux上重現此問題,則應該能夠提交支持服務單並將其修復。

+0

感謝您的提示。我目前只能訪問v13.x,所以我會嘗試在支持的平臺上覆制它,看看是否有幫助。 –

+1

我能夠使用Ubuntu 12.04(它是一個受支持的平臺)複製v13.0.1上的問題。我想我應該嘗試將它作爲一個錯誤報告給Intel。 –

+2

@JasonR:我會的。請注意,閱讀報告的第一個人將是一個「1級」無人機,因此您的目標是說服他們這是一個真正的錯誤,這樣他們會將您打倒在鏈條上。保持簡短,提供最小的測試用例,並提供非常直接的「重現步驟」。自從LTS發佈以來,Ubuntu 12.04就不錯。祝你好運 :-)。 – Nemo

相關問題