From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14443 invoked by alias); 18 Oct 2019 19:59:37 -0000 Mailing-List: contact glibc-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: glibc-cvs-owner@sourceware.org List-Subscribe: Received: (qmail 14397 invoked by uid 9587); 18 Oct 2019 19:59:37 -0000 Date: Fri, 18 Oct 2019 19:59:00 -0000 Message-ID: <20191018195937.14395.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Carlos O'Donell To: glibc-cvs@sourceware.org Subject: [glibc] elf: Use nocancel pread64() instead of lseek()+read() X-Act-Checkin: glibc X-Git-Author: Leandro Pereira X-Git-Refname: refs/heads/master X-Git-Oldrev: fed33b0fb03d1942a6713286176d42869c0f1580 X-Git-Newrev: 95c1056962a3f2297c94ce47f0eaf0c5b6563231 X-SW-Source: 2019-q4/txt/msg00112.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=95c1056962a3f2297c94ce47f0eaf0c5b6563231 commit 95c1056962a3f2297c94ce47f0eaf0c5b6563231 Author: Leandro Pereira Date: Wed Oct 2 12:48:17 2019 -0400 elf: Use nocancel pread64() instead of lseek()+read() Transforms this, when linking in a shared object: openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3"..., 832) = 832 lseek(3, 792, SEEK_SET) = 792 read(3, "\4\0\0\0\24\0\0\0"..., 68) = 68 fstat(3, {st_mode=S_IFREG|0755, st_size=6699224, ...}) = 0 lseek(3, 792, SEEK_SET) = 792 read(3, "\4\0\0\0\24\0\0\0"..., 68) = 68 lseek(3, 864, SEEK_SET) = 864 read(3, "\4\0\0\0\20\0\0\0"..., 32) = 32 Into this: openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3"..., 832) = 832 pread(3, "\4\0\0\0\24\0\0\0"..., 68, 792) = 68 fstat(3, {st_mode=S_IFREG|0755, st_size=6699224, ...}) = 0 pread(3, "\4\0\0\0\24\0\0\0"..., 68, 792) = 68 pread(3, "\4\0\0\0\20\0\0\0"..., 32, 864) = 32 Reviewed-by: Carlos O'Donell Diff: --- elf/dl-load.c | 13 ++++++------- sysdeps/x86/dl-prop.h | 3 +-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 1ed7a7b..c1bc8c2 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1015,8 +1015,8 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, else { phdr = alloca (maplength); - __lseek (fd, header->e_phoff, SEEK_SET); - if ((size_t) __read_nocancel (fd, (void *) phdr, maplength) != maplength) + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, + header->e_phoff) != maplength) { errstring = N_("cannot read file data"); goto call_lose_errno; @@ -1664,9 +1664,8 @@ open_verify (const char *name, int fd, else { phdr = alloca (maplength); - __lseek (fd, ehdr->e_phoff, SEEK_SET); - if ((size_t) __read_nocancel (fd, (void *) phdr, maplength) - != maplength) + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, + ehdr->e_phoff) != maplength) { read_error: errval = errno; @@ -1704,8 +1703,8 @@ open_verify (const char *name, int fd, abi_note = abi_note_malloced; } - __lseek (fd, ph->p_offset, SEEK_SET); - if (__read_nocancel (fd, (void *) abi_note, size) != size) + if (__pread64_nocancel (fd, (void *) abi_note, size, + ph->p_offset) != size) { free (abi_note_malloced); goto read_error; diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h index a99eec1..fa5bd98 100644 --- a/sysdeps/x86/dl-prop.h +++ b/sysdeps/x86/dl-prop.h @@ -167,8 +167,7 @@ _dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph, note_malloced = malloc (size); note = note_malloced; } - __lseek (fd, ph->p_offset, SEEK_SET); - if (__read_nocancel (fd, (void *) note, size) != size) + if (__pread64_nocancel (fd, (void *) note, size, ph->p_offset) != size) { if (note_malloced) free (note_malloced);