From patchwork Mon Jun 22 14:00:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Szabolcs Nagy X-Patchwork-Id: 39724 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B8BDA388A828; Mon, 22 Jun 2020 14:00:56 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60056.outbound.protection.outlook.com [40.107.6.56]) by sourceware.org (Postfix) with ESMTPS id 5C968388A81C for ; Mon, 22 Jun 2020 14:00:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5C968388A81C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Szabolcs.Nagy@arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vwk5exaxCsSSvGEQK8zlzQ0wuF05Wn4pKIztSjDQJyQ=; b=agn5cnhAZnHRwGXjm4YNPCVx/kXsHgDfkej+WaVy13ucrvhSY1iI5bK1uORjPV5q9Qub9OwDC8ECIIy5VGtA+sR7c3MDgTT7bCeW2zXIvdk90CpM49oKP+THMmJnw6R1xp0VogNxrz8ZHjT791WFOehL36C8SpQbgkn+aSdWwKc= Received: from AM5PR0502CA0021.eurprd05.prod.outlook.com (2603:10a6:203:91::31) by VE1PR08MB4752.eurprd08.prod.outlook.com (2603:10a6:802:a4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.23; Mon, 22 Jun 2020 14:00:48 +0000 Received: from AM5EUR03FT031.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:91:cafe::3) by AM5PR0502CA0021.outlook.office365.com (2603:10a6:203:91::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21 via Frontend Transport; Mon, 22 Jun 2020 14:00:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT031.mail.protection.outlook.com (10.152.16.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.22 via Frontend Transport; Mon, 22 Jun 2020 14:00:47 +0000 Received: ("Tessian outbound 8fb20e43acb7:v59"); Mon, 22 Jun 2020 14:00:47 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 87ced9c2c338f8a0 X-CR-MTA-TID: 64aa7808 Received: from df0e8ed4f6a4.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C5E8AC38-CD6E-47D2-93F6-60914F46D628.1; Mon, 22 Jun 2020 14:00:42 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id df0e8ed4f6a4.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 22 Jun 2020 14:00:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TnAqo4GTWskqygj3ItY7tYWAKzMQoQeJrfypdap1iVe8RIJu5sNzD65Acru74Dvh+4PVEgFuf4OcRRxVx17+t7YHULbMdUQMVfx3P4ilmPGXeT1SinxdwB0RbLh3DU8gR6iBwiIy5WKAC5VvssTxNiW6YaYMhru9MttQle+kaS7Cn36Fknuwd4LpT4MkiBtPVmHeh4SJYoCWTx5rc63rmHTJlP+b/+JwdiDk3hSV2uUbG8exr/uZ8z+MeUEXJc/BWwrkbRqW3rEqPLd9pjVzGpdVn6dtTAcvHwrdmVVpVwN6YPoFepDTkUtVg1HCq2nSg/0YOVnqjbIBiL7Eh8hXDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vwk5exaxCsSSvGEQK8zlzQ0wuF05Wn4pKIztSjDQJyQ=; b=cP9+QqPxlPnUrZ4+PqEhGc01BcZbbQT22cahQfLNiC2EM3my7gMWbL93iGobEjgku61ebjDVI0/c1wxf+orHABXR61Lx7hUbLj72sZPEUhnGRvkgLyoOps51jN6kxdQy2sTXLWkndfkA207ZnbMhd6McQ18lsJNfYhj1wD7ezojdUT4rHg/OW5PqMYOjcz8Y7iBtKdw2T8EOvuCsC32rdHrj4GuDmib8z41iKbtOxawaPJHyn7gk55g+ng602XAz43X5BRrLfuNFFuscTQbO7Pxo66sgr5aiZGNakQpCvhnBYK5lWFZNiI5z9qMU2ZVwFWMdSk3ZxKhS0wPIUq9VFg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vwk5exaxCsSSvGEQK8zlzQ0wuF05Wn4pKIztSjDQJyQ=; b=agn5cnhAZnHRwGXjm4YNPCVx/kXsHgDfkej+WaVy13ucrvhSY1iI5bK1uORjPV5q9Qub9OwDC8ECIIy5VGtA+sR7c3MDgTT7bCeW2zXIvdk90CpM49oKP+THMmJnw6R1xp0VogNxrz8ZHjT791WFOehL36C8SpQbgkn+aSdWwKc= Authentication-Results-Original: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=arm.com; Received: from AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) by AM6PR08MB4341.eurprd08.prod.outlook.com (2603:10a6:20b:b9::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.21; Mon, 22 Jun 2020 14:00:40 +0000 Received: from AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c]) by AM6PR08MB3047.eurprd08.prod.outlook.com ([fe80::2404:de9f:78c0:313c%6]) with mapi id 15.20.3109.027; Mon, 22 Jun 2020 14:00:40 +0000 From: Szabolcs Nagy To: libc-alpha@sourceware.org Subject: [PATCH v5 08/14] rtld: Rename _rtld_process_pt_note to _dl_process_pt_note Date: Mon, 22 Jun 2020 15:00:34 +0100 Message-Id: <3be82491fa7d4ee9efd9118c5021e866c7ef3820.1592834304.git.szabolcs.nagy@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0107.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::23) To AM6PR08MB3047.eurprd08.prod.outlook.com (2603:10a6:209:4c::23) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (217.140.106.53) by LO2P265CA0107.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3109.25 via Frontend Transport; Mon, 22 Jun 2020 14:00:40 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [217.140.106.53] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 3ca52194-da9e-4b37-0c4d-08d816b4aa2a X-MS-TrafficTypeDiagnostic: AM6PR08MB4341:|VE1PR08MB4752: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:8882;OLM:8882; X-Forefront-PRVS: 0442E569BC X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: f/ZZjrOmMQi5x2u60PyoKqB1Q9oF/53uQqSOBNsaoJk2/t+65N5kNqhWHU+TrUWWrZtxO+R/Cjw5IZzt5FojoLFB4lD215bG6XZuftKuOMZ8yrET158a3Qwiq0dTNCJyyHjrSVLzVNni73voFLb9Hr+1cAfvv9dh+5JXT7iL/eZI3zbubSfgZFY9l1Pfa4IOaRgax+tyYA93uwX20ik1OyZyUE03kWmCBcYIDJeyeCZNIPLHLQPSjrvvYQWjZRtiF9e33RLS/ZcHZo5KEerhI+VlwkCwi2FjGiIDeMvxLytJr/5lZttxVg9vhvHXG9d2MeQCtAFZ0E4yEnZMmLf9vBEPoKLoJ4r1JQ0cEJ3Srar34Jsc3PSu+0YXz8xyMq8M/mwZIXiQmQQt7wC/QarXLbbClQEj60u0wupYJGd2t/Q= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM6PR08MB3047.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(346002)(39860400002)(136003)(376002)(366004)(396003)(16526019)(186003)(66476007)(66556008)(2906002)(36756003)(6486002)(2616005)(44832011)(956004)(6512007)(316002)(66946007)(6666004)(478600001)(6506007)(69590400007)(52116002)(5660300002)(8936002)(8676002)(26005)(83380400001)(4326008)(86362001)(6916009)(136400200001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YtzuY8UF5isbLqh8mbgmTBewy09xIOOEMY6i5rpdGCOTqZ51wXVKUhapsQ8J5g2Iyvfzbeziu7CJ6GA2Ej7qK2E79lZxN+mwAy40WJHekAzvI1B0h2ZAFSVyhnosYvYPvfadOPNVGABzu0og4Aecg6NpT2OKbL3/XarH6LnqOyO9fbmhWsshbNzCVIBe1sdHIeS1hZMFJaU8msiRltCDoLj1qjv9oVv/nnXMhHZre9zg8MEs3NDhOxrvKE3WhJw/ol0VJ9I3IQP6QMh1955jlnRy8IAQ89gZH2t5C/E3yIhDmNTzhe+FV9947PR5tBkGhCbBZ6ozojCqZ2R63Q6GJRb7YC0YLgXZqy1q02hCvsoKxmPrJERt0jJ3CVXDbeuxviJQ7kyvjaBubBR61r9sjtEvcW4oTw50wfEZ88RMZRDpWwJe3DuYQVVzj7h8EptyQz9tsywyZslzvVbGEVZuNYOtj6MWpEN/VxVyLF2LU0Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4341 Original-Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none; sourceware.org; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT031.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(376002)(396003)(136003)(346002)(39860400002)(46966005)(8936002)(5660300002)(81166007)(478600001)(82310400002)(82740400003)(6666004)(70586007)(70206006)(6916009)(2906002)(83380400001)(8676002)(47076004)(2616005)(6512007)(44832011)(6486002)(36756003)(336012)(69590400007)(956004)(4326008)(356005)(316002)(16526019)(186003)(36906005)(86362001)(107886003)(26005)(6506007)(136400200001); DIR:OUT; SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: 54fce58b-6569-4979-3f7d-08d816b4a5d0 X-Forefront-PRVS: 0442E569BC X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mmIUoulY3/QrGBa64avvrRfjpZcERQ19i6oyoA/kBXd1ScONp8PXRJXBsUMIBbbRgiaQLFEsae/ORPbkIJZ5IL0x5Ra5fvJkGmL4fgfwD3HfucmVt1jj96S6oU3bw6Yw5f28l9W4KaHvRglP5BOqeYGVxsMie/fLhBCRvrh3y1CVL7Qgv/0pzgrosh5PY+OpO2HGuGFk8xT5sXJgUc/AdWHyXL8POsWLdvsCWsOf14pzOmes9nRjPZrwibF2cL/S5dN0h/0aQNNNm8uLWUrYf0Vcewfrp6VuSfDntjubQPbkoyjlj4aCGLxTQRGupou+yC+OVE4BWnREejYTkJ9NifW4II2vBUA7/598sHReUahsBofCVDQn/2hTzKixK8hGIXLs9HShP2oBr6Rs8Yc1rsJFwfFmQvuRk8cpine14BbzNRQ25mW6y46ZRyP1IA64/lhBpO47ap1yxva+FzhTTw== X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2020 14:00:47.7172 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3ca52194-da9e-4b37-0c4d-08d816b4aa2a X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4752 X-Spam-Status: No, score=-16.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: "H.J. Lu" The old _dl_process_pt_note and _rtld_process_pt_note differ in how the program header is read. The old _dl_process_pt_note is called before PT_LOAD segments are mapped and _rtld_process_pt_note is called after PT_LOAD segments are mapped. Since PT_GNU_PROPERTY is processed after PT_LOAD segments are mapped, we can process PT_NOTE together with PT_GNU_PROPERTY. We can remove the old _dl_process_pt_note and rename _rtld_process_pt_note to _dl_process_pt_note. NOTE: We scan program headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY exits. --- elf/dl-load.c | 21 ++++++++----------- elf/rtld.c | 18 +++++++++------- sysdeps/generic/dl-prop.h | 14 ++----------- sysdeps/x86/dl-prop.h | 44 ++------------------------------------- 4 files changed, 23 insertions(+), 74 deletions(-) diff --git a/elf/dl-load.c b/elf/dl-load.c index 66bd0ca0a3..32c74f79ef 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1216,14 +1216,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, l->l_relro_addr = ph->p_vaddr; l->l_relro_size = ph->p_memsz; break; - - case PT_NOTE: - if (_dl_process_pt_note (l, ph, fd, fbp)) - { - errstring = N_("cannot process note segment"); - goto call_lose; - } - break; } if (__glibc_unlikely (nloadcmds == 0)) @@ -1261,12 +1253,17 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, goto call_lose; /* Process program headers again after load segments are mapped in - case processing requires accessing those segments. */ - for (ph = phdr; ph < &phdr[l->l_phnum]; ++ph) - switch (ph->p_type) + case processing requires accessing those segments. Scan program + headers backward so that PT_NOTE can be skipped if PT_GNU_PROPERTY + exits. */ + for (ph = &phdr[l->l_phnum]; ph != phdr; --ph) + switch (ph[-1].p_type) { + case PT_NOTE: + _dl_process_pt_note (l, &ph[-1]); + break; case PT_GNU_PROPERTY: - _dl_process_pt_gnu_property (l, ph); + _dl_process_pt_gnu_property (l, &ph[-1]); break; } } diff --git a/elf/rtld.c b/elf/rtld.c index 3ad2bf5079..f4c2602d65 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1507,15 +1507,17 @@ of this helper program; chances are you did not intend to run this program.\n\ main_map->l_relro_addr = ph->p_vaddr; main_map->l_relro_size = ph->p_memsz; break; - - case PT_GNU_PROPERTY: - _dl_process_pt_gnu_property (main_map, ph); - break; - + } + /* Process program headers again, but scan them backwards so + that PT_NOTE can be skipped if PT_GNU_PROPERTY exits. */ + for (ph = &phdr[phnum]; ph != phdr; --ph) + switch (ph[-1].p_type) + { case PT_NOTE: - if (_rtld_process_pt_note (main_map, ph)) - _dl_error_printf ("\ -ERROR: '%s': cannot process note segment.\n", _dl_argv[0]); + _dl_process_pt_note (main_map, &ph[-1]); + break; + case PT_GNU_PROPERTY: + _dl_process_pt_gnu_property (main_map, &ph[-1]); break; } diff --git a/sysdeps/generic/dl-prop.h b/sysdeps/generic/dl-prop.h index ceb6f623ee..f1cf576fe3 100644 --- a/sysdeps/generic/dl-prop.h +++ b/sysdeps/generic/dl-prop.h @@ -36,19 +36,9 @@ _dl_open_check (struct link_map *m) { } -#ifdef FILEBUF_SIZE -static inline int __attribute__ ((always_inline)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph, - int fd, struct filebuf *fbp) -{ - return 0; -} -#endif - -static inline int __attribute__ ((always_inline)) -_rtld_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +static inline void __attribute__ ((always_inline)) +_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) { - return 0; } /* Called for each property in the NT_GNU_PROPERTY_TYPE_0 note of L, diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h index 4a8ebc573e..89911e19e2 100644 --- a/sysdeps/x86/dl-prop.h +++ b/sysdeps/x86/dl-prop.h @@ -19,8 +19,6 @@ #ifndef _DL_PROP_H #define _DL_PROP_H -#include - extern void _dl_cet_check (struct link_map *, const char *) attribute_hidden; extern void _dl_cet_open_check (struct link_map *) @@ -146,49 +144,11 @@ _dl_process_cet_property_note (struct link_map *l, #endif } -#ifdef FILEBUF_SIZE -static inline int __attribute__ ((unused)) -_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph, - int fd, struct filebuf *fbp) -{ -# if CET_ENABLED - const ElfW(Nhdr) *note; - ElfW(Nhdr) *note_malloced = NULL; - ElfW(Addr) size = ph->p_filesz; - - if (ph->p_offset + size <= (size_t) fbp->len) - note = (const void *) (fbp->buf + ph->p_offset); - else - { - if (size < __MAX_ALLOCA_CUTOFF) - note = alloca (size); - else - { - note_malloced = malloc (size); - note = note_malloced; - } - if (__pread64_nocancel (fd, (void *) note, size, ph->p_offset) != size) - { - if (note_malloced) - free (note_malloced); - return -1; - } - } - - _dl_process_cet_property_note (l, note, size, ph->p_align); - if (note_malloced) - free (note_malloced); -# endif - return 0; -} -#endif - -static inline int __attribute__ ((unused)) -_rtld_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) +static inline void __attribute__ ((unused)) +_dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph) { const ElfW(Nhdr) *note = (const void *) (ph->p_vaddr + l->l_addr); _dl_process_cet_property_note (l, note, ph->p_memsz, ph->p_align); - return 0; } static inline int __attribute__ ((always_inline))