Bug 1034016 - Odd auto-load safe-path warnings when debugging alternate runtime.
Summary: Odd auto-load safe-path warnings when debugging alternate runtime.
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Fedora
Classification: Fedora
Component: gdb
Version: 19
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jan Kratochvil
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-11-25 04:49 UTC by Carlos O'Donell
Modified: 2013-11-25 14:11 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-11-25 14:11:12 UTC
Type: Bug


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Sourceware 16216 0 None None None Never

Description Carlos O'Donell 2013-11-25 04:49:18 UTC
Description of problem:
When building an application against an alternate build of glibc (with -Wl,--dynamic-linker and -Wl,-rpath) the debugger issues an odd auto-load safe-path warning that doesn't quite work nor is it correct.

Version-Release number of selected component (if applicable):
gdb-7.6.1-42.fc19.x86_64

How reproducible:
Always reproducible.

Steps to reproduce:
cat >> thread.c <<EOF
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void *
myfunc (void *arg)
{
  printf ("myfunc!\n");
  return NULL;
}

int
main (void)
{
  pthread_t mythread;
  int ret;
  void *retval;

  ret = pthread_create (&mythread, NULL, myfunc, NULL);

  if (ret != 0)
    {
      printf ("FAIL: pthread_create failed with %d\n", ret);
      exit (1);
    }
  else
    ret = pthread_join (mythread, &retval);

  if (ret != 0)
    {
      printf ("FAIL: pthread_join failed with %d\n", ret);
      exit (1);
    }

  return 0;
}
EOF

# Use the normal linker script but without all the distro-specific SEARCH_DIR paths.

ld --verbose | tail -n +11 | sed -e 's,SEARCH_DIR.*,,g' -e 's,===.*,,g' > link.script

# Compile the object file.
gcc -c thread.c

# Link against the alternate glibc build.
ld -Map link.map -T link.script --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /home/carlos/build/glibc/elf/ld.so -o thread /home/carlos/build/glibc/csu/crt1.o /home/carlos/build/glibc/csu/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.8.2/crtbegin.o -L/home/carlos/build/glibc -L/home/carlos/build/glibc/dlfcn -L/home/carlos/build/glibc/nptl -L/home/carlos/build/glibc/nss -L/home/carlos/build/glibc/nptl_db -L/home/carlos/build/glibc/csu -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../.. --dynamic-linker=/home/carlos/build/glibc/elf/ld.so -rpath=/home/carlos/build/glibc:/home/carlos/build/glibc/dlfcn:/home/carlos/build/glibc/nptl:/home/carlos/build/glibc/nss:/home/carlos/build/glibc/nptl_db /home/carlos/build/glibc/elf/ld.so -lpthread /home/carlos/build/glibc/nptl/libpthread_nonshared.a ./thread.o -lgcc --as-needed -lgcc_s --no-as-needed -lc /home/carlos/build/glibc/libc_nonshared.a -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.8.2/crtend.o /home/carlos/build/glibc/csu/crtn.o

Actual results:

[carlos@koi tmp]$ gdb thread
GNU gdb (GDB) Fedora 7.6.1-42.fc19
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/carlos/support/2013-11-22/tmp/thread...done.
(gdb) 
(gdb) r
Starting program: /home/carlos/support/2013-11-22/tmp/thread 
warning: File "/home/carlos/build/glibc/nptl/libthread_db.so.1" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load:/usr/bin/mono-gdb.py".
To enable execution of this file add
	add-auto-load-safe-path /home/carlos/build/glibc/nptl/libthread_db.so.1
line to your configuration file "/home/carlos/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/home/carlos/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
myfunc!
[Inferior 1 (process 27628) exited normally]
(gdb) 

# Note that /home/carlos/build/glibc/nptl/libthread_db.so.1 is actually the wrong path, it should be /home/carlos/build/glibc/nptl_db/libthread_db.so.1.

(gdb) add-auto-load-safe-path /home/carlos/build/glibc/nptl/libthread_db.so.1
(gdb) r
Starting program: /home/carlos/support/2013-11-22/tmp/thread 
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
myfunc!
[Inferior 1 (process 27748) exited normally]
(gdb) 

# So the recommendation doesn't work.

(gdb) set auto-load safe-path /
(gdb) r
Starting program: /home/carlos/support/2013-11-22/tmp/thread 
warning: Unable to find libthread_db matching inferior's thread library, thread debugging will not be available.
myfunc!
[Inferior 1 (process 27846) exited normally]
(gdb) 

# Completely disabling doesn't work either. What about the old preload trick?

[carlos@koi tmp]$ LD_PRELOAD=/home/carlos/build/glibc/nptl_db/libthread_db.so.1 gdb thread
GNU gdb (GDB) Fedora 7.6.1-42.fc19
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/carlos/support/2013-11-22/tmp/thread...done.
(gdb) r
Starting program: /home/carlos/support/2013-11-22/tmp/thread 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/home/carlos/build/glibc/nptl_db/libthread_db.so.1".
[New Thread 0x7ffff7608700 (LWP 27913)]
myfunc!
[Thread 0x7ffff7608700 (LWP 27913) exited]
[Inferior 1 (process 27909) exited normally]
(gdb) 

# OK, that works.

Expected results:

The auto-load safe-path warning should talk about /home/carlos/build/glibc/nptl_db/libthread_db.so.1, and it should be able to load that DSO without me needing to preload it.

I know this is a corner case, but I filed it anyways just to make the gdb team aware of the issues I saw while debuggin an alternate runtime.

Comment 1 Jan Kratochvil 2013-11-25 13:47:40 UTC
There are two unrelated issues:

(1) "auto-loading has been declined" is printed without checking the file exists.  This is a bug, such warning is pointless as there is nothing unsafe in such case.  I will fix that.  You can completely avoid this problem by that "set auto-load safe-path /" you used.

(2) libthread_db.so.1 (if the standard system one does not work) is expected to be in the same directory as libpthread.so.0.  So it is correct that GDB expects libthread_db in /nptl/ and not in /nptl_db/, GDB does not feature AI.  You should use "set libthread-db-search-path" to point GDB at your /nptl_db/ directory.  In such case you sure also need to "set auto-load safe-path" or "add-auto-load-safe-path".

So leaving this Bug open for the (1) part.


Note You need to log in before you can comment on or make changes to this bug.