From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14812 invoked by alias); 4 Mar 2020 00:03:48 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 14803 invoked by uid 89); 4 Mar 2020 00:03:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL,BAYES_00,KAM_INFOUSMEBIZ,MSGID_FROM_MTA_HEADER,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no version=3.3.1 spammy=Except, H*F:D*me, wins, H*r:209.85.160 X-HELO: NAM10-DM6-obe.outbound.protection.outlook.com Received: from mail-dm6nam10olkn2058.outbound.protection.outlook.com (HELO NAM10-DM6-obe.outbound.protection.outlook.com) (40.92.41.58) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Mar 2020 00:03:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j8tnVV9zFEH7GR4t5gYsO1pgw+4nC8ae5I7lM4Jtf+ZHr4ovYhSnTXhYj+k5F/h06Pw6XgC8wf4B8/QeF33nc2F6nualQPPYUZuUFWjFvCa3F7fHV7SB1bwb/8Xyj1Cg06cKHN9BJKjvFrxucpvzFyC8TBKsUJmjzaNbnWSRio21R2OWHG04XhsFMSKf3trAylFb5ZbfhNOXpevQSWv8G1iCxyl5Po9svoG22vebKhcqrfT8HWmOCrA7GW+gW3Xre+ugYqjHeBHeFknucrpwR5hgplsGebldbl1Br6NhGOa/d8kCkqe4dtOkifYSx2DbKGtEr8WuaAv5syH6FLZGcg== 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=853bjcQkzPK+aiUdSUh08KLYw9d1LKCH+D6VmajJW9c=; b=VcjjgMKz27sRlAhScg8XHMxgy9emXjQ3ghyJxPFBR4GttWh2iviEmDnsgd7/W5KmbAQ2pPP+a2D//Hztvk4z+fr5hs+9SCT7G4qv4AVatHii3MObtDMSW816cQFTojLteFHKvrh2JlDDgQUpZmNLKXyGfO3jvS5ixRTyxLTXZ4BVdxOQCYiRCIDCXFfognwuPtasGH2k5D6cyO6D+gzHaAxQ2XZjk9LqZvwHkbbLq+qkv+0ZZgGRk6EsA0EWMD2CPEfim1tWLwqW7CenD8roD4qcqEXnnukd4mWh/frRfiQfJF2kJzAClIs80tD8sA3TlPA8BU+L+pIffd0sF0OT2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=maskray.me; dmarc=pass action=none header.from=maskray.me; dkim=pass header.d=maskray.me; arc=none Received: from DM6NAM10FT062.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::3a) by DM6NAM10HT208.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e86::163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15; Wed, 4 Mar 2020 00:03:42 +0000 Received: from BY5PR07MB7316.namprd07.prod.outlook.com (2a01:111:e400:7e86::38) by DM6NAM10FT062.mail.protection.outlook.com (2a01:111:e400:7e86::444) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.14 via Frontend Transport; Wed, 4 Mar 2020 00:03:42 +0000 Received: from BY5PR07MB7316.namprd07.prod.outlook.com ([fe80::9dce:8d96:403c:b724]) by BY5PR07MB7316.namprd07.prod.outlook.com ([fe80::9dce:8d96:403c:b724%6]) with mapi id 15.20.2772.019; Wed, 4 Mar 2020 00:03:42 +0000 References: <20200226052300.wazzfmivxta63vef@gmail.com> <20200226063003.4uvshiarho3wbkrl@google.com> <20200303223901.GO5384@bubble.grove.modra.org> In-Reply-To: <20200303223901.GO5384@bubble.grove.modra.org> From: Fangrui Song Date: Wed, 04 Mar 2020 00:03:00 -0000 Message-ID: Subject: Re: [ld] section address : ALIGN(align) and the maximum of input section alignments To: Alan Modra Cc: binutils Content-Type: text/plain; charset="UTF-8" Return-Path: i@maskray.me X-Microsoft-Original-Message-ID: MIME-Version: 1.0 Received: from mail-qt1-f177.google.com (209.85.160.177) by MN2PR20CA0015.namprd20.prod.outlook.com (2603:10b6:208:e8::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15 via Frontend Transport; Wed, 4 Mar 2020 00:03:42 +0000 Received: by mail-qt1-f177.google.com with SMTP id 59so89951qtb.1 for ; Tue, 03 Mar 2020 16:03:42 -0800 (PST) X-Microsoft-Original-Message-ID: X-MS-Exchange-AntiSpam-MessageData: bejj1w6q6dXW53umPuIBZqbQrLqM5if+otJBY04Id0zN3qru9inePfdK2T4QehpNTn4V79qMUx7hzB65MksKIgoZ2hJv1V4oDrEab8FHvxTw0wdUWB650y0UFjjqeqTHmcv4VcnpDIZ6Vge0KZ8kNw== X-SW-Source: 2020-03/txt/msg00057.txt On Tue, Mar 3, 2020 at 2:39 PM Alan Modra wrote: > > On Tue, Feb 25, 2020 at 10:30:03PM -0800, Fangrui Song wrote: > > > Why doesn't `.bss . : ALIGN(16)` respect the maximum of input section alignments (32)? > > > > > > (I have verified that .bss being SHT_NOBITS is unrelated.) > > > > > > The rule of sh_addr computation appears to be: > > > > > > * ADDR is unset, ALIGN is unset => max_input_alignment > > > * ADDR is unset, ALIGN is set => max(ALIGN, max_input_alignment) > > > * ADDR is set, ALIGN is unset => max_input_alignment > > > * ADDR is set, ALIGN is set => ALIGN > > > > When ADDR is set, ALIGN is used while max_input_alignment is ignored. > > > > ld/ldlang.c:5582 > > > > if (os->addr_tree == NULL) { > > ... > > newdot = os->region->current; > > // maximum of ALIGN and input section alignments > > section_alignment = os->bfd_section->alignment_power; > > } > > else > > // ALIGN > > section_alignment = exp_get_power (os->section_alignment, "section alignment"); > > > > Alan, is the `else` branch supposed to use `section_alignment = os->bfd_section->alignment_power;` as well? > > No. When you specify the address of an output section that is the > address it should have. Except that specifying both an address and > alignment aligns the address given. Specifying both is somewhat > contradictory and it would probably have been better if we didn't > support ALIGN here. Thanks. For the example below, do you agree with the comments in a.x below? % cat a.s .globl _start; _start: ret .section .data.rel.ro,"aw"; .balign 8; .byte 0 .data; .byte 0 .section .data2,"aw"; .balign 8; .byte 0 .section .data3,"aw"; .balign 32; .byte 0 .bss; .balign 32; .byte 0 % as a.s -o a.o % cat a.x SECTIONS { .text 0x10000 : { *(.text) } /* sh_addr is 0x10010. Specifying both address and ALIGN should be disallowed. */ .data.rel.ro . : ALIGN(16) { *(.data.rel.ro) } .data 0x20000 : { *(.data) } /* sh_addr is 0x20001. Should there be a warning that sh_addralign is 8? Even --warn-section-align does not warn. */ .data2 . : { *(.data2) } /* sh_addr is 0x20020. The input section alignment wins. */ .data3 : ALIGN(16) { *(.data3) } /* sh_addr is 0x20030. Specifying both address and ALIGN should be disallowed. */ .bss . : ALIGN(16) { *(.bss) } } % ld.bfd -T a.x a.s -o a If specifying both Output Section Address and ALIGN is disallowed, there should be no "changing start of section" warning when --warn-section-align is not specified. Is my understanding correct? BTW, I filed a bug about duplicate "changing start of section" warnings https://sourceware.org/bugzilla/show_bug.cgi?id=25570