From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 100215 invoked by alias); 4 May 2017 09:50:44 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 100168 invoked by uid 89); 4 May 2017 09:50:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=51214, affair X-Spam-Status: No, score=-25.7 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-ve1eur01on0128.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.128) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 May 2017 09:50:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qtcompany.onmicrosoft.com; s=selector1-qt-io; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=x9Kk80mwqgqebwYPWu1bs+QhszBhBVANUKRlkVaC95Y=; b=VE1NLTExZOPVXGNmOa3i+qNkOO9R4jQIE64KwYpYWq3bJ5DbxHPWJBm/owiCTIuijNRXPK+VE76C+lmW4+iitIkElZ5ahBG3cc00UFZ+iYTtHB+PF+bTHT9rGErynPxHsFfod7cOBU9sLYm8phIscAw/tVaTXGzpWL+33q0QI/A= Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=qt.io; Received: from [10.9.78.56] (62.220.2.194) by AMSPR02MB230.eurprd02.prod.outlook.com (2a01:111:e400:8022::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1061.12; Thu, 4 May 2017 09:50:39 +0000 From: Ulf Hermann Subject: [PATCH] Skip fchown, fchmod, fadvise, fallocate if functions are unavailable To: Message-ID: <9bf3cb69-d521-d42f-f37d-47e166f0fe61@qt.io> Date: Thu, 04 May 2017 10:00:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [62.220.2.194] X-ClientProxiedBy: DB6PR1001CA0041.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::27) To AMSPR02MB230.eurprd02.prod.outlook.com (2a01:111:e400:8022::17) X-MS-Office365-Filtering-Correlation-Id: d6c57319-76f9-47d4-0adc-08d492d30574 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:AMSPR02MB230; X-Microsoft-Exchange-Diagnostics: 1;AMSPR02MB230;3:965bjCV6YoUlKEVPkfQGsYYRN1vTkAYRds41K5C52bDl+gckhgqEB+i+lfqbJrxjs26E7sNikxib5zlA1Cfbaj838niDCIykmc1ncojgXwV/eNHRaGTkOmG7WLykAJMtH1oD7IlQDNaXZFXDG5zthL0FAjITRbEyov1U9IpZaC/Y3uvgzQ2o1w/ABYEnVbifPVtdZw8b+rdlcyIjqkCQYIcaJf9KoJdmumgnwD0eL7go80usShU8i5pbG/BHS9Mdpj+r8+nJIunBwGTQinMPd4QyX756NAtniffs5xFIxBjp5gJ44Dco+bGDMd+AQlxsk/odRH11NAR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: X-Exchange-Antispam-Report-Test: UriScan:(788757137089); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123558100)(20161123560025)(20161123555025)(6072148);SRVR:AMSPR02MB230;BCL:0;PCL:0;RULEID:;SRVR:AMSPR02MB230; X-Microsoft-Exchange-Diagnostics: 1;AMSPR02MB230;4:6XGcu22c7icVYuE47HHiwzStQwb6ER0mKLnq/BuH2JRoy98i+jsZO1nByZh5lMGPc3Qo8dWcVidKjB9lL+ovOX7RGFzn/h2yIhnSmzef+cJeOYElke0Yh0U52TXy+z490HEHoFHxR7NG6U1QkExMEZ+N6yxJL0w4CUhy9tNkHNatH4L870BQF1vUK4XefMv6V8jBDpzABTucn/ORGzfyUJ5N3hvdKAhjlkMPDGN2iQUnbbeDcC1z3ApkX5KwbP+SVCLiggmwWAyd64/ZNEiMyxMCDlW12aU9AJ5tgWTbgHcSivv5EH/uxQTDqbFJkKAJTZMQhgXA3q9Gj8GzAkTkV3fYo8B5srcqOnahQ/fL9eZi5rTqasQyRHUeThNjPC4ss5DApaOlvGNKwpnlmocmuI6Pe5WTKknvOsPmSEQvVZsZiBNvbV4wd3ClB5lygagWX7ozvBmSPwPRzwDWnxstNSlUSBCP/sCMA18dthOzIe8RvoaYAZBAiTp5IZu47/EWr4Mb52kex+s3v0pwvomJ/pVgW6jdlk4jjA7RB+Knl4p/qX5l8bxTLOcJYCo2lnFV04zemWazr8WOu32kbg9f+2B7JATGUHp4GyaN9QvxhA+cRKyt8ECG587FBpjxXeGE0PeL1etpWQAo1mrQWZFWf5Fc6IyA0mUDLEsua3EFmf9otQls8fHNAXBeOBy6G9pZ845Amet3t24gHIFkP70WW/hVSaQ6LtWBNy+gA5sZwh2oLnmX2uYaivOLqKgLqmHuvuM7Ig5A4QNv+l2d9f6RRzUxGnuYGLJfgEB9sB9NOk5ALeVGaIjOv2rNf86MecVlCZGIrAb1VpTUmQQobCVEyg== X-Forefront-PRVS: 02973C87BC X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(377424004)(53936002)(23676002)(5660300001)(65826007)(50466002)(33646002)(74482002)(7736002)(6916009)(305945005)(36756003)(31696002)(86362001)(575784001)(64126003)(83506001)(110136004)(3846002)(25786009)(54356999)(81166006)(50986999)(230700001)(47776003)(478600001)(2906002)(77096006)(6486002)(8676002)(6116002)(66066001)(38730400002)(4001350100001)(189998001)(31686004)(42186005)(2351001);DIR:OUT;SFP:1102;SCL:1;SRVR:AMSPR02MB230;H:[10.9.78.56];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTVNQUjAyTUIyMzA7MjM6Z0M5VXdsam0yaENMSFBzb09tUkE1WUJDN2J3?= =?utf-8?B?SXRhdWxUU0p4b2tQSGFwcjMwdzFBWlJvTWJIbUhnZlhKRmIyOTl4S3BZV3R6?= =?utf-8?B?Z24rNm1MS05ZYjN1ZWZtTTk3eUVSbmVzMVFnY1NMQkdwRjgybkQ2ZXNSblV6?= =?utf-8?B?STlSTzkvQVNWQWxzSWswaGJKU1IxdklwRzVnWmQwYlZ1ck50M2FVd3VFWjJj?= =?utf-8?B?R2pvamhwL3A4N3BaWHRyMEVtQTMyN05xMVRFaEV1aGRtQnBzbXNaQzFUT0Jm?= =?utf-8?B?R3NYVHY0elZyQ2x4R3RFSmhmelRtYUFrRzNKTnIxWjlCTFhybVN2NFlLWGlh?= =?utf-8?B?MFEya1dOQ2F1bGk3bkl5K2haMVlVS0tweTZGcTRTbnc2WFFWV1BmbjdhZXZK?= =?utf-8?B?dzNMRTMxaGhWUmJJdmlIZTk1cEhsakdKOGYvUFhwUVNFMmFoZ1RHbG5XRmdZ?= =?utf-8?B?WUNyTVdQOW1rZkdPMy9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8?B?RkZ5MFJzcVg5VFJiaVExbStxNzRlYjh2U1ZhR29rY3VzV2lubzNTVmlmTzg0?= =?utf-8?B?K1JzZ1Z3YTBSbU5ZT2kzMnAydkQ0Qy93TjQ3a1dIQmsxU3N1UExJTUpYeGQv?= =?utf-8?Q?PohQHibR7DcbDOO63wPePjhE0OK4x/EGCcihl7UA6u95M?= X-Microsoft-Exchange-Diagnostics: 1;AMSPR02MB230;6:KcsW5F4VxOOBubwG6extN0WdUmZ8mvBPQrjfFrAmfqQcgN+JRPsrmEplSp5Y/drErWndKFMixi1dNA/Tuwr2oGM1IrxEwLUm1U+Htedjs4qHl8Q77TN4mY824DIz7chuBqkYsvXMC99+smKb/0+crBvUGfqHB4XfTzIPlpLB7mB670Zt9VEMlcm1N/tYwZCCGkha6S+pSuphEoYYcyhxw22sE5khN+MD3p7Qs8C4s2bUp5I4Ei3DoX2+mCBsm3bw8d+FDNa98fxuJXkkkknREtrJKlr72xXyR2za4h5+hf9j7ZasSCqY1IgGYxTGWlQqu0mhA/0UhXgtusHMx3ergeZVtoK4BX7QOZhKK0i3noETu4OK/Bldr6lZv20SMiQUfRHO+f0PS5+23zQpsACDP5F8LuhzNb3NIaxXXrLp2r9yyjJl7JV4UfPXoSceXU3vSDwk5H2tQ14uj3cKZ+HAdunHse70hHNQNvQi9+IpY6k/E1DicSgL9j69J5crp563L8erj7btzl3Mkn2FN/OEoA==;5:+9/MH2r5Qu6em8gBtspGLmkMnS64dVVHKNe6YIi8Kkah1JtTGtUY7l5U7+pXRYVH4Z1rIUXmM1aJYEZWkreJdUwLdHolQSGtUY4zBE3lBagENBSFhiGO2eDxn4aTUocSDo8dTFjY2GLl7WPEvq0n+Q==;24:RNidoX5L03LoYoZHHoc4W0SqonqJhYN470LhohFaCxWxYEOO064CclPankKhqiPxfFrxkwpvrh1SsUhEyO2P01c9fmfXQ2Tpof0AceJHvCI= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AMSPR02MB230;7:DtPWO5XGekozIbE+PTdpzcx1/9dIhiNiaaEnOs6RkY0goxZW3TTz38BOumt35x9YnhUazOK4lCufvFIHxxBlCzKZCjSjtWavyznGkB6CW1cbzVThYc/3wVHTg7z99WHdQ96LeTP+wi7nWIOcVsfQypUl7apnB81q6elaDQf7fJwS6d4pvfHh/Cu5IvUYhGL2EwvtEhXtD1dwcSTcUFjFz3HlJ5pl82Qr4R/FH0F/nOmdE0JFr7JvekjMm4swV9ICCeeQB9J3YB1zViQhCWGqgBLhZQ0qkWbAESp0AknMqUhklKMtaBKVv1q0YMXjmR9jTqLj3ZAqUDiVjOHjahmdSA== X-OriginatorOrg: qt.io X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2017 09:50:39.1697 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AMSPR02MB230 X-IsSubscribed: yes X-SW-Source: 2017-q2/txt/msg00165.txt.bz2 If fchmod or fchown are unavailable, then the file permission model is likely to be different from what we expect there. posix_fallocate is a frather fragile affair already on linux, and not guaranteed to do anything useful. If it's not available, the result will be the same as when it's available and unreliable. fadvise is an optimization. Signed-off-by: Ulf Hermann --- ChangeLog | 5 +++++ configure.ac | 3 +++ libasm/ChangeLog | 4 ++++ libasm/asm_end.c | 2 ++ libelf/ChangeLog | 5 +++++ libelf/elf_update.c | 4 ++++ src/ChangeLog | 9 ++++++++ src/ar.c | 59 +++++++++++++++++++++++++++++++++++------------------ src/elfcompress.c | 4 ++++ src/ranlib.c | 21 +++++++++++-------- src/strings.c | 2 ++ src/strip.c | 5 ++++- tests/ChangeLog | 5 +++++ tests/elfstrmerge.c | 4 ++++ 14 files changed, 103 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a86247..7a40c9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2017-05-04 Ulf Hermann + * configure.ac: Check for posix_fallocate, posix_fadvise, fchown, + fchmod. + +2017-05-04 Ulf Hermann + * configure.ac: Check for tdestroy and node_t. Declare tdestroy in config.h if tdestroy is not available from search.h, but node_t is. diff --git a/configure.ac b/configure.ac index 88b9d0a..e55360d 100644 --- a/configure.ac +++ b/configure.ac @@ -631,6 +631,9 @@ void tdestroy(void *root, void (*free_node)(void *nodep)); #endif ]) +AC_CHECK_DECLS([posix_fallocate, posix_fadvise], [], [], [[#include ]]) +AC_CHECK_DECLS([fchown, fchmod], [], [], [[#include ]]) + dnl Check if we have for EM_BPF disassembly. AC_CHECK_HEADERS(linux/bpf.h) AM_CONDITIONAL(HAVE_LINUX_BPF_H, [test "x$ac_cv_header_linux_bpf_h" = "xyes"]) diff --git a/libasm/ChangeLog b/libasm/ChangeLog index 5321213..2b499c7 100644 --- a/libasm/ChangeLog +++ b/libasm/ChangeLog @@ -1,3 +1,7 @@ +2017-05-04 Ulf Hermann + + * asm_end.c: Don't fchmod the new file if fchmod is unavailable. + 2017-02-28 Ulf Hermann * Makefile.am: Use the predefined common library names rather than diff --git a/libasm/asm_end.c b/libasm/asm_end.c index ced24f5..7fabe94 100644 --- a/libasm/asm_end.c +++ b/libasm/asm_end.c @@ -512,12 +512,14 @@ asm_end (AsmCtx_t *ctx) if (result != 0) return result; +#if HAVE_DECL_FCHMOD /* Make the new file globally readable and user/group-writable. */ if (fchmod (ctx->fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) != 0) { __libasm_seterrno (ASM_E_CANNOT_CHMOD); return -1; } +#endif /* Rename output file. */ if (rename (ctx->tmp_fname, ctx->fname) != 0) diff --git a/libelf/ChangeLog b/libelf/ChangeLog index 0a5200f..fd20ebb 100644 --- a/libelf/ChangeLog +++ b/libelf/ChangeLog @@ -1,3 +1,8 @@ +2017-05-04 Ulf Hermann + + * elf_update.c: Don't try to posix_fallocate on systems where it isn't + available. Don't fchmod the output file if there is no fchmod. + 2017-02-28 Ulf Hermann * Makefile.am: Use the predefined common library names rather than diff --git a/libelf/elf_update.c b/libelf/elf_update.c index 8ce0782..b6014cd 100644 --- a/libelf/elf_update.c +++ b/libelf/elf_update.c @@ -80,6 +80,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) if (elf->map_address != NULL) { +#if HAVE_DECL_POSIX_FALLOCATE /* When using mmap we want to make sure the file content is really there. Only using ftruncate might mean the file is extended, but space isn't allocated yet. This might cause a @@ -100,6 +101,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) __libelf_seterrno (ELF_E_WRITE_ERROR); return -1; } +#endif /* The file is mmaped. */ if ((class == ELFCLASS32 @@ -129,6 +131,7 @@ write_file (Elf *elf, off_t size, int change_bo, size_t shnum) size = -1; } +#if HAVE_DECL_FCHMOD /* 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. */ @@ -140,6 +143,7 @@ write_file (Elf *elf, off_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; diff --git a/src/ChangeLog b/src/ChangeLog index 4a32604..e0df2e1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,14 @@ 2017-05-04 Ulf Hermann + * ar.c: Don't fchmod or fchown the output file if fchmod or fchown + don't exist. + * elfcompress.c: Likewise. + * ranlib.c: Likewise. + * strip.c: Likewise. + * strings.c: Skip posix_fadvise if it doesn't exist. + +2017-05-04 Ulf Hermann + * strings.c: If roundup() is not defined, define it. 2017-04-28 Ulf Hermann diff --git a/src/ar.c b/src/ar.c index ec32cee..45b219a 100644 --- a/src/ar.c +++ b/src/ar.c @@ -655,6 +655,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, if (oper != oper_print) { +#if HAVE_DECL_FCHMOD /* Fix up the mode. */ if (unlikely (fchmod (xfd, arhdr->ar_mode) != 0)) { @@ -662,6 +663,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, arhdr->ar_name); status = 0; } +#endif if (preserve_dates) { @@ -788,20 +790,25 @@ cannot rename temporary file to %.*s"), != (ssize_t) symtab.symsofflen) || (write_retry (newfd, symtab.symsname, symtab.symsnamelen) - != (ssize_t) symtab.symsnamelen))) + != (ssize_t) symtab.symsnamelen))) || /* Even if the original file had content before the symbol table, we write it in the correct order. */ - || (index_off != SARMAG - && copy_content (elf, newfd, SARMAG, index_off - SARMAG)) - || copy_content (elf, newfd, rest_off, st.st_size - rest_off) + (index_off != SARMAG + && copy_content (elf, newfd, SARMAG, index_off - SARMAG)) || + copy_content (elf, newfd, rest_off, st.st_size - rest_off) || +#if HAVE_DECL_FCHMOD /* Set the mode of the new file to the same values the original file has. */ - || fchmod (newfd, st.st_mode & ALLPERMS) != 0 + fchmod (newfd, st.st_mode & ALLPERMS) != 0 || +#endif + ( +#if HAVE_DECL_FCHOWN /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, + ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, arfname) != 0)) +#endif + close (newfd) != 0) || + (newfd = -1, rename (tmpfname, arfname) != 0)) goto nonew_unlink; } } @@ -1046,13 +1053,19 @@ do_oper_delete (const char *arfname, char **argv, int argc, goto nonew_unlink; } - /* Set the mode of the new file to the same values the original file - has. */ - if (fchmod (newfd, st.st_mode & ALLPERMS) != 0 + if ( +#if HAVE_DECL_FCHMOD + /* Set the mode of the new file to the same values the original file + has. */ + fchmod (newfd, st.st_mode & ALLPERMS) != 0 || +#endif + ( +#if HAVE_DECL_FCHOWN /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, arfname) != 0)) + ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), +#endif + close (newfd) != 0) || + (newfd = -1, rename (tmpfname, arfname) != 0)) goto nonew_unlink; errout: @@ -1503,14 +1516,20 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc, goto nonew_unlink; } - /* Set the mode of the new file to the same values the original file - has. */ if (fd != -1 - && (fchmod (newfd, st.st_mode & ALLPERMS) != 0 + && ( +#if HAVE_DECL_FCHMOD + /* Set the mode of the new file to the same values the original file + has. */ + fchmod (newfd, st.st_mode & ALLPERMS) != 0 || +#endif + ( +#if HAVE_DECL_FCHOWN /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, arfname) != 0))) + ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), +#endif + close (newfd) != 0) || + (newfd = -1, rename (tmpfname, arfname) != 0))) goto nonew_unlink; errout: diff --git a/src/elfcompress.c b/src/elfcompress.c index 8e0d5c5..e092e13 100644 --- a/src/elfcompress.c +++ b/src/elfcompress.c @@ -1235,13 +1235,17 @@ process_file (const char *fname) elf_end (elfnew); elfnew = NULL; +#if HAVE_DECL_FCHMOD /* Try to match mode and owner.group of the original file. */ if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0) if (verbose >= 0) error (0, errno, "Couldn't fchmod %s", fnew); +#endif +#if HAVE_DECL_FCHOWN if (fchown (fdnew, st.st_uid, st.st_gid) != 0) if (verbose >= 0) error (0, errno, "Couldn't fchown %s", fnew); +#endif /* Finally replace the old file with the new file. */ if (foutput == NULL) diff --git a/src/ranlib.c b/src/ranlib.c index cc0ee23..ecaeb55 100644 --- a/src/ranlib.c +++ b/src/ranlib.c @@ -252,19 +252,24 @@ handle_file (const char *fname) != (ssize_t) symtab.symsofflen) || (write_retry (newfd, symtab.symsname, symtab.symsnamelen) - != (ssize_t) symtab.symsnamelen))) + != (ssize_t) symtab.symsnamelen))) || /* Even if the original file had content before the symbol table, we write it in the correct order. */ - || (index_off > SARMAG - && copy_content (arelf, newfd, SARMAG, index_off - SARMAG)) - || copy_content (arelf, newfd, rest_off, st.st_size - rest_off) + (index_off > SARMAG + && copy_content (arelf, newfd, SARMAG, index_off - SARMAG)) || + copy_content (arelf, newfd, rest_off, st.st_size - rest_off) || +#if HAVE_DECL_FCHMOD /* Set the mode of the new file to the same values the original file has. */ - || fchmod (newfd, st.st_mode & ALLPERMS) != 0 + fchmod (newfd, st.st_mode & ALLPERMS) != 0 || +#endif + ( +#if HAVE_DECL_FCHOWN /* Never complain about fchown failing. */ - || (({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), - close (newfd) != 0) - || (newfd = -1, rename (tmpfname, fname) != 0)) + ({asm ("" :: "r" (fchown (newfd, st.st_uid, st.st_gid))); }), +#endif + close (newfd) != 0) || + (newfd = -1, rename (tmpfname, fname) != 0)) goto nonew_unlink; } } diff --git a/src/strings.c b/src/strings.c index 22cbfac..46b2356 100644 --- a/src/strings.c +++ b/src/strings.c @@ -574,9 +574,11 @@ read_block (int fd, const char *fname, off_t fdlen, off_t from, off_t to) elfmap_off = from & ~(ps - 1); elfmap_base = elfmap = map_file (fd, elfmap_off, fdlen, &elfmap_size); +#if HAVE_DECL_POSIX_FADVISE if (unlikely (elfmap == MAP_FAILED)) /* Let the kernel know we are going to read everything in sequence. */ (void) posix_fadvise (fd, 0, 0, POSIX_FADV_SEQUENTIAL); +#endif } if (unlikely (elfmap == MAP_FAILED)) diff --git a/src/strip.c b/src/strip.c index f747441..f592081 100644 --- a/src/strip.c +++ b/src/strip.c @@ -2007,7 +2007,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, /* Create the real output file. First rename, then change the mode. */ if (rename (tmp_debug_fname, debug_fname) != 0 - || fchmod (debug_fd, mode) != 0) +#if HAVE_DECL_FCHMOD + || fchmod (debug_fd, mode) != 0 +#endif + ) { error (0, errno, gettext ("while creating '%s'"), debug_fname); result = 1; diff --git a/tests/ChangeLog b/tests/ChangeLog index a9bc6fa..6dab801 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,8 @@ +2017-05-04 Ulf Hermann + + * elfstrmerge.c: Don't fchmod or fchown the output file if fchmod or + fchown don't exist. + 2017-04-28 Ulf Hermann * run-disasm-x86-64.sh: Disable if the native binary format is not diff --git a/tests/elfstrmerge.c b/tests/elfstrmerge.c index c2c3fb9..17f40c7 100644 --- a/tests/elfstrmerge.c +++ b/tests/elfstrmerge.c @@ -650,11 +650,15 @@ main (int argc, char **argv) elf_end (elfnew); elfnew = NULL; +#if HAVE_DECL_FCHMOD /* Try to match mode and owner.group of the original file. */ if (fchmod (fdnew, st.st_mode & ALLPERMS) != 0) error (0, errno, "Couldn't fchmod %s", fnew); +#endif +#if HAVE_DECL_FCHOWN if (fchown (fdnew, st.st_uid, st.st_gid) != 0) error (0, errno, "Couldn't fchown %s", fnew); +#endif /* Finally replace the old file with the new merged strings file. */ if (replace) -- 2.1.4