From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by sourceware.org (Postfix) with ESMTPS id 5FAC63856DD5 for ; Fri, 6 May 2022 06:54:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5FAC63856DD5 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2173.outbound.protection.outlook.com [104.47.17.173]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-39-LHTMqIsiOOOkmouZGMBB2g-1; Fri, 06 May 2022 08:54:04 +0200 X-MC-Unique: LHTMqIsiOOOkmouZGMBB2g-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YCbC4NUNBFxDVCIJwhLQtZB5qcMOGc4HOclSGrUfYtezkdnYVjwokS4Gx+q00EumP7mH656rWfFbY2MqHGD0DI526E7eVdYre9aSgz4LXgKNIDSyGSAewl9iA5A3hcdOMKvQWfa4BbAszYB3XwLes2mFPzfwQBKzdhJkBx+ad9ZYitwr27KaB2bJlbI3/nzhMAkIP4r5hP5090KjwnPikYVNJcgs3KUs0LYuQlZNyePVDbHajpIQ7ApSVCTODXJLQvgNnqWZA9dWb2kEBMJTn2goIhxhzf0aKBrWrrIr5C8MudJsrOp+PhIQlHij3pob9kDY7Bd9jCi5qLJUZrJ9CQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0yeFmBVFRAf31CQO0ESor8jREaAcp3/RM7f8qzKLkHM=; b=TKEemsyfLDu+RRQAtCTq6p0wOtsBSynD33IwCs9hiPimj+WM9sXhffYuaWyXPjWoBLKmfBo93eeD8lcparF6fjrMPpFZOeAmCRKiXigb5a9edA/VVQ+4X1lKrliiubQKkG5PUL1AwzuUy9H/NXdGmy8o3psJtceYsaBEJR80i0pvUHC18PNvz19EdLfvLzdHKvzKHYT4BK5UbXTsybhXt28Ei9JlLJIxnlb9GoHK3Rddg1h65OUAETfU5IIhvBxmo6h7oTBC2NlqN4sBjo8IZQPeI6l6vDY2zTdwHVAePwCbr6qOzxqldg8s8yXBk06tHkjD6Hwh7CXIPwAFzrZBaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) by DB7PR04MB4426.eurprd04.prod.outlook.com (2603:10a6:5:34::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.27; Fri, 6 May 2022 06:54:03 +0000 Received: from DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::84b:e9d3:8906:8b9c]) by DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::84b:e9d3:8906:8b9c%6]) with mapi id 15.20.5227.018; Fri, 6 May 2022 06:54:03 +0000 Message-ID: Date: Fri, 6 May 2022 08:54:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: [PATCH 1/5] don't over-align file positions of PE executable sections Content-Language: en-US To: Binutils Cc: Dave Korn References: <4242b48a-f2c3-4af2-db1e-35dbbbdc1b2e@suse.com> From: Jan Beulich In-Reply-To: <4242b48a-f2c3-4af2-db1e-35dbbbdc1b2e@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM6P192CA0074.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::15) To DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 862c22be-8c57-4312-2b4d-08da2f2d34c5 X-MS-TrafficTypeDiagnostic: DB7PR04MB4426:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2CmDVSzco8MoahDwu2IqTuSvywVa0qw/CoaWpKZKWIu5UIbTm4YsCpFrvHg8AqTJ5F3k2hf+o/1RveSLhrlum4syXrK+sDt57vR2ecx1asngRHsTpejZeyfhKJRzU4p6cWWnxHMwcieMnO7R4Dyw4hDCwhS7BzWpp4pvv0HzHJkIyq2YPeydi6WSmJfDcONQuFgiPbfIg+qhddr4AlQ9RXHxWrc3dqaok1JzImitN8W1Vd5BAVVmTsCcyynpCWxZ1APug7V9hDBM0nsPnwwLJD/7maRhgiVYqwgRP8yIADeAQ0ZXJOXiOoYT1Jw8Ja/2Ddn3tPxpCVJ+MsngUtn9rlz/yPzaXdOJeGk5AZaUQmzswU+MniXfOggbkA1HLrya4rU1FgXTkYAm4kt6rtSLQSgqxpgcYPzb703Du5Ldh22uFSMsIZqexVy+8Ks+j4FqzAwA6sky0mEPEDxybzqXhMxrigULMPZZa9uXmGFozkMZ0UemufE9pC2RiRtvOdtilG4LqUah76qXL8kHNt5CTntsP4JiLOOSjel/yfQsGgOeCeanqPqLP4idubTF5Va9Fk/tlvVb2sOPzmvfPcpg6CWm5aXoXrjAlPOcFsI4Pq+iWeVYdb+cmcE+5e/HIasC7EOnw7/BJlObmP9FXbMWUasFCdNPQx4Mj4t9Skznw/Uzm9jzSQ9f9f2LgpsiRMn1eHmWZdbKgQ4LOno/mSSBEJRL0mbgaGMn88lD61yD5i/E1B+X234K+zxDVljCMVb6 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8616.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(6506007)(2616005)(6916009)(31686004)(8936002)(6512007)(26005)(5660300002)(508600001)(2906002)(6486002)(36756003)(86362001)(66946007)(66556008)(186003)(31696002)(8676002)(66476007)(316002)(83380400001)(38100700002)(4326008)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?K29Ja1F3R1plVTlrN1BRRndvZ0pFVDQ4cVZTMGlJdmtybDZ1WSsrWndkQUtO?= =?utf-8?B?N3ZRdHNybmxLYm5tbi8yMW1scDBkVzkyQWpmdmNzVE4zcFA3bFJaTVRrVk9h?= =?utf-8?B?OWo2NmlOREZRWWZYeFQrNDZLM09jVUxjU3ZPbzYybmZsTm5XaDRMYTFHQ3hL?= =?utf-8?B?SnduZzNXSWxFT2gyOVNxaVFteWFxTHV3YngraXVNTjl2Nzh6ejdqWFlQTGF3?= =?utf-8?B?RmZ4akZlenM0bitZUzZhZjluQy9KaXkrVkxTei9KQWJnM3pkMkhrZDFmbncr?= =?utf-8?B?Y3BxWlA3YmlhNmd5UHVDbzBERnF5WU1MTmNBYm51NFZVM2dSK1cwOHVESlRM?= =?utf-8?B?Uis0YndpVXhzdksvcmpHTmV6c1NBcXpyTFNOaWhnbW95cjZzbkhLUUlJbkFr?= =?utf-8?B?YW5QanVwOTY4M1VSVnpTNFdBOVpiMDR0bnIvd3BkQUMzRWhPOCsrNmxzNmVu?= =?utf-8?B?QkdSVkc4SHlKa1YxQkYwUW9tZm5OR1ZSUnF2ZEREc2JuYmt2SjB3Vkx0Qzgz?= =?utf-8?B?ZmR3bVBFRFFTamlwNFF2ZVFHcVh1c1EyMzlPcFFiRDZCR0QyQzVyQ2hMTnFZ?= =?utf-8?B?T1ZZdmphb09LOHpPbjlQYmhXWVk1R01zTTF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XhmdDdnNE1TTGY1WUdKWUlvWjNLc3c3M2huOVpNNmx5?= =?utf-8?B?dEtmWlRNby9ib20vYkRwTU5OUi92SEc0L0V5Mi8zZFVoZ2w4b3BTQUd1dmZJ?= =?utf-8?B?YkYxNWJLTXRZWDRHeDdOaXd6VjdORUJFWk1sQlVOaGRvV3dnc2RRMm16MGl1?= =?utf-8?B?NmFaTE0zc0FiZGliSDBReFJDalpROTR2TWo1WWVnajVzMnZrbGxRWWZ4MFBu?= =?utf-8?B?RkhoWnZiS3hRZzd3VGRoRVlrdUZzVzdaVS9ueW5qMGNMRFFQTGRVUmF4eDVl?= =?utf-8?B?U2o2S2VhK1FZcjM0ZkJONlZsdXVUL2lORHlhU0h1aUpUVnVpS015QkhsNmYz?= =?utf-8?B?MkpPbmZTdFJpMTByYzBhcXRodjF5d3BzMmZCNGNZNkQ2U0VDTXdCdklJemRa?= =?utf-8?B?MFNPd3RINU5vSFZRbE1RcXlrQjZiSTJpUEFNQnZmdzJoei80R3pWZ2piWGpq?= =?utf-8?B?WXVUY004N3pKY0liUHUxMUJqRlN6LzdzWXhsQmtlYUZtbm1lV3VzeThMQnlr?= =?utf-8?B?a1B3UXQxWEtrclRtdGV3aGJvOU9QUEhUTkJYcVpIUGJLZUtsME81ZFEwT3JX?= =?utf-8?B?UFpwOUVaQ3NWc1N6YW82dkZBTHoxQUwwWkdobzFTWlZCUld3Q1M3TENEN29E?= =?utf-8?B?UE9pN2loZVA0QXR5V3hCcXpDeG1tOW9BczNpOUhCLy9ZMEtMcWI1MTB2N2w2?= =?utf-8?B?djNYVHNQRGhTSWVNZlM1QkFuQThzSzhmWXZCWHJvdXFqcDlxQ2lNbm5SRDZF?= =?utf-8?B?VCt3a3U0Zjd0K3VnQjRtTEg5ODF3SnBpU21kMlNUM29uQVJJNWlDdz09?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 862c22be-8c57-4312-2b4d-08da2f2d34c5 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8616.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2022 06:54:03.3123 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DyhYamfi89f7NMaAjpEEyPd6L2uOtA0co3GX3qSJwdCaobySt+gng1BiWFyn1nYhvPoXqt1HMcAR92drSDJY/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR04MB4426 X-Spam-Status: No, score=-3031.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2022 06:54:08 -0000 When a sufficiently small alignment was specified via --file-alignment, individual section alignment shouldn't affect placement within the file. This involves first of all clearing D_PAGED for images when section and file alignment together don't permit paging of the image. The involved comparison against COFF_PAGE_SIZE in turn helped point out (through a compiler warning) that 'page_size' should be of unsigned type (as in particular FileAlignment is). This yet in turn pointed out a dubious error condition (which is being deleted). For the D_PAGED case I think the enforced file alignment may still be too high, but I'm wary of changing that logic without knowing of possible corner cases. Furthermore file positions in PE should be independent of the alignment recorded in section headers anyway. Otherwise there are e.g. anomalies following commit 6f8f6017a0c4 ("PR27567, Linking PE files adds alignment section flags to executables") in that linking would use information a subsequent processing step (e.g. stripping) wouldn't have available anymore, and hence a binary could change in that 2nd step for no actual reason. (Similarly stripping a binary linked with a linker pre-dating that commit would change the binary again when stripping it a 2nd time.) --- The new condition for clearing D_PAGED may be a little too strict now; the alternative would be to check all section RVAs and file positions to match modulo COFF_PAGE_SIZE. One could think that it should be the other way around (file positions _only_ be assigned to satisfy that condition), but then there would be no way to request sections to be arranged in this more space saving manner. (Note that if that condition was adjusted, other changes made later in the function then would also need further refinement.) Quite likely the referenced commit should be follow by another change suppressing also the reading of the section alignment bits when processing a PE binary. This would similarly eliminate the oddity of stripping a previously stripped binary altering that binary again. --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -2962,7 +2962,7 @@ coff_compute_section_file_positions (bfd #endif #ifdef COFF_IMAGE_WITH_PE - int page_size; + unsigned int page_size; if (coff_data (abfd)->link_info || (pe_data (abfd) && pe_data (abfd)->pe_opthdr.FileAlignment)) @@ -2973,22 +2973,12 @@ coff_compute_section_file_positions (bfd This repairs 'ld -r' for arm-wince-pe target. */ if (page_size == 0) page_size = 1; - - /* PR 17512: file: 0ac816d3. */ - if (page_size < 0) - { - bfd_set_error (bfd_error_file_too_big); - _bfd_error_handler - /* xgettext:c-format */ - (_("%pB: page size is too large (0x%x)"), abfd, page_size); - return false; - } } else page_size = PE_DEF_FILE_ALIGNMENT; #else #ifdef COFF_PAGE_SIZE - int page_size = COFF_PAGE_SIZE; + unsigned int page_size = COFF_PAGE_SIZE; #endif #endif @@ -3070,9 +3060,10 @@ coff_compute_section_file_positions (bfd bfd_size_type amt; #ifdef COFF_PAGE_SIZE - /* Clear D_PAGED if section alignment is smaller than - COFF_PAGE_SIZE. */ - if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE) + /* Clear D_PAGED if section / file alignment aren't suitable for + paging at COFF_PAGE_SIZE granularity. */ + if (pe_data (abfd)->pe_opthdr.SectionAlignment < COFF_PAGE_SIZE + || page_size < COFF_PAGE_SIZE) abfd->flags &= ~D_PAGED; #endif @@ -3193,7 +3184,11 @@ coff_compute_section_file_positions (bfd padding the previous section up if necessary. */ old_sofar = sofar; +#ifdef COFF_IMAGE_WITH_PE + sofar = BFD_ALIGN (sofar, page_size); +#else sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); +#endif #ifdef RS6000COFF_C /* Make sure the file offset and the vma of .text/.data are at the @@ -3269,7 +3264,11 @@ coff_compute_section_file_positions (bfd else { old_sofar = sofar; +#ifdef COFF_IMAGE_WITH_PE + sofar = BFD_ALIGN (sofar, page_size); +#else sofar = BFD_ALIGN (sofar, 1 << current->alignment_power); +#endif align_adjust = sofar != old_sofar; current->size += sofar - old_sofar; }