[PATCH] Fix PR42531: lto generates invalid assembler ".section" directives.

Richard Guenther richard.guenther@gmail.com
Thu Dec 31 17:52:00 GMT 2009


On Thu, Dec 31, 2009 at 6:15 PM, Dave Korn
<dave.korn.cygwin@googlemail.com> wrote:
> H.J. Lu wrote:
>
>> The patch doesn't look right:
>>
>>  @@ -2005,12 +2007,17 @@ copy_function (struct cgraph_node *node)
>>    const char *data;
>>    size_t len;
>>    const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (function));
>> -  char *section_name =
>> -    lto_get_section_name (LTO_section_function_body, name);
>> +  char *section_name;
>>    size_t i, j;
>>    struct lto_in_decl_state *in_state;
>> -  struct lto_out_decl_state *out_state = lto_get_out_decl_state ();
>> +  struct lto_out_decl_state *out_state;
>>
>> +  if (name[0] == '*')
>> +    name++;
>> +  section_name =
>> +    lto_get_section_name (LTO_section_function_body, name);
>> +  out_state = lto_get_out_decl_state ();
>> +
>>    lto_begin_section (section_name, !flag_wpa);
>>    free (section_name);
>>
>> It doesn't handle name == NULL.
>
>  Nor do some of the other (pre-existing) code sequences, such as
>
>>       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (t));
>>
>>       /* FIXME lto: this is from assemble_name_raw in varasm.c. For some
>>        architectures we might have to do the same name manipulations that
>>        ASM_OUTPUT_LABELREF does. */
>>       if (name[0] == '*')
>>       name = &name[1];
>
>  Some places guard it with DECL_ASSEMBLER_NAME_SET_P (see e.g.
> lto_output_builtin_tree) but others don't.  Is it possible that the assembler
> name could not be set at this point?  Have you seen a segfault?
>
>  I'll add a null check in the revised patch, but things are surely going to
> be going badly wrong if it's ever needed.  What happens if we call
> copy_function for two different functions that both don't have any assembler name?

They always have an assembler name.

Richard.



More information about the Gcc-patches mailing list