预加载自定义strchr() – ubuntu崩溃

我实现了strchr()

global strchr strchr: cmp byte[rdi], 0 je end cmp [rdi], sil je end add rdi, 1 jmp strchr end: mov rax, rdi ret 

当我把它预加载为.so使用,

 export LD_PRELOAD=abs/path/to/lib.so 

Ubuntu 16.04崩溃。 有时它完全是crahses,有时它显示SIGILL(损坏的数据?)。

当我预载使用opensuse 4,它的工作原理。

任何想法为什么?

感谢Michael Petch:

该strchr()不符合手动,因为它没有找到字符时不返回NULL。

修正了strchr():

 global strchr strchr: cmp [rdi], sil;first check for character (useful if user searches '\0') je end cmp byte[rdi], 0;then if it is EoS and the character is not in the string, return NULL je eos add rdi, 1 jmp strchr eos: mov rax, 0 ret end: mov rax, rdi ret