varasm.c (initialize_cold_section_name): Fix alloca buffer overflow.
* varasm.c (initialize_cold_section_name): Fix alloca buffer overflow. (assemble_start_function): Fix strcmp confusion. From-SVN: r100733
This commit is contained in:
parent
ff680eb128
commit
60ff97f497
@ -1,3 +1,8 @@
|
|||||||
|
2005-06-07 Richard Henderson <rth@redhat.com>
|
||||||
|
|
||||||
|
* varasm.c (initialize_cold_section_name): Fix alloca buffer overflow.
|
||||||
|
(assemble_start_function): Fix strcmp confusion.
|
||||||
|
|
||||||
2005-06-07 Uros Bizjak <uros@kss-loka.si>
|
2005-06-07 Uros Bizjak <uros@kss-loka.si>
|
||||||
|
|
||||||
* config/i386/i386.h (enum ix86_entity): New.
|
* config/i386/i386.h (enum ix86_entity): New.
|
||||||
|
34
gcc/varasm.c
34
gcc/varasm.c
@ -176,21 +176,22 @@ EXTRA_SECTION_FUNCTIONS
|
|||||||
static void
|
static void
|
||||||
initialize_cold_section_name (void)
|
initialize_cold_section_name (void)
|
||||||
{
|
{
|
||||||
const char *name;
|
|
||||||
const char *stripped_name;
|
const char *stripped_name;
|
||||||
char *buffer;
|
char *name, *buffer;
|
||||||
|
tree dsn;
|
||||||
|
|
||||||
gcc_assert (cfun && current_function_decl);
|
gcc_assert (cfun && current_function_decl);
|
||||||
if (cfun->unlikely_text_section_name)
|
if (cfun->unlikely_text_section_name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (flag_function_sections && DECL_SECTION_NAME (current_function_decl))
|
dsn = DECL_SECTION_NAME (current_function_decl);
|
||||||
|
if (flag_function_sections && dsn)
|
||||||
{
|
{
|
||||||
name = alloca (TREE_STRING_LENGTH (DECL_SECTION_NAME
|
name = alloca (TREE_STRING_LENGTH (dsn) + 1);
|
||||||
(current_function_decl)));
|
memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
|
||||||
strcpy ((char *) name, TREE_STRING_POINTER (DECL_SECTION_NAME
|
|
||||||
(current_function_decl)));
|
|
||||||
stripped_name = targetm.strip_name_encoding (name);
|
stripped_name = targetm.strip_name_encoding (name);
|
||||||
|
|
||||||
buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
|
buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
|
||||||
cfun->unlikely_text_section_name = ggc_strdup (buffer);
|
cfun->unlikely_text_section_name = ggc_strdup (buffer);
|
||||||
}
|
}
|
||||||
@ -1289,26 +1290,11 @@ assemble_start_function (tree decl, const char *fnname)
|
|||||||
doing partitioning, if the entire function was decided by
|
doing partitioning, if the entire function was decided by
|
||||||
choose_function_section (predict.c) to be cold. */
|
choose_function_section (predict.c) to be cold. */
|
||||||
|
|
||||||
int i;
|
|
||||||
int len;
|
|
||||||
char *s;
|
|
||||||
|
|
||||||
initialize_cold_section_name ();
|
initialize_cold_section_name ();
|
||||||
|
|
||||||
/* The following is necessary, because 'strcmp
|
|
||||||
(TREE_STRING_POINTER (DECL_SECTION_NAME (decl)), blah)' always
|
|
||||||
fails, presumably because TREE_STRING_POINTER is declared to
|
|
||||||
be an array of size 1 of char. */
|
|
||||||
|
|
||||||
len = TREE_STRING_LENGTH (DECL_SECTION_NAME (decl));
|
|
||||||
s = (char *) xmalloc (len + 1);
|
|
||||||
|
|
||||||
for (i = 0; i < len; i ++)
|
|
||||||
s[i] = (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)))[i];
|
|
||||||
s[len] = '\0';
|
|
||||||
|
|
||||||
if (cfun->unlikely_text_section_name
|
if (cfun->unlikely_text_section_name
|
||||||
&& (strcmp (s, cfun->unlikely_text_section_name) == 0))
|
&& strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
|
||||||
|
cfun->unlikely_text_section_name) == 0)
|
||||||
first_function_block_is_cold = true;
|
first_function_block_is_cold = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user