diff mbox

Don't issue errors on GDB Python files

Message ID 20150624103058.GA3719@intel.com
State Superseded
Headers show

Commit Message

H.J. Lu June 24, 2015, 10:30 a.m. UTC
Many packages, including GCC, install Python files for GDB in library
diretory. ldconfig reads them and issue errors since they aren't ELF
files:

ldconfig: /usr/gcc-5.1.1/lib/libstdc++.so.6.0.21-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

ldconfig: /usr/gcc-5.1.1/libx32/libstdc++.so.6.0.21-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

ldconfig: /usr/gcc-5.1.1/lib64/libstdc++.so.6.0.21-gdb.py is not an ELF file - it has the wrong magic bytes at the start.

This patch silences ldconfig on GDB Python files by checking filenames
with -gdb.py suffix.

OK for master?

H.J.
--
	[BZ #18585]
	* elf/readlib.c (is_gdb_python_file): New.
	(process_file): Don't issue errors on filenames with -gdb.py
	suffix.
---
 elf/readlib.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Comments

Ondrej Bilka June 24, 2015, 10:44 a.m. UTC | #1
On Wed, Jun 24, 2015 at 03:30:58AM -0700, H.J. Lu wrote:
> Many packages, including GCC, install Python files for GDB in library
> diretory. ldconfig reads them and issue errors since they aren't ELF
> files:
> 
> ldconfig: /usr/gcc-5.1.1/lib/libstdc++.so.6.0.21-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
> 
> ldconfig: /usr/gcc-5.1.1/libx32/libstdc++.so.6.0.21-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
> 
> ldconfig: /usr/gcc-5.1.1/lib64/libstdc++.so.6.0.21-gdb.py is not an ELF file - it has the wrong magic bytes at the start.
> 
> This patch silences ldconfig on GDB Python files by checking filenames
> with -gdb.py suffix.
> 
> OK for master?
> 
> H.J.
> --
> 	[BZ #18585]
> 	* elf/readlib.c (is_gdb_python_file): New.
> 	(process_file): Don't issue errors on filenames with -gdb.py
> 	suffix.
> ---
>  elf/readlib.c | 20 +++++++++++++++-----
>  1 file changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/elf/readlib.c b/elf/readlib.c
> index 5c14a42..ad12da6 100644
> --- a/elf/readlib.c
> +++ b/elf/readlib.c
> @@ -63,6 +63,13 @@ static struct known_names known_libs[] =
>  };
>  
>  
> +/* Check if string corresponds to a GDB Python file.  */
> +static bool
> +is_gdb_python_file (const char *name)
> +{
> +  size_t len = strlen (name);
> +  return len > 7 && strcmp (name + len - 7, "-gdb.py") == 0;
> +}
>  
>  /* Returns 0 if everything is ok, != 0 in case of error.  */
>  int
> @@ -155,11 +162,14 @@ process_file (const char *real_file_name, const char *file_name,
>        /* The file is neither ELF nor aout.  Check if it's a linker
>  	 script, like libc.so - otherwise complain.  Only search the
>  	 beginning of the file.  */
> -      size_t len = MIN (statbuf.st_size, 512);
> -      if (memmem (file_contents, len, "GROUP", 5) == NULL
> -	  && memmem (file_contents, len, "GNU ld script", 13) == NULL)
> -	error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
> -	       file_name);
> +      if (!is_gdb_python_file (file_name))
> +	{
> +	  size_t len = MIN (statbuf.st_size, 512);
> +	  if (memmem (file_contents, len, "GROUP", 5) == NULL
> +	      && memmem (file_contents, len, "GNU ld script", 13) == NULL)
> +	    error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
> +		   file_name);
> +	}
>        ret = 1;
>      }
>    /* Libraries have to be shared object files.  */

mostly ok, but just write that condition as

 if (memmem (file_contents, len, "GROUP", 5) == NULL
     && memmem (file_contents, len, "GNU ld script", 13) == NULL
     && !is_gdb_python_file (file_name))
Szabolcs Nagy June 24, 2015, 11:02 a.m. UTC | #2
On 24/06/15 11:30, H.J. Lu wrote:
> @@ -155,11 +162,14 @@ process_file (const char *real_file_name, const char *file_name,
>        /* The file is neither ELF nor aout.  Check if it's a linker
>  	 script, like libc.so - otherwise complain.  Only search the
>  	 beginning of the file.  */
> -      size_t len = MIN (statbuf.st_size, 512);
> -      if (memmem (file_contents, len, "GROUP", 5) == NULL
> -	  && memmem (file_contents, len, "GNU ld script", 13) == NULL)
> -	error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
> -	       file_name);
> +      if (!is_gdb_python_file (file_name))
> +	{
> +	  size_t len = MIN (statbuf.st_size, 512);
> +	  if (memmem (file_contents, len, "GROUP", 5) == NULL
> +	      && memmem (file_contents, len, "GNU ld script", 13) == NULL)
> +	    error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
> +		   file_name);
> +	}
>        ret = 1;
>      }

special-casing -gdb.py is ugly.

and these heuristics are fragile
(eg if the python script happened to be smaller than
an elf header then you would get a "too small" warning).

i think either the 'strstr (file_name, ".so") != NULL'
check at the begining of the function should be more
strict or just silently ignore any file with invalid
header.
H.J. Lu June 24, 2015, 11:10 a.m. UTC | #3
On Wed, Jun 24, 2015 at 4:02 AM, Szabolcs Nagy <szabolcs.nagy@arm.com> wrote:
> On 24/06/15 11:30, H.J. Lu wrote:
>> @@ -155,11 +162,14 @@ process_file (const char *real_file_name, const char *file_name,
>>        /* The file is neither ELF nor aout.  Check if it's a linker
>>        script, like libc.so - otherwise complain.  Only search the
>>        beginning of the file.  */
>> -      size_t len = MIN (statbuf.st_size, 512);
>> -      if (memmem (file_contents, len, "GROUP", 5) == NULL
>> -       && memmem (file_contents, len, "GNU ld script", 13) == NULL)
>> -     error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
>> -            file_name);
>> +      if (!is_gdb_python_file (file_name))
>> +     {
>> +       size_t len = MIN (statbuf.st_size, 512);
>> +       if (memmem (file_contents, len, "GROUP", 5) == NULL
>> +           && memmem (file_contents, len, "GNU ld script", 13) == NULL)
>> +         error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
>> +                file_name);
>> +     }
>>        ret = 1;
>>      }
>
> special-casing -gdb.py is ugly.

ldconfig is full of special cases on filenames.

>
> and these heuristics are fragile
> (eg if the python script happened to be smaller than
> an elf header then you would get a "too small" warning).

Can you write a GDB python script with less than 4 bytes?

> i think either the 'strstr (file_name, ".so") != NULL'

This is more restrictive than checking -gdb.py.  That is it may
break existing DSOes.

> check at the begining of the function should be more
> strict or just silently ignore any file with invalid
> header.

I assume the error was done on purpose.  I don't want to
remove it.
diff mbox

Patch

diff --git a/elf/readlib.c b/elf/readlib.c
index 5c14a42..ad12da6 100644
--- a/elf/readlib.c
+++ b/elf/readlib.c
@@ -63,6 +63,13 @@  static struct known_names known_libs[] =
 };
 
 
+/* Check if string corresponds to a GDB Python file.  */
+static bool
+is_gdb_python_file (const char *name)
+{
+  size_t len = strlen (name);
+  return len > 7 && strcmp (name + len - 7, "-gdb.py") == 0;
+}
 
 /* Returns 0 if everything is ok, != 0 in case of error.  */
 int
@@ -155,11 +162,14 @@  process_file (const char *real_file_name, const char *file_name,
       /* The file is neither ELF nor aout.  Check if it's a linker
 	 script, like libc.so - otherwise complain.  Only search the
 	 beginning of the file.  */
-      size_t len = MIN (statbuf.st_size, 512);
-      if (memmem (file_contents, len, "GROUP", 5) == NULL
-	  && memmem (file_contents, len, "GNU ld script", 13) == NULL)
-	error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
-	       file_name);
+      if (!is_gdb_python_file (file_name))
+	{
+	  size_t len = MIN (statbuf.st_size, 512);
+	  if (memmem (file_contents, len, "GROUP", 5) == NULL
+	      && memmem (file_contents, len, "GNU ld script", 13) == NULL)
+	    error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
+		   file_name);
+	}
       ret = 1;
     }
   /* Libraries have to be shared object files.  */