gas 2.20.1 assertion failure when .file directive empty and .stabs directive present

Alan Modra amodra@gmail.com
Tue Aug 31 09:40:00 GMT 2010


On Thu, Aug 26, 2010 at 03:19:23PM -0700, Raymes Khoury wrote:
> This error can be easily reproduced by executing the following with
> binutils 2.20.1 (I'm using gcc 4.4.3).
> 
> $ echo "int main() { return 0; }" | gcc -x c - -gstabs
> /tmp/ccautrgB.s: Assembler messages:
> /tmp/ccautrgB.s:2: Internal error!
> Assertion failure in obj_elf_init_stab_section at
> ../../gas/config/obj-elf.c line 1782.
> Please report this bug.
> 
> When the program is passed from stdin, gcc uses an empty string as the
> value of the .file directive. The assembler output is as follows:
>         .file   ""
>         .stabs  "",100,0,2,.Ltext0
>         .text
>         ...
> 
> The assertion fails in obj_elf_init_stab_section which calls
> get_stab_string_offset (stabs.c) with the value of the .file
> directive. When this is an empty string, get_stab_string_offset
> returns 0 which appears to be a failure value as the offset is
> actually 1 (and in all other cases it will return a value >= 1).
> obj_elf_init_stab_section asserts the return value is 1 and thus
> fails.
[snip]

Let's just fix the assertion.  There isn't much point in adding
another NUL to the stab string section.  The first one will do fine.

	* config/obj-elf.c (obj_elf_init_stab_section): Fix assertion.

Index: gas/config/obj-elf.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-elf.c,v
retrieving revision 1.129
diff -u -p -r1.129 obj-elf.c
--- gas/config/obj-elf.c	17 Aug 2010 20:03:40 -0000	1.129
+++ gas/config/obj-elf.c	31 Aug 2010 05:31:33 -0000
@@ -1795,7 +1795,7 @@ obj_elf_init_stab_section (segT seg)
   strcpy (stabstr_name, segment_name (seg));
   strcat (stabstr_name, "str");
   stroff = get_stab_string_offset (file, stabstr_name);
-  know (stroff == 1);
+  know (stroff == 1 || (stroff == 0 && file[0] == '\0'));
   md_number_to_chars (p, stroff, 4);
   seg_info (seg)->stabu.p = p;
 }

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list