问题 Valgrind和“警告:新的重定向与现有的冲突”


我在Valgrind得到这个。

--24101-- REDIR: 0xbb20580 (operator delete(void*)) redirected to 0x93b7d48 (operator delete(void*))
--24101-- REDIR: 0xbb22580 (operator new[](unsigned long)) redirected to 0x93b88b7 (operator new[](unsigned long))
==24101== WARNING: new redirection conflicts with existing -- ignoring it
--24101--     new: 0x15632010 (__GI_strlen         ) R-> 0x093b96b0 strlen
--24101-- REDIR: 0xbb205c0 (operator delete[](void*)) redirected to 0x93b79c4 (operator delete[](void*))

有什么顾虑吗?


13138
2017-07-23 23:37


起源

我会忽略这些警告。即使在跑步时也会显示它们 valgrind 在最小的 int main(){} 程序。我不确定 为什么 这恰好发生了。 BTW在我的机器上 valgrind 警告 index不是 strlen。也许这取决于你的 libc 版。 - n.m.


答案:


Valgrind的神奇之处在于它如何拦截/重定向函数调用以跟踪世界状态。

据我了解,重定向是使用共享对象/函数名称模式实现的,当匹配“重定向”调用新地址时。检查valgrind源代码,我们发现了'重定向器'的概念:

The redirector holds two pieces of state:

Specs  - a set of   (soname pattern, fnname pattern) -> redir addr
Active - a set of   orig addr -> (bool, redir addr)

(m_redir.c第104行)

所以'Specs'提供共享对象/函数名称来映射映射,'Actives'代表映射本身。

主动计算:

Active = empty
for spec in Specs {
   sopatt = spec.soname pattern
   fnpatt = spec.fnname pattern
   redir  = spec.redir addr
   for so matching sopatt in SyminfoState {
      for fn matching fnpatt in fnnames_of(so) {
         &fn -> redir is added to Active
      }
   }
}

(m_redir.c第120行)

这里也提到了“冲突重定向”的想法:

Clearly we must impose the requirement that domain(Active) contains
no duplicates.  The difficulty is how to constrain Specs enough to
avoid getting into that situation.  It's easy to write specs which
could cause conflicting bindings in Active, eg:

   (libpthread.so, pthread_mutex_lock) ->    a1
   (libpthread.so, pthread_*)          ->    a2

for a1 != a2.  Or even hairier:

   (libpthread.so, pthread_mutex_*) ->    a1
   (libpthread.so, pthread_*_lock)  ->    a2

(m_redir.c第152行)

为了利益,这里是您生成警告的地方:

old = VG_(OSetGen_Lookup)( activeSet, &act.from_addr );
if (old) {
   /* Dodgy.  Conflicting binding. */
   vg_assert(old->from_addr == act.from_addr);
   if (old->to_addr != act.to_addr) {
      /* we have to ignore it -- otherwise activeSet would contain
         conflicting bindings. */
      what = "new redirection conflicts with existing -- ignoring it";
      goto bad;
   } 

(m_redir.c第664行)

因此,在所有这些之后,可以安全地假设:

  1. 重定向消息是正常valgrind操作的一部分。
  2. 警告消息可能是规范模式冲突的结果(在这种情况下可能不是引起关注的重要原因。)

参考文献: Valgrind手册Valgrind 3.6.1来源


15
2017-07-24 06:08



请注意,当我像这样使用valgrind时,我得到了这些: valgrind --leak-check=full -v ./your_program。如果我删除了 -v,我没有收到它们。非常好,有这个问题和答案,勇敢的家伙! :)我的意思是我很困惑发生了什么! - gsamaras