aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2006-10-31 02:36:18 +0000
committerAlan Modra <amodra@gmail.com>2006-10-31 02:36:18 +0000
commita39f33461a71ec868be8917625b10bd66ab23eef (patch)
tree832b16f41053c7ece7683db83fdf978f67108040 /bfd
parentee9e139d63a2dfaeabadc16348ddbefb055917d0 (diff)
downloadgdb-a39f33461a71ec868be8917625b10bd66ab23eef.zip
gdb-a39f33461a71ec868be8917625b10bd66ab23eef.tar.gz
gdb-a39f33461a71ec868be8917625b10bd66ab23eef.tar.bz2
* elf.c (elfcore_write_note): Pad note descriptor to 4-byte
boundary. Tidy. Comment.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/elf.c47
2 files changed, 29 insertions, 23 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index cd3a99f..788c9e2 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,4 +1,7 @@
-bfd/
+2006-10-31 Alan Modra <amodra@bigpond.net.au>
+
+ * elf.c (elfcore_write_note): Pad note descriptor to 4-byte
+ boundary. Tidy. Comment.
2006-10-30 H.J. Lu <hongjiu.lu@intel.com>
diff --git a/bfd/elf.c b/bfd/elf.c
index 2594e21..9550ab1 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -8088,45 +8088,42 @@ elfcore_grok_nto_note (bfd *abfd, Elf_Internal_Note *note)
/* Function: elfcore_write_note
Inputs:
- buffer to hold note
+ buffer to hold note, and current size of buffer
name of note
type of note
data for note
size of data for note
+ Writes note to end of buffer. ELF64 notes are written exactly as
+ for ELF32, despite the current (as of 2006) ELF gabi specifying
+ that they ought to have 8-byte namesz and descsz field, and have
+ 8-byte alignment. Other writers, eg. Linux kernel, do the same.
+
Return:
- End of buffer containing note. */
+ Pointer to realloc'd buffer, *BUFSIZ updated. */
char *
-elfcore_write_note (bfd *abfd,
+elfcore_write_note (bfd *abfd,
char *buf,
- int *bufsiz,
+ int *bufsiz,
const char *name,
- int type,
+ int type,
const void *input,
- int size)
+ int size)
{
Elf_External_Note *xnp;
size_t namesz;
- size_t pad;
size_t newspace;
- char *p, *dest;
+ char *dest;
namesz = 0;
- pad = 0;
if (name != NULL)
- {
- const struct elf_backend_data *bed;
-
- namesz = strlen (name) + 1;
- bed = get_elf_backend_data (abfd);
- pad = -namesz & 3;
- }
+ namesz = strlen (name) + 1;
- newspace = 12 + namesz + pad + size;
+ newspace = 12 + ((namesz + 3) & -4) + ((size + 3) & -4);
- p = realloc (buf, *bufsiz + newspace);
- dest = p + *bufsiz;
+ buf = realloc (buf, *bufsiz + newspace);
+ dest = buf + *bufsiz;
*bufsiz += newspace;
xnp = (Elf_External_Note *) dest;
H_PUT_32 (abfd, namesz, xnp->namesz);
@@ -8137,14 +8134,20 @@ elfcore_write_note (bfd *abfd,
{
memcpy (dest, name, namesz);
dest += namesz;
- while (pad != 0)
+ while (namesz & 3)
{
*dest++ = '\0';
- --pad;
+ ++namesz;
}
}
memcpy (dest, input, size);
- return p;
+ dest += size;
+ while (size & 3)
+ {
+ *dest++ = '\0';
+ ++size;
+ }
+ return buf;
}
#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)