On Thu, May 07 2020, Masato Asou <a...@soum.co.jp> wrote:
> hi,
>
> Valgrind reports the correct wirte as an invalid write. It is
> occurring at /usr/libexec/ld.so.
>
> I run following program.
>
> $ cat main.c
> #include <stdio.h>
>
> int
> main(int argc, char *argv[])
> {
>         printf("Hello, world\n");
>         return (0);
> }
> $ cc -g main.c
> $ valgrind ./a.out
> ==46291== Memcheck, a memory error detector
> ==46291== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
> ==46291== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
> ==46291== Command: /home/asou/tmp/a.out
> ==46291==
> ==46291== Invalid write of size 1
> ==46291==    at 0x410730C: ???
> ==46291==    by 0x4103CC8: ???
> ==46291==    by 0x41032EE: ???
> ==46291==    by 0x4102605: ???
> ==46291==  Address 0x40052d0 is not stack'd, malloc'd or (recently) free'd
> ==46291==
> ==46291== Invalid write of size 1
> ==46291==    at 0x410730E: ???
> ==46291==    by 0x4103CC8: ???
> ==46291==    by 0x41032EE: ???
> ==46291==    by 0x4102605: ???
> ==46291==  Address 0x40052d1 is not stack'd, malloc'd or (recently) free'd
> ==46291==
>
> </snip>
>
> ==46291== For counts of detected and suppressed errors, rerun with: -v
> ==46291== Use --track-origins=yes to see where uninitialised values come from
> ==46291== ERROR SUMMARY: 3209 errors from 357 contexts (suppressed: 0 from 0)
> $ 
>
> I got 3209 errors.
>
> However, when the following patch was applied, the error was reduced
> to four as below:

Hah, that look much better.

> $ valgrind ./a.out
> ==7449== Memcheck, a memory error detector
> ==7449== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
> ==7449== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
> ==7449== Command: /home/asou/tmp/a.out
> ==7449==
> ==7449== Use of uninitialised value of size 8
> ==7449==    at 0x4ACB969: write (sys/w_write.c:26)
> ==7449==    by 0x4AB60DF: __sflush (stdio/fflush.c:80)
> ==7449==    by 0x4A491F1: __sfvwrite (stdio/fvwrite.c:191)
> ==7449==    by 0x4A62F62: __sprint (stdio/vfprintf.c:108)
> ==7449==    by 0x4A62F62: __vfprintf (stdio/vfprintf.c:1067)
> ==7449==    by 0x4A5F151: vfprintf (stdio/vfprintf.c:263)
> ==7449==    by 0x4A43DB0: printf (stdio/printf.c:44)
> ==7449==    by 0x109374: main (main.c:6)
> ==7449==
> ==7449== Use of uninitialised value of size 8
> ==7449==    at 0x4ACB97A: write (sys/w_write.c:26)
> ==7449==    by 0x4AB60DF: __sflush (stdio/fflush.c:80)
> ==7449==    by 0x4A491F1: __sfvwrite (stdio/fvwrite.c:191)
> ==7449==    by 0x4A62F62: __sprint (stdio/vfprintf.c:108)
> ==7449==    by 0x4A62F62: __vfprintf (stdio/vfprintf.c:1067)
> ==7449==    by 0x4A5F151: vfprintf (stdio/vfprintf.c:263)
> ==7449==    by 0x4A43DB0: printf (stdio/printf.c:44)
> ==7449==    by 0x109374: main (main.c:6)
> ==7449==
> Hello, world
> ==7449== Use of uninitialised value of size 8
> ==7449==    at 0x4ACB98E: write (sys/w_write.c:28)
> ==7449==    by 0x4AB60DF: __sflush (stdio/fflush.c:80)
> ==7449==    by 0x4A491F1: __sfvwrite (stdio/fvwrite.c:191)
> ==7449==    by 0x4A62F62: __sprint (stdio/vfprintf.c:108)
> ==7449==    by 0x4A62F62: __vfprintf (stdio/vfprintf.c:1067)
> ==7449==    by 0x4A5F151: vfprintf (stdio/vfprintf.c:263)
> ==7449==    by 0x4A43DB0: printf (stdio/printf.c:44)
> ==7449==    by 0x109374: main (main.c:6)
> ==7449==
> ==7449== Use of uninitialised value of size 8
> ==7449==    at 0x4ACC31C: _thread_finalize (stdlib/atexit.c:131)
> ==7449==    by 0x4ACC31C: __cxa_finalize (stdlib/atexit.c:153)
> ==7449==    by 0x4AD13C0: exit (stdlib/exit.c:54)
> ==7449==    by 0x109141: ___start (in /home/asou/tmp/a.out)
> ==7449==
> ==7449==
> ==7449== FILE DESCRIPTORS: 3 open at exit.
> ==7449== Open file descriptor 2:
> ==7449==    <inherited from parent>
> ==7449==
> ==7449== Open file descriptor 1:
> ==7449==    <inherited from parent>
> ==7449==
> ==7449== Open file descriptor 0:
> ==7449==    <inherited from parent>
> ==7449==
> ==7449==
> ==7449== HEAP SUMMARY:
> ==7449==     in use at exit: 65,536 bytes in 1 blocks
> ==7449==   total heap usage: 1 allocs, 0 frees, 65,536 bytes allocated
> ==7449==
> ==7449== LEAK SUMMARY:
> ==7449==    definitely lost: 0 bytes in 0 blocks
> ==7449==    indirectly lost: 0 bytes in 0 blocks
> ==7449==      possibly lost: 0 bytes in 0 blocks
> ==7449==    still reachable: 65,536 bytes in 1 blocks
> ==7449==         suppressed: 0 bytes in 0 blocks
> ==7449== Rerun with --leak-check=full to see details of leaked memory
> ==7449==
> ==7449== For counts of detected and suppressed errors, rerun with: -v
> ==7449== Use --track-origins=yes to see where uninitialised values come from
> ==7449== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
> $ 
>
>
> The patch to Makefile is a temporary. Because, my previous patch
> https://marc.info/?l=openbsd-ports&m=158624064212984&w=2
> does not get OK.

I did take a look at that one but got lost in a maze.  Will get back to
it when time permits.

> ok?

Diff looks good, lightly tested with a few base executables.
ok jca@ but please wait for tree unlock.

Thanks for caring about this port!

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to