]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - include/elf/external.h
Re-apply "elf: Properly compute offsets of note descriptor and next note"
[thirdparty/binutils-gdb.git] / include / elf / external.h
index d65bae0b2187c6580a2deabd6c724d6da809888a..eb0a53a9a9c3bb1c3e9137df3bec5d2552286621 100644 (file)
@@ -183,6 +183,22 @@ typedef struct {
   char         name[1];                /* Start of the name+desc data */
 } Elf_External_Note;
 
+/* Align an address upward to a boundary, expressed as a number of bytes.
+   E.g. align to an 8-byte boundary with argument of 8.  */
+#define ELF_ALIGN_UP(addr, boundary) \
+  (((bfd_vma) (addr) + ((boundary) - 1)) & ~ (bfd_vma) ((boundary) -1))
+
+/* Compute the offset of the note descriptor from size of note entry's
+   owner string and note alignment.  */
+#define ELF_NOTE_DESC_OFFSET(namesz, align) \
+  ELF_ALIGN_UP (offsetof (Elf_External_Note, name) + (namesz), (align))
+
+/* Compute the offset of the next note entry from size of note entry's
+   owner string, size of the note descriptor and note alignment.  */
+#define ELF_NOTE_NEXT_OFFSET(namesz, descsz, align) \
+  ELF_ALIGN_UP (ELF_NOTE_DESC_OFFSET ((namesz), (align)) + (descsz), \
+               (align))
+
 /* Relocation Entries */
 typedef struct {
   unsigned char r_offset[4];   /* Location at which to apply the action */