-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
debug symbols missing when running with valgrind #896
Comments
I can reproduce this with trunk clang: static int *foo(void) {
return (int *)10000000;
}
void _start(void) {
int *x = foo();
*x += 1;
}
|
Does it work if you run Ref: https://bugs.launchpad.net/ubuntu/+source/valgrind/+bug/1567219 |
Same behavior after More info: The above C code reproduces the problem with GCC as well as clang. From
I believe this is a valgrind issue. Perhaps we can send a patch. |
I've narrowed this down to linking with LLD vs linking with binutils ld. static int *foo(void) {
return (int *)10000000;
}
int main(void) {
int *x = foo();
*x += 1;
} Create an .o file:
Find out link command zig is using:
Use the same link command printed from above step, but replace LLD with binutils ld, and replace
Note that valgrind sees debug info:
Now repeat link but with LLD:
Note that valgrind does not see debug info:
|
upstream bug report: https://bugs.llvm.org/show_bug.cgi?id=37021 |
Workaround suggested by llvm-dev mailing list: diff --git a/src/link.cpp b/src/link.cpp
index 3c6e27e3..14e8cb52 100644
--- a/src/link.cpp
+++ b/src/link.cpp
@@ -217,6 +217,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
lj->args.append(g->linker_script);
}
+ lj->args.append("--no-rosegment");
lj->args.append("--gc-sections");
lj->args.append("-m");
I'm considering if we should use this. I don't fully understand the implications yet, but it does fix valgrind's debug info. |
I think this makes sense. I'm now convinced this is a bug in valgrind and I will work with the valgrind devs to fix the issue. |
https://sourceforge.net/p/valgrind/mailman/message/36286103/ It looks like the devs would appreciate a patch. This patch does some of the work and should be a clue as to what further changes need to be made for valgrind to support executables compiled with clang and linked with LLD: diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c
index c8a6124a2..dbe6da10a 100644
--- a/coregrind/m_debuginfo/debuginfo.c
+++ b/coregrind/m_debuginfo/debuginfo.c
@@ -1126,9 +1126,7 @@ ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
# error "Unknown platform"
# endif
-# if defined(VGP_x86_darwin) && DARWIN_VERS >= DARWIN_10_7
is_ro_map = seg->hasR && !seg->hasW && !seg->hasX;
-# endif
# if defined(VGO_solaris)
is_rx_map = seg->hasR && seg->hasX && !seg->hasW;
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
index 70c28e629..106a6ec0c 100644
--- a/coregrind/m_debuginfo/readelf.c
+++ b/coregrind/m_debuginfo/readelf.c
@@ -1797,6 +1797,12 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
TRACE_SYMTAB("rw_map: avma %#lx size %lu foff %ld\n",
map->avma, map->size, map->foff);
}
+ for (i = 0; i < VG_(sizeXA)(di->fsm.maps); i++) {
+ const DebugInfoMapping* map = VG_(indexXA)(di->fsm.maps, i);
+ if (map->ro)
+ TRACE_SYMTAB("ro_map: avma %#lx size %lu foff %ld\n",
+ map->avma, map->size, map->foff);
+ }
if (phdr_mnent == 0
|| !ML_(img_valid)(mimg, phdr_mioff, phdr_mnent * phdr_ment_szB)) {
@@ -1877,7 +1883,7 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
Bool loaded = False;
for (j = 0; j < VG_(sizeXA)(di->fsm.maps); j++) {
const DebugInfoMapping* map = VG_(indexXA)(di->fsm.maps, j);
- if ( (map->rx || map->rw)
+ if ( (map->rx || map->rw || map->ro)
&& map->size > 0 /* stay sane */
&& a_phdr.p_offset >= map->foff
&& a_phdr.p_offset < map->foff + map->size
@@ -1908,6 +1914,16 @@ Bool ML_(read_elf_debug_info) ( struct _DebugInfo* di )
i, (UWord)item.bias);
loaded = True;
}
+ if (map->ro
+ && (a_phdr.p_flags & (PF_R | PF_W | PF_X))
+ == PF_R) {
+ item.exec = False;
+ VG_(addToXA)(svma_ranges, &item);
+ TRACE_SYMTAB(
+ "PT_LOAD[%ld]: acquired as ro, bias 0x%lx\n",
+ i, (UWord)item.bias);
+ loaded = True;
+ }
}
}
if (!loaded) { |
this provides a workaround for #896 until valgrind adds support for clang/LLD (equivalent to gcc/gold -rosegment)
This issue appears to have been fixed with Valgrind 3.14 or LLVM 7 or the combination of both. |
See #896 Zig 0.3.0+ and Valgrind 3.14+ do not need the workaround.
however, with gdb the symbols are read just fine.
The text was updated successfully, but these errors were encountered: