From patchwork Tue Feb 27 08:15:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: vb-sc X-Patchwork-Id: 207085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2558211dyb; Tue, 27 Feb 2024 00:16:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWZ1VuDYPGTTQbXXYLOk7f2CMHW7gf//tElnKKl3RQ0TpizvVRGwNnrXD1s7rmyMKHARXFprv3FreDSx2tQ2hn3jp0y2w== X-Google-Smtp-Source: AGHT+IGC9JN1GGgfi1eY8JIXAtN5ZUjDtxquMtzTp7zmoir9jr+9HNCdqMvgAS0jLk/36EZnnbHK X-Received: by 2002:a05:6214:2b8f:b0:68f:fe88:cc4c with SMTP id kr15-20020a0562142b8f00b0068ffe88cc4cmr1777761qvb.41.1709021774334; Tue, 27 Feb 2024 00:16:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709021774; cv=pass; d=google.com; s=arc-20160816; b=AHCgZvzn3ZE19S+s7HIDtnPajngSMqi9F69e2EF91y9vt8ojGaVBVPM7XH9n5IVY6U O0Gs/bJ2bLpes2e30aAl4qkdBWL/WuRkkschxb6Ws6eVwyugrQCi5LSUX3Kn/ytJMYbf fXPhuwjcOkAQLGz38TixoZSfTphhfgdwF62/dDI8abB/amEWmTORiz8/r808UtpLPZd9 J+c9titxkNA7RY1f7EI2sqn15MlmZ0JpsBM8FkP79NMoICOy08wlLwhDEK8YsWHm4srg iR7MaAgcB4D8F4q4/8w5hw43Tgl8LmMYkAShUQjj4UDh15io4E5kKlpEyV9r4nCP++tc 0wKA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-signature:dkim-filter:arc-filter:dmarc-filter:delivered-to; bh=/cIY+xNDRGsotT8MDIkxPe1t9t/1lgkXe7QGOXGNW94=; fh=/e1N0zK08T6UbHtGyznPymdOsGRxZ/PKNxwzrHeKtN0=; b=rtUqFAzKoBVgfPmbSm8ptlAzhCcjzSYxAxfuTQthDUr0EY9Kj7B5i66g8o+ckrSoSG B2qeT2tg/YR+WNvLrySazMx55sIn5rJydtSg+d+ItKSpOTiNRbTFJnzLf4FmoxlXGV37 T7+Vw3TzKWPvn1/Yly5bH2D032TMVQcqSskIUcVxVSaVJ/NURBnts2C3OVh859+0XllT rD9aya5qWEyXtJKTCeu+u/WsOlyaTQCzLEZ3kH+mxkJyHtMOSsaSrSPdGBZHsfuTzXUv /XxzkDQBqoCdN46EcB6ApOPy9O2ss7O8Zd/yGHal2i+ieNL1Js1BZ9oaaEBefsKdCMth kItw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@syntacore.com header.s=mta-04 header.b=xLzHXPoc; dkim=pass header.i=@syntacore.com header.s=mta-03 header.b=KbECnCo4; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=syntacore.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fo14-20020ad45f0e000000b0068fb7a5e858si6854373qvb.90.2024.02.27.00.16.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 00:16:14 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@syntacore.com header.s=mta-04 header.b=xLzHXPoc; dkim=pass header.i=@syntacore.com header.s=mta-03 header.b=KbECnCo4; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=syntacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01AA83858415 for ; Tue, 27 Feb 2024 08:16:14 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mta-04.yadro.com (mta-04.yadro.com [89.207.88.248]) by sourceware.org (Postfix) with ESMTPS id 858833858D38 for ; Tue, 27 Feb 2024 08:15:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 858833858D38 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=syntacore.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=syntacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 858833858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.207.88.248 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709021763; cv=none; b=RUYiQ/CPVstwdoJ+/Wk0uvvrWhViZ+3HN8P3rpfkPpDcpefNBrc863z27FCOzmxWOcs33goCHGrLnKiJc1pjh8Llf74JXD5aj2xqFzxQdStM0+PS5WvDPyySE6IdX9yh/ico71VOM91vYhSHNnzEHpISL8S/qmhPmMXySuxClW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709021763; c=relaxed/simple; bh=1MzaMsKd5L3dMiDgM9iyWz5l2JvPqQze7wCw9Iim05Q=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=cBtVvfTcuO2X7tYDhjaC0CnHi4RyjyLI4A3PfjaKlxuSbmqt4jo2J7GA5Rg/ZnXrmbYioFWUHnmvrkJ+tZpuNnBrmLdZyYD5+u34Y8h2eb/SsbUqSqzeY7eKZUZfJds7I1K7G8aOyH4uJoOxa0Y18eeHjIx1q0hY+kVfpEVZe1s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 mta-04.yadro.com 2E013C0002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-04; t=1709021756; bh=/cIY+xNDRGsotT8MDIkxPe1t9t/1lgkXe7QGOXGNW94=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=xLzHXPoc+8GBH9QFwdo7gWSCaOU66XvVM/EpcRZjmflHBK6h6N3sMeavv80u6Rxy9 5Zwt0+2c9m19nz5azIgmRgyNprzb42DTg61Ek+3Ye2b3Lgev0af/OJQWh6X0FQtpW9 wrdadabMI5EuTgJUbHGZfds3oQu7c8ZMjD+sVGZEuMvgpu46CRlS4zMCOdws+6+PIv Q0E3buHR2ywwW+f1+3xHx3+d3EAsl0Xt8pqmtfVqnM8VoK4jSWJwumqhnEjrjXEy5R qfILGMfHN4P4y6NVRJU1F5FYaGxabXpLAuQjpH6spQ4Gy5tm5L7KuPDq6wX3/j4EYn htLT4QQUPuBOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-03; t=1709021756; bh=/cIY+xNDRGsotT8MDIkxPe1t9t/1lgkXe7QGOXGNW94=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=KbECnCo4U5nVqj/Z1mc8Ve6oEgT0PbacHtRTtGCgRnpUgrUKx+YSKjGdw1kfRxk5E GWJO+YyflWXxmi3AT9IiGuw1iy49b3ww8upHLnrNqcrQv5+HDxZuvvWVNOJPPwmzNd 3h7MM3gCgs11pT9FHM1UBbTgXQuYKta1/IAaVFjYW8yKEJjvS5FDaog43+KBGQkb2p x3IFnmbb2LnKsJCKMKYpHyIjDvkaohItdjCZ9o4sIcwyMPCV+d9Ist8HAQp2KUOasc AIy8yb6/I+Z4yMLwklgiJgvG0fh4LquK65tnclIXWWKVsV0OEsHy0psCtV0AQctcrG mfcgQyBVv3cqg== From: vb-sc To: CC: vb-sc Subject: [PATCH] changed ld subalign priority Date: Tue, 27 Feb 2024 11:15:47 +0300 Message-ID: <20240227081547.8260-1-vladislav.belov@syntacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-ClientProxiedBy: T-Exch-05.corp.yadro.com (172.17.10.109) To S-Exch-01.corp.yadro.com (10.78.5.241) X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, TXREP, T_SCC_BODY_TEXT_LINE, T_SPF_PERMERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792039215831612399 X-GMAIL-MSGID: 1792039215831612399 Hi, According to the GNU LD documentation: <> However, let's consider the behaviour of GNU ld Suppose we have the following test: $ cat one.c char a_one __attribute__((__aligned__(8))) __attribute__((section(".mysection"))) = 0; and the following linker script: $ cat foo.lds SECTIONS {     . = 0x10024;     .mysection : SUBALIGN(4) {         *(.mysection)     }        .note.gnu.property ALIGN(8) : {       *(.note.gnu.property)       *(.comment)     } } We suppose that the section .mysection would be aligned by 4 despite of alignment attribute 8 in source code. However, after linking object file "one.o" __ with gnu ld linker the symbol .mysection is aligned by 8 $ gcc -c one.c $ ld -T foo.lds one.o -o foo.out $ objdump -h foo.out foo2.out: file format elf64-x86-64Sections: Idx Name Size VMA LMA File off Algn 0 .mysection 00000001 0000000000010028 0000000000010028 00001028 2**3 CONTENTS, ALLOC, LOAD, DATA 1 .note.gnu.property 0000004b 0000000000010030 0000000000010030 00001030 2**3 CONTENTS, ALLOC, LOAD, READONLY, DATA It seems like this is contrary to documented behavior. Below you can see the patch fixed this problem. --- Best regards, Vladislav --- ld/ldlang.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ld/ldlang.c b/ld/ldlang.c index df4c43ce9f4..0ab59daccb4 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -5349,17 +5349,22 @@ size_input_section bfd_size_type alignment_needed; /* Align this section first to the input sections requirement, - then to the output section's requirement. If this alignment - is greater than any seen before, then record it too. Perform - the alignment by inserting a magic 'padding' statement. */ - - if (output_section_statement->subsection_alignment != NULL) - i->alignment_power - = exp_get_power (output_section_statement->subsection_alignment, - "subsection alignment"); + then to the output section's requirement. If this alignment + is greater than any seen before, then record it too. Perform + the alignment by inserting a magic 'padding' statement. + We can force input section alignment within an output section + by using SUBALIGN. The value specified overrides any alignment + given by input sections, whether larger or smaller. */ + + if (output_section_statement->subsection_alignment != NULL) { + i->alignment_power = + exp_get_power(output_section_statement->subsection_alignment, + "subsection alignment"); + o->alignment_power = i->alignment_power; + } - if (o->alignment_power < i->alignment_power) - o->alignment_power = i->alignment_power; + else if (o->alignment_power < i->alignment_power) + o->alignment_power = i->alignment_power; alignment_needed = align_power (dot, i->alignment_power) - dot;