mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-26 23:10:06 +00:00
8d81ce0c6d
A note header has 3 4-bytes fields, followed by note name and note descriptor. According to gABI, in a note entry, the note name field, not note name size, is padded for the note descriptor. And the note descriptor field, not note descriptor size, is padded for the next note entry. Notes are aligned to 4 bytes in 32-bit objects and 8 bytes in 64-bit objects. For all GNU notes, the name is "GNU" which is 4 bytes. They have the same format in the first 16 bytes in both 32-bit and 64-bit objects. They differ by note descriptor size and note type. So far, .note.ABI-tag and .note.gnu.build-id notes are always aligned to 4 bytes. The exsting codes compute the note size by aligning the note name size and note descriptor size to 4 bytes. It happens to produce the same value as the actual note size by luck since the name size is 4 and offset of the note descriptor is 16. But it will produce the wrong size when note alignment is 8 bytes in 64-bit objects. This patch defines ELF_NOTE_DESC_OFFSET and ELF_NOTE_NEXT_OFFSET to properly compute offsets of note descriptor and next note. It uses alignment of PT_NOTE segment to support both 4-byte and 8-byte note alignments in 64-bit objects. To handle PT_NOTE segments with incorrect alignment, which may lead to an infinite loop, if segment alignment is less than 4, we treate alignment as 4 bytes since some note segments have 0 or 1 byte alignment. [BZ #22370] * elf/dl-hwcaps.c (ROUND): Removed. (_dl_important_hwcaps): Replace ROUND with ELF_NOTE_DESC_OFFSET and ELF_NOTE_NEXT_OFFSET. * elf/dl-load.c (ROUND): Removed. (open_verify): Replace ROUND with ELF_NOTE_NEXT_OFFSET. * elf/readelflib.c (ROUND): Removed. (process_elf_file): Replace ROUND with ELF_NOTE_NEXT_OFFSET. * include/elf.h [!_ISOMAC]: Include <libc-pointer-arith.h>. [!_ISOMAC] (ELF_NOTE_DESC_OFFSET): New. [!_ISOMAC] (ELF_NOTE_NEXT_OFFSET): Likewise.
30 lines
935 B
C
30 lines
935 B
C
#ifndef _ELF_H
|
|
#include <elf/elf.h>
|
|
|
|
#ifndef _ISOMAC
|
|
|
|
# include <libc-pointer-arith.h>
|
|
|
|
/* 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) \
|
|
ALIGN_UP (sizeof (ElfW(Nhdr)) + (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) \
|
|
ALIGN_UP (ELF_NOTE_DESC_OFFSET ((namesz), (align)) + (descsz), (align))
|
|
|
|
/* Some information which is not meant for the public and therefore not
|
|
in <elf.h>. */
|
|
# include <dl-dtprocnum.h>
|
|
# ifdef DT_1_SUPPORTED_MASK
|
|
# error DT_1_SUPPORTED_MASK is defined!
|
|
# endif
|
|
# define DT_1_SUPPORTED_MASK \
|
|
(DF_1_NOW | DF_1_NODELETE | DF_1_INITFIRST | DF_1_NOOPEN \
|
|
| DF_1_ORIGIN | DF_1_NODEFLIB)
|
|
|
|
#endif /* !_ISOMAC */
|
|
#endif /* elf.h */
|