Bug 407307

Summary: Intercept stpcpy also in ld.so for arm64
Product: [Developer tools] valgrind Reporter: Mark Wielaard <mark>
Component: memcheckAssignee: Julian Seward <jseward>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: 3.15 SVN   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Mark Wielaard 2019-05-07 16:17:26 UTC
On other arches stpcpy () is intercepted for both libc.so and ld.so. But not on arm64, where it is only intercepted for libc.so.

This can cause memcheck warnings about the use of stpcpy () in ld.so when called through dlopen () because ld.so contains its own copy of that functions.

==3145== Use of uninitialised value of size 8
==3145==    at 0x4018014: stpcpy (strcpy.S:158)
==3145==    by 0x4007607: _dl_dst_substitute (dl-load.c:327)
==3145==    by 0x40081EB: _dl_map_object (dl-load.c:2173)
==3145==    by 0x4011ADB: dl_open_worker (dl-open.c:217)
==3145==    by 0x4A2C047: _dl_catch_exception (dl-error-skeleton.c:196)
==3145==    by 0x40116B7: _dl_open (dl-open.c:588)
==3145==    by 0x48F1093: dlopen_doit (dlopen.c:66)
==3145==    by 0x4A2C047: _dl_catch_exception (dl-error-skeleton.c:196)
==3145==    by 0x4A2C0EF: _dl_catch_error (dl-error-skeleton.c:215)
==3145==    by 0x48F17DF: _dlerror_run (dlerror.c:163)
==3145==    by 0x48F1133: dlopen@@GLIBC_2.17 (dlopen.c:87)

The following proposed patch gets rid of this warning:

diff --git a/include/pub_tool_redir.h b/include/pub_tool_redir.h
index c97941ff4..15ba67fdb 100644
--- a/include/pub_tool_redir.h
+++ b/include/pub_tool_redir.h
@@ -313,7 +313,9 @@
 #define  VG_Z_LD_SO_1               ldZdsoZd1                  // ld.so.1
 #define  VG_U_LD_SO_1               "ld.so.1"
 
+#define  VG_Z_LD_LINUX_AARCH64_SO_1  ldZhlinuxZhaarch64ZdsoZd1
 #define  VG_U_LD_LINUX_AARCH64_SO_1 "ld-linux-aarch64.so.1"
+
 #define  VG_U_LD_LINUX_ARMHF_SO_3   "ld-linux-armhf.so.3"
 
 #endif
diff --git a/shared/vg_replace_strmem.c b/shared/vg_replace_strmem.c
index 89a7dccb7..19143cf15 100644
--- a/shared/vg_replace_strmem.c
+++ b/shared/vg_replace_strmem.c
@@ -1160,6 +1160,7 @@ static inline void my_exit ( int x )
  STPCPY(VG_Z_LIBC_SONAME,          __stpcpy_sse2_unaligned)
  STPCPY(VG_Z_LD_LINUX_SO_2,        stpcpy)
  STPCPY(VG_Z_LD_LINUX_X86_64_SO_2, stpcpy)
+ STPCPY(VG_Z_LD_LINUX_AARCH64_SO_1,stpcpy)
 
 #elif defined(VGO_darwin)
  //STPCPY(VG_Z_LIBC_SONAME,          stpcpy)
Comment 1 Mark Wielaard 2019-05-07 19:23:15 UTC
Briefly discussed on irc and now committed as:

commit 89423f5d8ba05a099c2c62227a00a4f4eec59eb3
Author: Mark Wielaard <mark@klomp.org>
Date:   Tue May 7 21:20:04 2019 +0200

    Intercept stpcpy also in ld.so for arm64
    
    On other arches stpcpy () is intercepted for both libc.so and ld.so.
    But not on arm64, where it is only intercepted for libc.so.
    
    This can cause memcheck warnings about the use of stpcpy () in ld.so
    when called through dlopen () because ld.so contains its own copy of
    that functions.
    
    Fix by introducing VG_Z_LD_LINUX_AARCH64_SO_1 (the encoded name of
    ld.so on arm64) and using that in vg_replace_strmem.c to intercept
    stpcpy.
    
    https://bugs.kde.org/show_bug.cgi?id=407307