链接libboost_log.so使boost :: asio :: io_service :: run立即退出 [英] Linking libboost_log.so makes boost::asio::io_service::run exit immediately

查看:71
本文介绍了链接libboost_log.so使boost :: asio :: io_service :: run立即退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是设置:

boost1::asio::io_service         _ios;
boost::asio::ip::tcp::acceptor  _acceptor;`
...
_acceptor(_ios)
...
boost::system::error_code ec;
int rc = _ios.run(ec);

使用gdb,我看到运行调用跳入boost :: asio :: impl :: io_service :: run
这有一点好处

with gdb I see that run call jump into boost::asio::impl::io_service::run
Here is a bit of boost

boost/asio/impl/io_service.ipp:

boost/asio/impl/io_service.ipp:

std::size_t io_service::run(boost::system::error_code& ec)
{
  return impl_.run(ec);
}

这里证明impl_是Linux情况下的task_io_service.

Here is proof that impl_ is task_io_service for linux case.

boost/boost/asio/io_service.hpp

boost/boost/asio/io_service.hpp

#if defined(BOOST_ASIO_HAS_IOCP)
namespace detail { typedef win_iocp_io_service io_service_impl; }
#else
namespace detail { typedef task_io_service io_service_impl; }
#endif

...

private:
  typedef detail::io_service_impl impl_type;
#if defined(BOOST_ASIO_HAS_IOCP)
  friend class detail::win_iocp_overlapped_ptr;
#endif

...

impl_type& impl_;

如果在编译过程中未链接-lboost_log,则将解析impl_run调用(通过plt存根调用,ld_trampoline.S dl-runtime_resolve和dl-runtime.c _dl_fixup)来增强::: asio :: detail :: impl:: task_io_service ::在我的二进制文件中运行,run()开始等待受体提供的工作.

If I don't link -lboost_log during compilation, then impl_run call is resolved (through plt stub call, ld_trampoline.S dl-runtime_resolve and dl-runtime.c _dl_fixup) to boost::asio::detail::impl::task_io_service::run in my binary and run() starts waiting for work provided by acceptor.

如果我确实通过GDB进行链接增强,则可以看到此调用被解析为libboost_log.so符号_ZN5boost4asio6detail15task_io_service3runERNS_6system10error_codeE,并且退出几乎立即运行.

If I do link boost, through GDB i see this call to be resolved to libboost_log.so symbol _ZN5boost4asio6detail15task_io_service3runERNS_6system10error_codeE and exits run nearly immediately.

nm -D libboost_log.so确认符号在那里,这不是我的链接问题.

nm -D libboost_log.so confirms that the symbol is there and it is not my linking issue.

为什么在libboost_log.so中此task_io_service3run符号?好像是增强错误,不是吗?有什么方法可以确保预期的方法解析?

Why is this task_io_service3run symbol in libboost_log.so? It seems like boost bug, doesn't it? Are there ways to ensure intended method resolution?

推荐答案

简而言之,Linux上的运行时符号解析在符号可见性方面起作用.如果在您的应用程序加载的一个或几个共享对象中外部可见某个符号,则运行时链接程序可以自由选择任何一种实现,并在所有其他共享对象中使用它.这非常类似于编译时链接过程,并且它允许保留几种语言规则(例如,在程序中的任何地方,获取函数的地址必须产生相同的地址).

In a nutshell, runtime symbol resolution on Linux works in terms of symbol visibility. If a symbol is externally visible in one or several of the shared objects that are loaded with your application then the runtime linker is free to choose any one of the implementations and use it in all other shared objects. This is very much like the compile time linking process and it allows for several language rules to hold (for example, taking address of a function must yield the same address, wherever in the program that address is taken).

Boost.Log确实确实使用Boost.ASIO来实现其某些功能(尤其是基于网络的syslog接收器).Boost.ASIO将其符号标记为在外部可见,因此它们将从Boost.Log共享对象中导出.

Boost.Log does indeed use Boost.ASIO to implement some of its features (network-based syslog sink, in particular). Boost.ASIO marks its symbols as externally visible, so they are exported from Boost.Log shared object.

现在,Boost.ASIO不再使用ABI命名空间或任何其他技术来使符号名称根据库版本或配置而有所不同.这意味着任何使用Boost.Log和Boost.ASIO的应用程序或库都必须使用相同版本的Boost.ASIO,并且配置方式与构建Boost.Log时配置的方式相同.否则,由于ABI不兼容,您可能会在您或Boost.Log使用Boost.ASIO时观察到各种未定义的行为.我怀疑这可能是您遇到问题的原因.

Now Boost.ASIO does not use an ABI namespace or any other technique to make the symbol names different depending on the library version or configuration. It means that any application or library that uses Boost.Log and Boost.ASIO must be using the same version of Boost.ASIO, configured the same way as it was configured when building Boost.Log. Otherwise due to ABI incompatibilities you may observe all kinds of undefined behavior in your or Boost.Log's use of Boost.ASIO. I suspect this might be the reason why you could be having problems.

在构建代码和Boost.Log时,请检查是否使用了相同版本的Boost.ASIO.在两种情况下,请检查是否以相同的方式定义了所有宏.检查是否正在使用任何与ABI相关的编译器开关.

Check that you're using the same version of Boost.ASIO when building your code and Boost.Log. Check that all macros are defined the same way in both cases. Check if you're using any ABI-related compiler switches.

这篇关于链接libboost_log.so使boost :: asio :: io_service :: run立即退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆