Skip to content

Commit a0c44fb

Browse files
committed
Always define valgrind replacement symbol for zend_string_equal_val
The required symbol name seems to be very stable, so we can hardcode a fallback. This avoids many false positives when PHP is not built against valgrind.
1 parent 1bfaba4 commit a0c44fb

File tree

1 file changed

+11
-61
lines changed

1 file changed

+11
-61
lines changed

Zend/zend_string.c

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,17 @@ ZEND_API void zend_interned_strings_switch_storage(bool request)
324324
}
325325
}
326326

327+
/* Even if we don't build with valgrind support, include the symbol so that valgrind available
328+
* only at runtime will not result in false positives. */
329+
#ifndef HAVE_VALGRIND
330+
# define I_REPLACE_SONAME_FNNAME_ZU(soname, fnname) _vgr00000ZU_ ## soname ## _ ## fnname
331+
#endif
332+
333+
ZEND_API bool ZEND_FASTCALL I_REPLACE_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
334+
{
335+
return !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1));
336+
}
337+
327338
#if defined(__GNUC__) && defined(__i386__)
328339
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2)
329340
{
@@ -362,36 +373,6 @@ ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *
362373
return ret;
363374
}
364375

365-
#ifdef HAVE_VALGRIND
366-
ZEND_API bool ZEND_FASTCALL I_WRAP_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
367-
{
368-
size_t len = ZSTR_LEN(s1);
369-
char *ptr1 = ZSTR_VAL(s1);
370-
char *ptr2 = ZSTR_VAL(s2);
371-
zend_ulong ret;
372-
373-
__asm__ (
374-
"test %1, %1\n\t"
375-
"jnz .LL1%=\n\t"
376-
"movl $0x1, %0\n\t"
377-
"jmp .LL2%=\n\t"
378-
".LL1%=:\n\t"
379-
"cld\n\t"
380-
"rep\n\t"
381-
"cmpsb\n\t"
382-
"sete %b0\n\t"
383-
"movzbl %b0, %0\n\t"
384-
".LL2%=:\n"
385-
: "=a"(ret),
386-
"+c"(len),
387-
"+D"(ptr1),
388-
"+S"(ptr2)
389-
:
390-
: "cc");
391-
return ret;
392-
}
393-
#endif
394-
395376
#elif defined(__GNUC__) && defined(__x86_64__) && !defined(__ILP32__)
396377
ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *s2)
397378
{
@@ -429,37 +410,6 @@ ZEND_API bool ZEND_FASTCALL zend_string_equal_val(zend_string *s1, zend_string *
429410
: "cc");
430411
return ret;
431412
}
432-
433-
#ifdef HAVE_VALGRIND
434-
ZEND_API bool ZEND_FASTCALL I_WRAP_SONAME_FNNAME_ZU(NONE,zend_string_equal_val)(zend_string *s1, zend_string *s2)
435-
{
436-
size_t len = ZSTR_LEN(s1);
437-
char *ptr1 = ZSTR_VAL(s1);
438-
char *ptr2 = ZSTR_VAL(s2);
439-
zend_ulong ret;
440-
441-
__asm__ (
442-
"test %1, %1\n\t"
443-
"jnz .LL1%=\n\t"
444-
"movq $0x1, %0\n\t"
445-
"jmp .LL2%=\n\t"
446-
".LL1%=:\n\t"
447-
"cld\n\t"
448-
"rep\n\t"
449-
"cmpsb\n\t"
450-
"sete %b0\n\t"
451-
"movzbq %b0, %0\n\t"
452-
".LL2%=:\n"
453-
: "=a"(ret),
454-
"+c"(len),
455-
"+D"(ptr1),
456-
"+S"(ptr2)
457-
:
458-
: "cc");
459-
return ret;
460-
}
461-
#endif
462-
463413
#endif
464414

465415
ZEND_API zend_string *zend_string_concat2(

0 commit comments

Comments
 (0)