diff mbox

libbacktrace patch committed: Don't warn about missing shared libs

Message ID mcrfw51ngh8.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Oct. 26, 2012, 8:08 p.m. UTC
I have not been able to recreate PR 55087, but it seems to be pointing
out a case where libbacktrace is issuing an error attempting to open a
shared library that does not exist (in this case it's the VDSO library,
which never exists in the file system as far as I know).  This patch to
libbacktrace avoids issuing an error in such a case.  Bootstrapped and
ran libbacktrace testsuite on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian


2012-10-26  Ian Lance Taylor  <iant@google.com>

	PR other/55087
	* posix.c (backtrace_open): Add does_not_exist parameter.
	* elf.c (phdr_callback): Do not warn if shared library could not
	be opened.
	* fileline.c (fileline_initialize): Update calls to
	backtrace_open.
	* internal.h (backtrace_open): Update declaration.
diff mbox

Patch

Index: posix.c
===================================================================
--- posix.c	(revision 192860)
+++ posix.c	(working copy)
@@ -57,14 +57,20 @@  POSSIBILITY OF SUCH DAMAGE.  */
 
 int
 backtrace_open (const char *filename, backtrace_error_callback error_callback,
-		void *data)
+		void *data, int *does_not_exist)
 {
   int descriptor;
 
+  if (does_not_exist != NULL)
+    *does_not_exist = 0;
+
   descriptor = open (filename, O_RDONLY | O_BINARY | O_CLOEXEC);
   if (descriptor < 0)
     {
-      error_callback (data, filename, errno);
+      if (does_not_exist != NULL && errno == ENOENT)
+	*does_not_exist = 1;
+      else
+	error_callback (data, filename, errno);
       return -1;
     }
 
Index: elf.c
===================================================================
--- elf.c	(revision 192860)
+++ elf.c	(working copy)
@@ -810,6 +810,7 @@  phdr_callback (struct dl_phdr_info *info
 {
   struct phdr_data *pd = (struct phdr_data *) pdata;
   int descriptor;
+  int does_not_exist;
   fileline elf_fileline_fn;
   int found_dwarf;
 
@@ -821,7 +822,8 @@  phdr_callback (struct dl_phdr_info *info
       || info->dlpi_addr == 0)
     return 0;
 
-  descriptor = backtrace_open (info->dlpi_name, pd->error_callback, pd->data);
+  descriptor = backtrace_open (info->dlpi_name, pd->error_callback, pd->data,
+			       &does_not_exist);
   if (descriptor < 0)
     return 0;
 
Index: internal.h
===================================================================
--- internal.h	(revision 192860)
+++ internal.h	(working copy)
@@ -109,10 +109,16 @@  struct backtrace_state
   struct backtrace_freelist_struct *freelist;
 };
 
-/* Open a file for reading.  Returns -1 on error.  */
+/* Open a file for reading.  Returns -1 on error.  If DOES_NOT_EXIST
+   is not NULL, *DOES_NOT_EXIST will be set to 0 normally and set to 1
+   if the file does not exist.  If the file does not exist and
+   DOES_NOT_EXIST is not NULL, the function will return -1 and will
+   not call ERROR_CALLBACK.  On other errors, or if DOES_NOT_EXIST is
+   NULL, the function will call ERROR_CALLBACK before returning.  */
 extern int backtrace_open (const char *filename,
 			   backtrace_error_callback error_callback,
-			   void *data);
+			   void *data,
+			   int *does_not_exist);
 
 /* A view of the contents of a file.  This supports mmap when
    available.  A view will remain in memory even after backtrace_close
Index: fileline.c
===================================================================
--- fileline.c	(revision 192860)
+++ fileline.c	(working copy)
@@ -80,9 +80,9 @@  fileline_initialize (struct backtrace_st
   /* We have not initialized the information.  Do it now.  */
 
   if (state->filename != NULL)
-    descriptor = backtrace_open (state->filename, error_callback, data);
+    descriptor = backtrace_open (state->filename, error_callback, data, NULL);
   else
-    descriptor = backtrace_open ("/proc/self/exe", error_callback, data);
+    descriptor = backtrace_open ("/proc/self/exe", error_callback, data, NULL);
   if (descriptor < 0)
     failed = 1;