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)
所以「規格」提供共享對象/函數名地址映射和「活性物質'代表映射本身。
主動運算:
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)
所以,畢竟這很可能是安全的假設:
- 重定向消息是正常的valgrind操作的一部分。
- 警告消息可能是相互衝突的規範模式的結果
引用(可能不適合在這種情況非常令人擔憂。):Valgrind manual,Valgrind 3.6.1 source
我會忽略這些警告。即使在最小的'int main(){}'程序中運行'valgrind',它們也會顯示出來。我不確定_why_究竟發生了什麼。順便說一下,在我的機器上'valgrind'會警告'index',而不是'strlen'。也許這取決於你的'libc'版本。 –