From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id E5EEC384D15D for ; Thu, 20 Oct 2022 18:26:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5EEC384D15D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1031.google.com with SMTP id a6-20020a17090abe0600b0020d7c0c6650so4365998pjs.0 for ; Thu, 20 Oct 2022 11:26:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uBTW2cWd9xOnKFiRZuIQaiEKXSIvNtrFYGz1TralyqY=; b=SKUvrJEFPshKJBNW+MjEpHKlODfj/0uqN4e1H+Vg0DOHNYByZXWfGuebu9iN1AjNJ+ 3SHC6mMOa/KHGuW3LgGkBByknRI2z6kPaW0r37aWpkQJEcer7SqyCjYggIuWij5wdHq7 K5jQgme+m9+LYlzmPXup5hglE/pop7eF3kZTUSW5ySpADLyg9otw0mBYQHJHj3ZjY1zA EjlBLENKKCOSz/K5su5KR5iYgva79bGct//KV5vi2F7m8J937Wo36DwfhroJW7MMgj+4 nMsIxzaeCBr+Upxl6ssHPB3Nw5s1jKXrKPxm68wnpMFop/K2UBnKwAYWJmEuniCEQvEh l+mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uBTW2cWd9xOnKFiRZuIQaiEKXSIvNtrFYGz1TralyqY=; b=FF8GgNsS9nqDVZZgJtSccS7l7/9ea/pE3rkCkgBlo42hlMIthwtG8Yth2yUStkDp7Z 6Y6tn2mxwQGpzlTrfW7KxlwIXBA043rKXzNN7PmFnzPEK3Tr3k9NPMQyGAQrOKPCuqxd Cvbq2gjECAT1o/VABispV6xQzh4KezeO19VkOcDSpvqVZUaEA5sTjZOtRw7OlTUWH6S2 F6Ogqok5pUqwbtIQLrS3Tqawp9HajYRGa7wkzmpQkngkaFrbHs+lUfZJ5zT0AMKyFaXR LQv5T9pPU/jAU204VLzirC+cCKawOmZxZueVkhpORyZ9fctzXk1Q1Ayr5I15PG0ts4li sFjQ== X-Gm-Message-State: ACrzQf3llvsJzDd7CmrDISyMNgDSdd8+GVEVdhq1BU27CTlFcb5rhhNy o1ztVlRy9OaOAtkdU0fG89rcueEQ8aA2vw== X-Google-Smtp-Source: AMsMyM73MriPzjd1zyfkAXc56Z06Wfo1o0QdkiqbkeZzgEQssUYWgqo4hB79mg++v8GJDlQRCvTJ3w== X-Received: by 2002:a17:903:11cd:b0:170:cde8:18b7 with SMTP id q13-20020a17090311cd00b00170cde818b7mr15231547plh.165.1666290397514; Thu, 20 Oct 2022 11:26:37 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id w15-20020a17090a460f00b00202fbd9c21dsm115067pjg.48.2022.10.20.11.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 11:26:36 -0700 (PDT) From: Yonggang Luo To: elfutils-devel@sourceware.org Cc: Yonggang Luo Subject: [PATCH 08/25] Use configure to detect HAVE_DECL_MMAP and use it for system doesn't provide sys/mman.h Date: Fri, 21 Oct 2022 02:25:47 +0800 Message-Id: <20221020182603.815-9-luoyonggang@gmail.com> X-Mailer: git-send-email 2.36.1.windows.1 In-Reply-To: <20221020182603.815-1-luoyonggang@gmail.com> References: <20221020182603.815-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Signed-off-by: Yonggang Luo --- configure.ac | 1 + lib/crc32_file.c | 4 ++-- lib/system.h | 2 ++ libelf/elf32_updatefile.c | 3 ++- libelf/elf_begin.c | 5 ++++- libelf/elf_end.c | 2 ++ libelf/elf_update.c | 5 ++++- 7 files changed, 17 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 03b67a9d..63aeb748 100644 --- a/configure.ac +++ b/configure.ac @@ -428,6 +428,7 @@ AC_CHECK_DECLS([memrchr, rawmemchr],[],[], [#define _GNU_SOURCE #include ]) AC_CHECK_DECLS([powerof2],[],[],[#include ]) +AC_CHECK_DECLS([mmap],[],[],[#include ]) AC_CHECK_DECLS([mempcpy],[],[], [#define _GNU_SOURCE #include ]) diff --git a/lib/crc32_file.c b/lib/crc32_file.c index f7607d0b..66833702 100644 --- a/lib/crc32_file.c +++ b/lib/crc32_file.c @@ -32,9 +32,7 @@ #include "libeu.h" #include -#include #include -#include #include "system.h" int @@ -45,6 +43,7 @@ crc32_file (int fd, uint32_t *resp) off_t off = 0; ssize_t count; +#if HAVE_DECL_MMAP struct stat st; if (fstat (fd, &st) == 0) { @@ -78,6 +77,7 @@ crc32_file (int fd, uint32_t *resp) munmap (mapped, mapsize); } } +#endif while ((count = TEMP_FAILURE_RETRY (pread (fd, buffer, sizeof buffer, off))) > 0) diff --git a/lib/system.h b/lib/system.h index bbbe06c4..561d3e03 100644 --- a/lib/system.h +++ b/lib/system.h @@ -42,7 +42,9 @@ /* System dependend headers */ #include #include +#if HAVE_DECL_MMAP #include +#endif #include #include diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c index 46afa1f4..8229fd26 100644 --- a/libelf/elf32_updatefile.c +++ b/libelf/elf32_updatefile.c @@ -96,7 +96,7 @@ sort_sections (Elf_Scn **scns, Elf_ScnList *list) qsort (scns, scnp - scns, sizeof (*scns), compare_sections); } - +#if HAVE_DECL_MMAP static inline void fill_mmap (size_t offset, char *last_position, char *scn_start, char *const shdr_start, char *const shdr_end) @@ -482,6 +482,7 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t shnum) return 0; } +#endif /* Size of the buffer we use to generate the blocks of fill bytes. */ diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c index fe8c640a..6d31882e 100644 --- a/libelf/elf_begin.c +++ b/libelf/elf_begin.c @@ -645,10 +645,12 @@ static struct Elf * read_file (int fildes, int64_t offset, size_t maxsize, Elf_Cmd cmd, Elf *parent) { +#if HAVE_DECL_MMAP void *map_address = NULL; int use_mmap = (cmd == ELF_C_READ_MMAP || cmd == ELF_C_RDWR_MMAP || cmd == ELF_C_WRITE_MMAP || cmd == ELF_C_READ_MMAP_PRIVATE); +#endif if (parent == NULL) { @@ -669,7 +671,7 @@ read_file (int fildes, int64_t offset, size_t maxsize, /* The parent is already loaded. Use it. */ assert (maxsize != ~((size_t) 0)); } - +#if HAVE_DECL_MMAP if (use_mmap) { if (parent == NULL) @@ -713,6 +715,7 @@ read_file (int fildes, int64_t offset, size_t maxsize, return result; } +#endif /* Otherwise we have to do it the hard way. We read as much as necessary from the file whenever we need information which is not available. */ diff --git a/libelf/elf_end.c b/libelf/elf_end.c index 5c451f36..8023b216 100644 --- a/libelf/elf_end.c +++ b/libelf/elf_end.c @@ -222,8 +222,10 @@ elf_end (Elf *elf) /* The file was read or mapped for this descriptor. */ if ((elf->flags & ELF_F_MALLOCED) != 0) free (elf->map_address); +#if HAVE_DECL_MMAP else if ((elf->flags & ELF_F_MMAPPED) != 0) munmap (elf->map_address, elf->maximum_size); +#endif } rwlock_unlock (elf->lock); diff --git a/libelf/elf_update.c b/libelf/elf_update.c index 56af3a1c..e81eb6c9 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -64,7 +64,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); return -1; } - +#if HAVE_DECL_MMAP /* Try to map the file if this isn't done yet. */ if (elf->map_address == NULL && elf->cmd == ELF_C_WRITE_MMAP) { @@ -125,6 +125,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t shnum) size = -1; } else +#endif { /* The file is not mmaped. */ if ((class == ELFCLASS32 @@ -145,6 +146,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t shnum) size = -1; } +#if HAVE_DECL_MMAP /* POSIX says that ftruncate and write may clear the S_ISUID and S_ISGID mode bits. So make sure we restore them afterwards if they were set. This is not atomic if someone else chmod's the file while we operate. */ @@ -156,6 +158,7 @@ write_file (Elf *elf, int64_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); size = -1; } +#endif if (size != -1 && elf->parent == NULL) elf->maximum_size = size; -- 2.36.1.windows.1