From patchwork Tue Oct 31 12:56:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 23992 Received: (qmail 28914 invoked by alias); 31 Oct 2017 12:56:27 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 28905 invoked by uid 89); 31 Oct 2017 12:56:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pg0-f65.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=2x8hrCtL2SiBerfrCIScfyaNPJ7RThWWABO82bvjor0=; b=d8D8VWmFFkdpcJn1+XfEsEDxeENYVhLXAplrMWJ8GIJcva7wNpSXS/zDbWR5eYua0d UI5Cwb+YJdfvebv2IfS1lq1VshEsSIB7+geoqHWlE1VyFuUHuPL2ZJ9I0zOsL6gqhGzJ bdY+z6q4buWXcunFxAKcjafrpyxk2xQ1/OWl2W+nMdoTHBXEam8GyG0+1I9Rrvtaa6ua hZUMoz2KODoHiHrqfqyGtG6fi0oV/yBUbRJLjb56kKZMfoKRsQGlH0RY41brp1jR5NcW gsLb0tl3V3hZTnO43Jcsxmq7yeYHnkGSKXTGGiPm42kj+beNrmzEzwIktUxZM81KWqse ogBQ== X-Gm-Message-State: AMCzsaXL5h8PKidU6KbBgyKiJr541JwKWYpXLlAs5RAjCWREm26saR8a gylm3+T6sqDfYzAjAF5dGHI/Hg== X-Google-Smtp-Source: ABhQp+QAZ7VdW0rF6o0syrdPqvevdEdPE2GgDYa2F4OZ2fJ3ppHqgJSlrGIK7qj15oMZuyyrNupqdQ== X-Received: by 10.98.201.87 with SMTP id k84mr1998475pfg.109.1509454583597; Tue, 31 Oct 2017 05:56:23 -0700 (PDT) Date: Tue, 31 Oct 2017 05:56:22 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] Replace ROUND with ALIGN_UP by p_align [BZ #22370] Message-ID: <20171031125622.GA18905@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.1 (2017-09-22) Alignment of notes in PT_NOTE segment is specified by the p_align field in the PT_NOTE segment header. This patch replaces ROUND with ALIGN_UP by p_align to scan notes in PT_NOTE segment. Tested on i686 and x86-64. Any comments? H.J. --- [BZ #22370] * dl-hwcaps.c (ROUND): Removed. (_dl_important_hwcaps): Replace ROUND with ALIGN_UP by p_align. * elf/dl-load.c (ROUND): Removed. (open_verify): Replace ROUND with ALIGN_UP by p_align. * elf/readelflib.c (ROUND): Removed. (process_elf_file): Replace ROUND with ALIGN_UP by p_align. --- elf/dl-hwcaps.c | 9 +++++---- elf/dl-load.c | 6 +++--- elf/readelflib.c | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c index 92f2eb45ce..de271a6fc8 100644 --- a/elf/dl-hwcaps.c +++ b/elf/dl-hwcaps.c @@ -67,6 +67,7 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz, { const ElfW(Addr) start = (phdr[i].p_vaddr + GLRO(dl_sysinfo_map)->l_addr); + const ElfW(Addr) align = phdr[i].p_align; /* The standard ELF note layout is exactly as the anonymous struct. The next element is a variable length vendor name of length VENDORLEN (with a real length rounded to ElfW(Word)), followed @@ -80,7 +81,6 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz, } *note = (const void *) start; while ((ElfW(Addr)) (note + 1) - start < phdr[i].p_memsz) { -#define ROUND(len) (((len) + sizeof (ElfW(Word)) - 1) & -sizeof (ElfW(Word))) /* The layout of the type 2, vendor "GNU" note is as follows: .long .long (as mask >> _DL_FIRST_EXTRA). @@ -92,7 +92,8 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz, && note->datalen > 2 * sizeof (ElfW(Word)) + 2) { const ElfW(Word) *p = ((const void *) (note + 1) - + ROUND (sizeof "GNU")); + + ALIGN_UP (sizeof "GNU", + sizeof (ElfW(Word)))); cnt += *p++; ++p; /* Skip mask word. */ dsocaps = (const char *) p; /* Pseudo-string "name" */ @@ -100,8 +101,8 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz, break; } note = ((const void *) (note + 1) - + ROUND (note->vendorlen) + ROUND (note->datalen)); -#undef ROUND + + ALIGN_UP (note->vendorlen, align) + + ALIGN_UP (note->datalen, align)); } if (dsocaps != NULL) break; diff --git a/elf/dl-load.c b/elf/dl-load.c index 1220183ce2..8fdfadd41e 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1683,6 +1683,7 @@ open_verify (const char *name, int fd, if (ph->p_type == PT_NOTE && ph->p_filesz >= 32 && ph->p_align >= 4) { ElfW(Addr) size = ph->p_filesz; + ElfW(Addr) align = ph->p_align; if (ph->p_offset + size <= (size_t) fbp->len) abi_note = (void *) (fbp->buf + ph->p_offset); @@ -1696,10 +1697,9 @@ open_verify (const char *name, int fd, while (memcmp (abi_note, &expected_note, sizeof (expected_note))) { -#define ROUND(len) (((len) + sizeof (ElfW(Word)) - 1) & -sizeof (ElfW(Word))) ElfW(Addr) note_size = 3 * sizeof (ElfW(Word)) - + ROUND (abi_note[0]) - + ROUND (abi_note[1]); + + ALIGN_UP (abi_note[0], align) + + ALIGN_UP (abi_note[1], align); if (size - 32 < note_size) { diff --git a/elf/readelflib.c b/elf/readelflib.c index 9ad56dcc34..247afa7de2 100644 --- a/elf/readelflib.c +++ b/elf/readelflib.c @@ -131,15 +131,15 @@ process_elf_file (const char *file_name, const char *lib, int *flag, ElfW(Word) *abi_note = (ElfW(Word) *) (file_contents + segment->p_offset); ElfW(Addr) size = segment->p_filesz; + ElfW(Addr) align = segment->p_align; while (abi_note [0] != 4 || abi_note [1] != 16 || abi_note [2] != 1 || memcmp (abi_note + 3, "GNU", 4) != 0) { -#define ROUND(len) (((len) + sizeof (ElfW(Word)) - 1) & -sizeof (ElfW(Word))) ElfW(Addr) note_size = 3 * sizeof (ElfW(Word)) - + ROUND (abi_note[0]) - + ROUND (abi_note[1]); + + ALIGN_UP (abi_note[0], align) + + ALIGN_UP (abi_note[1], align); if (size - 32 < note_size || note_size == 0) {