diff options
author | Alan Modra <amodra@gmail.com> | 2018-12-01 09:37:48 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2018-12-01 15:18:04 +1030 |
commit | 0acc7632bb09cce832a1b3756d31cc3fa93a724a (patch) | |
tree | d55c1680973037e5cc8ced249bcda4f9b33fa91e /gas/config | |
parent | 35d1b0784a27fcd71daf1b058423010c9001f039 (diff) | |
download | gdb-0acc7632bb09cce832a1b3756d31cc3fa93a724a.zip gdb-0acc7632bb09cce832a1b3756d31cc3fa93a724a.tar.gz gdb-0acc7632bb09cce832a1b3756d31cc3fa93a724a.tar.bz2 |
PR23938, should not free memory alloced in obstack by free()
This removes ineffectual and wrong code caching section names in
gas/stabs.c. Code like
seg = subseg_new (name, 0);
...
if (seg->name == name)
seg->name = xstrdup (name);
with the idea of being able to unconditionally free "name" later no
longer works. "name" is referenced by the section hash table as well
as in the section->name field. It would be possible to use
"bfd_rename_section (stdoutput, seg, xstrdup (name))", but instead I
opted for a fairly straight-forward approach of adding extra
parameters to two functions to indicate section name strings should be
freed if possible.
PR 23938
* read.h (get_stab_string_offset): Update prototype.
* stabs.c (get_stab_string_offset): Add free_stabstr_secname
parameter. Free stabstr_secname if unused as section name.
Don't xstrdup name when used.
(s_stab_generic): Remove forward declaration. Add
stab_secname_obstack_end param. Reference notes obstack via
macros. Delete cached_secname. Adjust get_stab_string_offset
call. Free stab_secname if unused as section name.
(s_stab): Adjust s_stab_generic call.
(s_xstab): Likewise. Delete saved_secname and saved_strsecname.
* config/obj-elf.c (obj_elf_init_stab_section): Adjust
get_stab_string_offset call.
* config/obj-coff.c (obj_coff_init_stab_section): Likewise.
* config/obj-som.c (obj_som_init_stab_section): Likewise.
* testsuite/gas/all/pr23938.s: New test.
* testsuite/gas/all/gas.exp: Run it.
Diffstat (limited to 'gas/config')
-rw-r--r-- | gas/config/obj-coff.c | 2 | ||||
-rw-r--r-- | gas/config/obj-elf.c | 2 | ||||
-rw-r--r-- | gas/config/obj-som.c | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/gas/config/obj-coff.c b/gas/config/obj-coff.c index 945b4ec..2a5b544 100644 --- a/gas/config/obj-coff.c +++ b/gas/config/obj-coff.c @@ -1802,7 +1802,7 @@ obj_coff_init_stab_section (segT seg) memset (p, 0, 12); file = as_where ((unsigned int *) NULL); stabstr_name = concat (seg->name, "str", (char *) NULL); - stroff = get_stab_string_offset (file, stabstr_name); + stroff = get_stab_string_offset (file, stabstr_name, TRUE); know (stroff == 1); md_number_to_chars (p, stroff, 4); } diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c index a674c1b..3ec6b59 100644 --- a/gas/config/obj-elf.c +++ b/gas/config/obj-elf.c @@ -2127,7 +2127,7 @@ obj_elf_init_stab_section (segT seg) memset (p, 0, 12); file = as_where (NULL); stabstr_name = concat (segment_name (seg), "str", (char *) NULL); - stroff = get_stab_string_offset (file, stabstr_name); + stroff = get_stab_string_offset (file, stabstr_name, TRUE); know (stroff == 1 || (stroff == 0 && file[0] == '\0')); md_number_to_chars (p, stroff, 4); seg_info (seg)->stabu.p = p; diff --git a/gas/config/obj-som.c b/gas/config/obj-som.c index 3f2e27b..491bef8 100644 --- a/gas/config/obj-som.c +++ b/gas/config/obj-som.c @@ -243,7 +243,7 @@ obj_som_init_stab_section (segT seg) p = frag_more (12); memset (p, 0, 12); file = as_where ((unsigned int *) NULL); - stroff = get_stab_string_offset (file, "$GDB_STRINGS$"); + stroff = get_stab_string_offset (file, "$GDB_STRINGS$", FALSE); know (stroff == 1); md_number_to_chars (p, stroff, 4); seg_info (seg)->stabu.p = p; |