Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory issues detected by valgrind #1

Open
mingodad opened this issue Jul 27, 2022 · 7 comments
Open

Memory issues detected by valgrind #1

mingodad opened this issue Jul 27, 2022 · 7 comments

Comments

@mingodad
Copy link

On a fresh build of this project and executing it under valgrind gives this result:

valgrind ./msta c5.y 
==16580== Memcheck, a memory error detector
==16580== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==16580== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==16580== Command: ./msta c5.y
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x450CB7: malloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4B186A: _dl_get_origin (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47E45E: _dl_non_dynamic_init (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47FAD0: __libc_init_first (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x431D90: (below main) (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x450DA9: malloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4B186A: _dl_get_origin (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47E45E: _dl_non_dynamic_init (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47FAD0: __libc_init_first (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x431D90: (below main) (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x44E813: _int_malloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4506D4: tcache_init.part.4 (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x450DB8: malloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4B186A: _dl_get_origin (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47E45E: _dl_non_dynamic_init (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x47FAD0: __libc_init_first (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x431D90: (below main) (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x44CFC5: _int_free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x44FB24: _int_realloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x452A30: realloc_hook_ini (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x428F83: _VLO_tailor_function (vlobject.c:74)
==16580==    by 0x42B2E4: start_command_line_processing (commline.c:253)
==16580==    by 0x400753: main (main.c:432)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x44CFC5: _int_free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x44FB24: _int_realloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x452E41: realloc (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x428F83: _VLO_tailor_function (vlobject.c:74)
==16580==    by 0x42B2E4: start_command_line_processing (commline.c:253)
==16580==    by 0x400753: main (main.c:432)
==16580== 
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x451BDF: free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x4295C2: _OS_delete_function (objstack.c:95)
==16580==    by 0x429F81: output_errors (errors.c:356)
==16580==    by 0x400ED7: main (main.c:708)
==16580== 
  Max look ahead is 1 token
  Real look ahead is 1 token
  1 shift/reduce conflict.
==16580== Conditional jump or move depends on uninitialised value(s)
==16580==    at 0x451BDF: free (in /home/mingo/dev/c/A_grammars/msta-dbg/msta)
==16580==    by 0x429E74: finish_errors (errors.c:328)
==16580==    by 0x428ECF: msta_finish (main.c:164)
==16580==    by 0x400EF8: main (main.c:714)
==16580== 
==16580== 
==16580== HEAP SUMMARY:
==16580==     in use at exit: 0 bytes in 0 blocks
==16580==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==16580== 
==16580== All heap blocks were freed -- no leaks are possible
==16580== 
==16580== Use --track-origins=yes to see where uninitialised values come from
==16580== For lists of detected and suppressed errors, rerun with: -s
==16580== ERROR SUMMARY: 55 errors from 7 contexts (suppressed: 0 from 0)
@rofl0r
Copy link
Collaborator

rofl0r commented Jul 27, 2022

you have a proposed fix ?

@mingodad
Copy link
Author

Not yet !
I did several tests but didn't got where the problem is right now.

@mingodad
Copy link
Author

Looking again I found that after commenting out this line on Makefile.in valgrind doesn't show any invalid memory access anymore:

nodist_msta_SOURCES = yacc.c
CLEANFILES = yacc.c
msta_CFLAGS = -I$(srcdir)/AMMUNITION
#msta_LDFLAGS = -static  #!!!!!<<<<  commenting this line

@mingodad
Copy link
Author

Looking again the correct place to comment the offending line is in Makefile.am.

@rofl0r
Copy link
Collaborator

rofl0r commented Jul 27, 2022

it's odd that this would make a difference, except in that valgrind requires dynamic linking to inject its shared libraries overriding malloc and friends... otoh forcing a static build probably isn't that good of an idea; it should be up to the user configuring the build.

@mingodad
Copy link
Author

Yes I agree with you, I don't see the point to link the compiler libraries statically by default.

@vnmakarov
Copy link
Member

Valgrind can be very rigorous. There are some algorithms which work fine using uninitialized data and valgrind will complaint about this. The classical example is sparse sets https://www.geeksforgeeks.org/sparse-set/

rofl0r added a commit that referenced this issue Jul 30, 2022
it should be up to the user deciding whether he wants the binary
statically or dynamically linked.

related: #1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants