[valgrind] [Bug 353192] Debug info/data section not detected on AMD64

2018-02-24 Thread Fredrik Tolf
https://bugs.kde.org/show_bug.cgi?id=353192

--- Comment #8 from Fredrik Tolf  ---
This is my reproducible testcase:

#include 

asm(".pushsection .foo,\"awx\",@progbits;"
".type writeablefunction, @function;"
"writeablefunction:"
"ret;"
".popsection;");

int main(int argc, char **argv)
{
malloc(128);
return(0);
}

I compiled with "gcc -g -Wall -o vgtest vgtest.c", but I reckon it should be
fairly tolerant with compiler flags. Valgrind output is:

$ valgrind --tool=memcheck --leak-check=full ./vgtest
==27841== Memcheck, a memory error detector
==27841== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==27841== Using Valgrind-3.12.0.SVN and LibVEX; rerun with -h for copyright
info
==27841== Command: ./vgtest
==27841== 
==27841== 
==27841== HEAP SUMMARY:
==27841== in use at exit: 128 bytes in 1 blocks
==27841==   total heap usage: 1 allocs, 0 frees, 128 bytes allocated
==27841== 
==27841== 128 bytes in 1 blocks are definitely lost in loss record 1 of 1
==27841==at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==27841==by 0x1086C8: ??? (in /tmp/vgtest)
==27841==by 0x4E582B0: (below main) (libc-start.c:291)
==27841== 
==27841== LEAK SUMMARY:
==27841==definitely lost: 128 bytes in 1 blocks
==27841==indirectly lost: 0 bytes in 0 blocks
==27841==  possibly lost: 0 bytes in 0 blocks
==27841==still reachable: 0 bytes in 0 blocks
==27841== suppressed: 0 bytes in 0 blocks
==27841== 
==27841== For counts of detected and suppressed errors, rerun with: -v
==27841== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

To point in this case being the missing symbol for "main" in the loss record.

-- 
You are receiving this mail because:
You are watching all bug changes.

[valgrind] [Bug 353192] Debug info/data section not detected on AMD64

2018-02-24 Thread Fredrik Tolf
https://bugs.kde.org/show_bug.cgi?id=353192

--- Comment #9 from Fredrik Tolf  ---
Also, this is a patch that fixes the issue for me. It does also include the fix
I mentioned above.

--- valgrind-3.12.0~svn20160714.orig/coregrind/m_debuginfo/debuginfo.c
+++ valgrind-3.12.0~svn20160714/coregrind/m_debuginfo/debuginfo.c
@@ -359,14 +359,14 @@ static Bool discard_syms_in_range ( Addr
   while (True) {
  if (curr == NULL)
 break;
- if (curr->text_present
- && curr->text_size > 0
- && (start+length - 1 < curr->text_avma 
- || curr->text_avma + curr->text_size - 1 < start)) {
-/* no overlap */
-} else {
-   found = True;
-   break;
+ if (curr->text_present && curr->text_size > 0) {
+   if (start+length - 1 < curr->text_avma 
+   || curr->text_avma + curr->text_size - 1 < start) {
+  /* no overlap */
+   } else {
+  found = True;
+  break;
+   }
 }
 curr = curr->next;
   }
@@ -944,10 +944,10 @@ ULong VG_(di_notify_mmap)( Addr a, Bool
is_ro_map = False;

 #  if defined(VGA_x86) || defined(VGA_ppc32) || defined(VGA_mips32) \
-  || defined(VGA_mips64)
+  || defined(VGA_mips64) || defined(VGA_amd64)
is_rx_map = seg->hasR && seg->hasX;
is_rw_map = seg->hasR && seg->hasW;
-#  elif defined(VGA_amd64) || defined(VGA_ppc64be) || defined(VGA_ppc64le)  \
+#  elif defined(VGA_ppc64be) || defined(VGA_ppc64le)  \
 || defined(VGA_arm) || defined(VGA_arm64)
is_rx_map = seg->hasR && seg->hasX && !seg->hasW;
is_rw_map = seg->hasR && seg->hasW && !seg->hasX;

This is against Debian's source tree, however. I hope that doesn't cause too
much problem.

-- 
You are receiving this mail because:
You are watching all bug changes.

[valgrind] [Bug 353192] Debug info/data section not detected on AMD64

2016-03-27 Thread Fredrik Tolf via KDE Bugzilla
https://bugs.kde.org/show_bug.cgi?id=353192

Fredrik Tolf  changed:

   What|Removed |Added

 CC||fred...@dolda2000.com

--- Comment #6 from Fredrik Tolf  ---
I also have this issue. The reason I have an executable data segment is because
I create a new section that is writable/executable for patchable code:

> .pushsection .genfuns,\"awx\",@progbits;
> [...]
> .popsection

This causes the linker to make the entire data segment RWX. Regardless of the
security implications, it seems Valgrind should be able to debug the file with
symbol info.


Also, while debugging Valgrind to see why it didn't load my symbols, I also
encountered what seemed to be unintentional behavior in
discard_syms_in_range(). On a completely unrelated munmap() call, it discarded
the DebugInfo for my executable because of how the in-range test is formulated.
It currently looks like this:

> if (curr->text_present
> && curr->text_size > 0
> && (start+length - 1 < curr->text_avma 
> || curr->text_avma + curr->text_size - 1 < start)) {
>/* no overlap */
> } else {
>found = True;
>break;
> }

This way, `found' is set not only when the range overlaps, but also when there
is no range. I don't know if there is any information elsewhere that makes this
meaningful, but it seems to me that the test should look like this instead:

> if (curr->text_present && curr->text_size > 0) {
> if (start+length - 1 < curr->text_avma 
> || curr->text_avma + curr->text_size - 1 < start) {
> /* no overlap */
> } else {
> found = True;
> break;
> }
> }

Technically, I guess this should perhaps be another report, but since it
doesn't cause any problems in and of itself, I wasn't sure how to report it. :)

-- 
You are receiving this mail because:
You are watching all bug changes.