aboutsummaryrefslogtreecommitdiff
path: root/libiberty/simple-object-elf.c
diff options
context:
space:
mode:
authorIain Buclaw <ibuclaw@gdcproject.org>2014-10-11 10:29:10 +0100
committerIain Buclaw <ibuclaw@gdcproject.org>2014-10-11 10:29:10 +0100
commitb55f967878a4f7905f78b05a9c37457797b1c7ed (patch)
tree73b2c4359c9138b5fcdf2675a3bcbf363b9fc2b0 /libiberty/simple-object-elf.c
parent754dd2b00f2bd3f2d7aaacdb27375bc6faf1458e (diff)
downloadgdb-b55f967878a4f7905f78b05a9c37457797b1c7ed.zip
gdb-b55f967878a4f7905f78b05a9c37457797b1c7ed.tar.gz
gdb-b55f967878a4f7905f78b05a9c37457797b1c7ed.tar.bz2
Sync libiberty with upstream GCC.
include/ChangeLog * libiberty.h (PEX_STDOUT_APPEND): New flag. (PEX_STDERR_APPEND): Likewise. * demangle.h (DMGL_DLANG): New macro. (DMGL_STYLE_MASK): Add DMGL_DLANG. (demangling_styles): Add dlang_demangling. (DLANG_DEMANGLING_STYLE_STRING): New macro. (DLANG_DEMANGLING): New macro. (dlang_demangle): New prototype. * longlong.h: Add __udiv_w_sdiv prototype. libiberty/ChangeLog * cp-demangle.c (d_substitution): Handle abi tags on abbreviation. * pex-common.h (struct pex_funcs): Add new parameter for open_write field. * pex-unix.c (pex_unix_open_write): Add support for new parameter. * pex-djgpp.c (pex_djgpp_open_write): Likewise. * pex-win32.c (pex_win32_open_write): Likewise. * pex-common.c (pex_run_in_environment): Likewise. * Makefile.in (CFILES): Add d-demangle.c. (REQUIRED_OFILES): Add d-demangle.o. * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case. (cplus_demangle): Likewise. * d-demangle.c: New file. * testsuite/Makefile.in (really-check): Add check-d-demangle. * testsuite/d-demangle-expected: New file. * simple-object-elf.c (simple_object_elf_write_ehdr): Correctly handle objects with more than SHN_LORESERVE sections. (simple_object_elf_write_shdr): Add sh_link parameter. (simple_object_elf_write_to_file): Correctly handle objects with more than SHN_LORESERVE sections. * cp-demangle.c (d_dump): Only access field from s_fixed part of the union for DEMANGLE_COMPONENT_FIXED_TYPE. (d_count_templates_scopes): Likewise. * testsuite/demangler-fuzzer.c: New file. * testsuite/Makefile.in (fuzz-demangler): New rule. (demangler-fuzzer): Likewise. (mostlyclean): Clean up demangler fuzzer.
Diffstat (limited to 'libiberty/simple-object-elf.c')
-rw-r--r--libiberty/simple-object-elf.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/libiberty/simple-object-elf.c b/libiberty/simple-object-elf.c
index 4196c53..8594cf9 100644
--- a/libiberty/simple-object-elf.c
+++ b/libiberty/simple-object-elf.c
@@ -698,6 +698,7 @@ simple_object_elf_write_ehdr (simple_object_write *sobj, int descriptor,
unsigned char buf[sizeof (Elf64_External_Ehdr)];
simple_object_write_section *section;
unsigned int shnum;
+ unsigned int shstrndx;
fns = attrs->type_functions;
cl = attrs->ei_class;
@@ -743,9 +744,17 @@ simple_object_elf_write_ehdr (simple_object_write *sobj, int descriptor,
(cl == ELFCLASS32
? sizeof (Elf32_External_Shdr)
: sizeof (Elf64_External_Shdr)));
- ELF_SET_FIELD (fns, cl, Ehdr, buf, e_shnum, Elf_Half, shnum);
- ELF_SET_FIELD (fns, cl, Ehdr, buf, e_shstrndx, Elf_Half,
- shnum == 0 ? 0 : shnum - 1);
+ ELF_SET_FIELD (fns, cl, Ehdr, buf, e_shnum, Elf_Half,
+ shnum >= SHN_LORESERVE ? 0 : shnum);
+ if (shnum == 0)
+ shstrndx = 0;
+ else
+ {
+ shstrndx = shnum - 1;
+ if (shstrndx >= SHN_LORESERVE)
+ shstrndx = SHN_XINDEX;
+ }
+ ELF_SET_FIELD (fns, cl, Ehdr, buf, e_shstrndx, Elf_Half, shstrndx);
return simple_object_internal_write (descriptor, 0, buf, ehdr_size,
errmsg, err);
@@ -758,8 +767,8 @@ simple_object_elf_write_shdr (simple_object_write *sobj, int descriptor,
off_t offset, unsigned int sh_name,
unsigned int sh_type, unsigned int sh_flags,
unsigned int sh_offset, unsigned int sh_size,
- unsigned int sh_addralign, const char **errmsg,
- int *err)
+ unsigned int sh_link, unsigned int sh_addralign,
+ const char **errmsg, int *err)
{
struct simple_object_elf_attributes *attrs =
(struct simple_object_elf_attributes *) sobj->data;
@@ -781,7 +790,7 @@ simple_object_elf_write_shdr (simple_object_write *sobj, int descriptor,
ELF_SET_FIELD (fns, cl, Shdr, buf, sh_flags, Elf_Addr, sh_flags);
ELF_SET_FIELD (fns, cl, Shdr, buf, sh_offset, Elf_Addr, sh_offset);
ELF_SET_FIELD (fns, cl, Shdr, buf, sh_size, Elf_Addr, sh_size);
- /* sh_link left as zero. */
+ ELF_SET_FIELD (fns, cl, Shdr, buf, sh_link, Elf_Word, sh_link);
/* sh_info left as zero. */
ELF_SET_FIELD (fns, cl, Shdr, buf, sh_addralign, Elf_Addr, sh_addralign);
/* sh_entsize left as zero. */
@@ -812,6 +821,8 @@ simple_object_elf_write_to_file (simple_object_write *sobj, int descriptor,
unsigned int shnum;
size_t shdr_offset;
size_t sh_offset;
+ unsigned int first_sh_size;
+ unsigned int first_sh_link;
size_t sh_name;
unsigned char zero;
@@ -842,8 +853,17 @@ simple_object_elf_write_to_file (simple_object_write *sobj, int descriptor,
shdr_offset = ehdr_size;
sh_offset = shdr_offset + shnum * shdr_size;
+ if (shnum < SHN_LORESERVE)
+ first_sh_size = 0;
+ else
+ first_sh_size = shnum;
+ if (shnum - 1 < SHN_LORESERVE)
+ first_sh_link = 0;
+ else
+ first_sh_link = shnum - 1;
if (!simple_object_elf_write_shdr (sobj, descriptor, shdr_offset,
- 0, 0, 0, 0, 0, 0, &errmsg, err))
+ 0, 0, 0, 0, first_sh_size, first_sh_link,
+ 0, &errmsg, err))
return errmsg;
shdr_offset += shdr_size;
@@ -887,7 +907,7 @@ simple_object_elf_write_to_file (simple_object_write *sobj, int descriptor,
if (!simple_object_elf_write_shdr (sobj, descriptor, shdr_offset,
sh_name, SHT_PROGBITS, 0, sh_offset,
- sh_size, 1U << section->align,
+ sh_size, 0, 1U << section->align,
&errmsg, err))
return errmsg;
@@ -898,7 +918,7 @@ simple_object_elf_write_to_file (simple_object_write *sobj, int descriptor,
if (!simple_object_elf_write_shdr (sobj, descriptor, shdr_offset,
sh_name, SHT_STRTAB, 0, sh_offset,
- sh_name + strlen (".shstrtab") + 1,
+ sh_name + strlen (".shstrtab") + 1, 0,
1, &errmsg, err))
return errmsg;