Re: [PATCH] Valgrind print symbol of ld.so
From: Masato Asou Date: Fri, 03 Apr 2020 15:24:44 +0900 (JST) > Sorry, this patch is not correct. I'm canceling this patch. I'll > consder it again. > > From: Masato Asou > Date: Fri, 03 Apr 2020 12:24:32 +0900 (JST) > >> Hello, >> >> I made patch for print symbold of ld.so, if error was occured as >> below: I was corrected previous patch. ok? Index: Makefile === RCS file: /cvs/ports/devel/valgrind/Makefile,v retrieving revision 1.23 diff -u -p -r1.23 Makefile --- Makefile23 Dec 2019 23:26:32 - 1.23 +++ Makefile7 Apr 2020 00:21:47 - @@ -7,7 +7,7 @@ CATEGORIES =devel V =3.10.1 PV = 20160331 -REVISION = 16 +REVISION = 17 DISTNAME = valgrind-${V} EXTRACT_SUFX = .tar.bz2 Index: patches/patch-coregrind_m_libcfile_c === RCS file: patches/patch-coregrind_m_libcfile_c diff -N patches/patch-coregrind_m_libcfile_c --- /dev/null 1 Jan 1970 00:00:00 - +++ patches/patch-coregrind_m_libcfile_c7 Apr 2020 00:21:47 - @@ -0,0 +1,39 @@ +$OpenBSD$ + +--- coregrind/m_libcfile.c.orig coregrind/m_libcfile.c +@@ -40,6 +40,9 @@ + #include "pub_core_xarray.h" + #include "pub_core_clientstate.h" // VG_(fd_hard_limit) + #include "pub_core_syscall.h" ++#if defined(VGO_openbsd) ++#include "pub_core_syswrap.h" ++#endif + + /* IMPORTANT: on Darwin it is essential to use the _nocancel versions +of syscalls rather than the vanilla version, if a _nocancel version +@@ -174,6 +177,14 @@ + # elif defined(VGO_linux) || defined(VGO_freebsd) || defined(VGO_openbsd) +SysRes res = VG_(do_syscall3)(__NR_open, + (UWord)pathname, flags, mode); ++#if defined(VGO_openbsd) ++ // Track opened files by Valgrind so that we can look up filenames for ++ // mapped vnodes via the recorded table, instead of relying on procfs or ++ // kvm. This is possible as all executables and related files (dynamic ++ // linkder etc.) are all opened by host (Valgrind). ++ VG_(record_fd_open_with_given_name)(-1, sr_Res(res), (char *)pathname); ++ VG_(mark_fd_as_internal)(-1, sr_Res(res)); ++#endif + # elif defined(VGO_darwin) +SysRes res = VG_(do_syscall3)(__NR_open_nocancel, + (UWord)pathname, flags, mode); +@@ -198,6 +209,9 @@ +/* Hmm. Return value is not checked. That's uncool. */ + # if defined(VGO_linux) || defined(VGO_freebsd) || defined(VGO_openbsd) +(void)VG_(do_syscall1)(__NR_close, fd); ++#if defined(VGO_openbsd) ++ VG_(record_fd_close)(fd); ++#endif + # elif defined(VGO_darwin) +(void)VG_(do_syscall1)(__NR_close_nocancel, fd); + # else Index: patches/patch-coregrind_m_main_c === RCS file: /cvs/ports/devel/valgrind/patches/patch-coregrind_m_main_c,v retrieving revision 1.3 diff -u -p -r1.3 patch-coregrind_m_main_c --- patches/patch-coregrind_m_main_c2 Oct 2019 17:19:29 - 1.3 +++ patches/patch-coregrind_m_main_c7 Apr 2020 00:21:47 - @@ -71,7 +71,24 @@ Index: coregrind/m_main.c // Get the current process stack rlimit. VG_(getrlimit)(VKI_RLIMIT_STACK, _(client_rlimit_stack)); -@@ -2433,6 +2468,10 @@ +@@ -1834,7 +1869,16 @@ +// Set default vex control params +LibVEX_default_VexControl(& VG_(clo_vex_control)); + ++#if defined(VGO_openbsd) +//-- ++ // setup file descriptors ++ // p: n/a ++ //-- ++ VG_(debugLog)(1, "main", "Setup file descriptors\n"); ++ setup_file_descriptors(); ++#endif ++ ++ //-- +// Load client executable, finding in $PATH if necessary +// p: early_process_cmd_line_options() [for 'exec', 'need_help', +// clo_max_stackframe, +@@ -2433,6 +2477,10 @@ VG_(address_of_m_main_shutdown_actions_NORETURN) = & shutdown_actions_NORETURN; @@ -82,7 +99,7 @@ Index: coregrind/m_main.c /* Run the first thread, eventually ending up at the continuation address. */ VG_(main_thread_wrapper_NORETURN)(1); -@@ -3159,6 +3198,8 @@ +@@ -3159,6 +3207,8 @@ "__start:\n" /* pass args (long argc, char **argv, ...) on stack */ "\tmovq %rsp, %rdi\n" @@ -91,7 +108,7 @@ Index: coregrind/m_main.c /* set up the new stack in %rsi */ "\tmovq $vgPlain_interim_stack, %rsi\n" "\taddq $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %rsi\n" -@@ -3166,6 +3207,9 @@ +@@ -3166,6 +3216,9 @@ "\tandq $~15, %rsi\n" /* install it, and collect the original one */ "\txchgq %rsi, %rsp\n" @@ -101,7 +118,7 @@ Index: coregrind/m_main.c /* call
Re: [PATCH] Valgrind print symbol of ld.so
Sorry, this patch is not correct. I'm canceling this patch. I'll consder it again. -- ASOU Masato From: Masato Asou Date: Fri, 03 Apr 2020 12:24:32 +0900 (JST) > Hello, > > I made patch for print symbold of ld.so, if error was occured as > below: > > > Before apply this patch: > $ valgrind ./a.out > ==62211== Memcheck, a memory error detector > ==62211== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et > al. > ==62211== Using Valgrind-3.10.1 and LibVEX; rerun with -h for > copyright info > ==62211== Command: ./a.out > ==62211== > ==62211== Invalid write of size 1 > ==62211==at 0x4108E72: ??? > ==62211==by 0x4108374: ??? > ==62211==by 0x41096FA: ??? > ==62211==by 0x4102D4E: ??? > ==62211==by 0x4103986: ??? > ==62211==by 0x4104535: ??? > ==62211== Address 0x40052a0 is not stack'd, malloc'd or (recently) free'd > ==62211== > > > > > After apply this patch: > $ valgrind ./a.out > ==81691== Memcheck, a memory error detector > ==81691== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et > al. > ==81691== Using Valgrind-3.10.1 and LibVEX; rerun with -h for > copyright info > ==81691== Command: ./a.out > ==81691== > ==81691== Invalid write of size 1 > ==81691==at 0x4108E72: chacha_encrypt_bytes (chacha_private.h:191) > ==81691==by 0x4108374: _dl_arc4randombuf (util.c:98) > ==81691==by 0x41096FA: rbytes_init (malloc.c:187) > ==81691==by 0x4102D4E: _dl_malloc_init (in /usr/libexec/ld.so) > ==81691==by 0x4103986: _dl_boot (in /usr/libexec/ld.so) > ==81691==by 0x4104535: _dl_start (in /usr/libexec/ld.so) > ==81691== Address 0x40053e0 is not stack'd, malloc'd or (recently) free'd > ==81691== > > > > Regards > > Index: Makefile > === > RCS file: /cvs/ports/devel/valgrind/Makefile,v > retrieving revision 1.23 > diff -u -p -r1.23 Makefile > --- Makefile 23 Dec 2019 23:26:32 - 1.23 > +++ Makefile 3 Apr 2020 03:12:38 - > @@ -7,7 +7,7 @@ CATEGORIES = devel > > V = 3.10.1 > PV = 20160331 > -REVISION = 16 > +REVISION = 17 > DISTNAME = valgrind-${V} > EXTRACT_SUFX = .tar.bz2 > > Index: patches/patch-coregrind_m_libcfile_c > === > RCS file: patches/patch-coregrind_m_libcfile_c > diff -N patches/patch-coregrind_m_libcfile_c > --- /dev/null 1 Jan 1970 00:00:00 - > +++ patches/patch-coregrind_m_libcfile_c 3 Apr 2020 03:12:38 - > @@ -0,0 +1,129 @@ > +--- coregrind/m_libcfile.c > coregrind/m_libcfile.c > +@@ -40,6 +40,9 @@ > + #include "pub_core_xarray.h" > + #include "pub_core_clientstate.h" // VG_(fd_hard_limit) > + #include "pub_core_syscall.h" > ++#if defined(VGO_openbsd) > ++#include "pub_core_mallocfree.h" > ++#endif > + > + /* IMPORTANT: on Darwin it is essential to use the _nocancel versions > +of syscalls rather than the vanilla version, if a _nocancel version > +@@ -165,6 +168,90 @@ > + } > + #endif > + > ++#if defined(VGO_openbsd) > ++/* - > ++ File-descriptor tracking > ++ -- */ > ++ > ++/* One of these is allocated for each open file descriptor. */ > ++typedef struct OpenFd > ++{ > ++ Int fd;/* The file descriptor */ > ++ HChar *pathname; /* NULL if not a regular file or unknown > */ > ++ struct OpenFd *next, *prev; > ++} OpenFd; > ++ > ++/* List of allocated file descriptors. */ > ++static OpenFd *opened_fds = NULL; > ++ > ++/* Note the fact that a file descriptor was just closed. */ > ++static > ++void delete_fd(Int fd) > ++{ > ++ OpenFd *i = opened_fds; > ++ > ++ while(i) { > ++ if(i->fd == fd) { > ++ if(i->prev) > ++i->prev->next = i->next; > ++ else > ++opened_fds = i->next; > ++ if(i->next) > ++i->next->prev = i->prev; > ++ if(i->pathname) > ++VG_(arena_free) (VG_AR_CORE, i->pathname); > ++ VG_(arena_free) (VG_AR_CORE, i); > ++ break; > ++ } > ++ i = i->next; > ++ } > ++} > ++ > ++/* Note the fact that a file descriptor was just opened. */ > ++static > ++void register_fd(Int fd, const HChar *pathname) > ++{ > ++ OpenFd *i; > ++ > ++ /* Check to see if this fd is already open. */ > ++ i = opened_fds; > ++ while (i) { > ++ if (i->fd == fd) { > ++ if (i->pathname) VG_(arena_free)(VG_AR_CORE, i->pathname); > ++ break; > ++ } > ++ i = i->next; > ++ } > ++ > ++ /* Not already one: allocate an OpenFd */ > ++ if (i == NULL) { > ++ i = VG_(arena_malloc)(VG_AR_CORE, "libcfile.regfd.1", sizeof(OpenFd)); > ++ > ++ i->prev = NULL; > ++ i->next = opened_fds; > ++ if(opened_fds) opened_fds->prev = i; > ++ opened_fds = i;
[PATCH] Valgrind print symbol of ld.so
Hello, I made patch for print symbold of ld.so, if error was occured as below: Before apply this patch: $ valgrind ./a.out ==62211== Memcheck, a memory error detector ==62211== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==62211== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==62211== Command: ./a.out ==62211== ==62211== Invalid write of size 1 ==62211==at 0x4108E72: ??? ==62211==by 0x4108374: ??? ==62211==by 0x41096FA: ??? ==62211==by 0x4102D4E: ??? ==62211==by 0x4103986: ??? ==62211==by 0x4104535: ??? ==62211== Address 0x40052a0 is not stack'd, malloc'd or (recently) free'd ==62211== After apply this patch: $ valgrind ./a.out ==81691== Memcheck, a memory error detector ==81691== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==81691== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info ==81691== Command: ./a.out ==81691== ==81691== Invalid write of size 1 ==81691==at 0x4108E72: chacha_encrypt_bytes (chacha_private.h:191) ==81691==by 0x4108374: _dl_arc4randombuf (util.c:98) ==81691==by 0x41096FA: rbytes_init (malloc.c:187) ==81691==by 0x4102D4E: _dl_malloc_init (in /usr/libexec/ld.so) ==81691==by 0x4103986: _dl_boot (in /usr/libexec/ld.so) ==81691==by 0x4104535: _dl_start (in /usr/libexec/ld.so) ==81691== Address 0x40053e0 is not stack'd, malloc'd or (recently) free'd ==81691== Regards Index: Makefile === RCS file: /cvs/ports/devel/valgrind/Makefile,v retrieving revision 1.23 diff -u -p -r1.23 Makefile --- Makefile23 Dec 2019 23:26:32 - 1.23 +++ Makefile3 Apr 2020 03:12:38 - @@ -7,7 +7,7 @@ CATEGORIES =devel V =3.10.1 PV = 20160331 -REVISION = 16 +REVISION = 17 DISTNAME = valgrind-${V} EXTRACT_SUFX = .tar.bz2 Index: patches/patch-coregrind_m_libcfile_c === RCS file: patches/patch-coregrind_m_libcfile_c diff -N patches/patch-coregrind_m_libcfile_c --- /dev/null 1 Jan 1970 00:00:00 - +++ patches/patch-coregrind_m_libcfile_c3 Apr 2020 03:12:38 - @@ -0,0 +1,129 @@ +--- coregrind/m_libcfile.c coregrind/m_libcfile.c +@@ -40,6 +40,9 @@ + #include "pub_core_xarray.h" + #include "pub_core_clientstate.h" // VG_(fd_hard_limit) + #include "pub_core_syscall.h" ++#if defined(VGO_openbsd) ++#include "pub_core_mallocfree.h" ++#endif + + /* IMPORTANT: on Darwin it is essential to use the _nocancel versions +of syscalls rather than the vanilla version, if a _nocancel version +@@ -165,6 +168,90 @@ + } + #endif + ++#if defined(VGO_openbsd) ++/* - ++ File-descriptor tracking ++ -- */ ++ ++/* One of these is allocated for each open file descriptor. */ ++typedef struct OpenFd ++{ ++ Int fd;/* The file descriptor */ ++ HChar *pathname; /* NULL if not a regular file or unknown */ ++ struct OpenFd *next, *prev; ++} OpenFd; ++ ++/* List of allocated file descriptors. */ ++static OpenFd *opened_fds = NULL; ++ ++/* Note the fact that a file descriptor was just closed. */ ++static ++void delete_fd(Int fd) ++{ ++ OpenFd *i = opened_fds; ++ ++ while(i) { ++ if(i->fd == fd) { ++ if(i->prev) ++i->prev->next = i->next; ++ else ++opened_fds = i->next; ++ if(i->next) ++i->next->prev = i->prev; ++ if(i->pathname) ++VG_(arena_free) (VG_AR_CORE, i->pathname); ++ VG_(arena_free) (VG_AR_CORE, i); ++ break; ++ } ++ i = i->next; ++ } ++} ++ ++/* Note the fact that a file descriptor was just opened. */ ++static ++void register_fd(Int fd, const HChar *pathname) ++{ ++ OpenFd *i; ++ ++ /* Check to see if this fd is already open. */ ++ i = opened_fds; ++ while (i) { ++ if (i->fd == fd) { ++ if (i->pathname) VG_(arena_free)(VG_AR_CORE, i->pathname); ++ break; ++ } ++ i = i->next; ++ } ++ ++ /* Not already one: allocate an OpenFd */ ++ if (i == NULL) { ++ i = VG_(arena_malloc)(VG_AR_CORE, "libcfile.regfd.1", sizeof(OpenFd)); ++ ++ i->prev = NULL; ++ i->next = opened_fds; ++ if(opened_fds) opened_fds->prev = i; ++ opened_fds = i; ++ } ++ ++ i->fd = fd; ++ i->pathname = VG_(arena_strdup)(VG_AR_CORE, "libcfile.regfd.2", pathname); ++} ++ ++extern char *VG_(pathname_by_fd)(Int); ++ ++char * ++VG_(pathname_by_fd)(Int fd) ++{ ++ OpenFd *a; ++ ++ for (a = opened_fds; a; a = a->next) { ++ if (a->fd == fd && a->pathname) ++ return a->pathname; ++ } ++ return NULL; ++} ++#endif ++ + SysRes VG_(open) ( const HChar* pathname, Int flags, Int mode ) + { + # if