From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by sourceware.org (Postfix) with ESMTPS id 951A238582B9 for ; Mon, 29 Jan 2024 16:23:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 951A238582B9 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 951A238582B9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706545440; cv=none; b=MeJk8JMq4YD5hwB9S8E1JNBTxCTDxLJbjRac5opS4KzngukNS0KRU0aoPyJoPnpRdtc4t8YMPvCXxQPXkV/zoVWvtahgMk/HFx7BtpufDbrA5AKSUZ2KRUVRPfQXjyjc+OzFB4L7hVR83RbsULiChhZMgIHB/q0Qk6/9Uce2nMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706545440; c=relaxed/simple; bh=ZpQLsb+SxZTaehHUClf3QhaN/ShMVNnvD3Kj5WINlq8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=GueaZNior+ER2WIpFEN00oVtNNoJIhL+32GXEneWUULRWNWuhq1AmYdVcA52pOOM0amkzVQa9sLCYMJmCMLrGEQYhF7XM8wZOeRrF/0lXn+h4s4105BBnUAGrucfRpnB11DKEpCZFnjVvqseDs/0MhSQpzrehsIk8cLLgdsWwXY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb2a.google.com with SMTP id 3f1490d57ef6-dc608c3718dso2409498276.1 for ; Mon, 29 Jan 2024 08:23:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706545437; x=1707150237; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Z3apTABZ+v0skZLpMZFSysqfsl0Aa7SJxdPj5lLmE2k=; b=NEez9vju8EGbX/VF46OaynUq158iehfjxD4PsGy1MMfQ5GeF8w/2jKqKLRqN/pK8ZA zERVM8dW0WJ2qi66K5dMWyKQpi5kNdYFvD0w+MTohZyMTQn+Rizf7CQpb8K7Iah/8JaM LBrnFkbZvMdIJEKhJXMmcsA0HZZtadmV1qU/pHmvt2wpgjXodK9YN+UZm8Z14PhZp+DL xgmDvYkkr0167ZEcwozGBUygwRV8DXST+HN42Qz6467z1ziH7n090sFXiKt6tcIzyjYn PMYuBcPO98pveNySLwnX/0eZt0A+d032a1N+oo339a2QojpPNE6z0I0qp830Q+fu/E62 PUgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706545437; x=1707150237; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z3apTABZ+v0skZLpMZFSysqfsl0Aa7SJxdPj5lLmE2k=; b=RBEkCQBqXoAWr/t3OzmhVPZADZxlUL/yA/HE649OVakgj0KtkhailGyaWpRlVQgBWR i7ohODIsQdyNMxHN9rt4KBW80TVafqxsv/dt98LQhN1mEW2txw6blYcoqoae3ntpMHwA LsQuMzemQ+/MSm3j+QrLkN0Le56v5zbMJN/yqyXPjxRCPabJadQQ/LO2bNaXYEuGD0k2 Ka/k2Yd202iSbPU1sdrMncKdyEpVxrZPrZeqIiLxbYJR2GH2SsobBjWyokzj2HizXDa0 ppxtyRtCowEUKQAytypOQqdvhtVODqEbEL/95AIpGE2rlqRTMhBv29fm2M2tE1Ec93GD 47LA== X-Gm-Message-State: AOJu0Yxk0FZ1Vek9WuFRgDmCmRh1DUptw/qZmjIZQpVDqX36Ed3gsEKF W9pBg9EiRStxAk8YCLOiADD6qJ7Opt0qMMNjeQZr2Qy694yrWIZSB1u307gwNMKXDZwGdwHh6Cm bcPEdAFZ2VcvBiMcyMT7QObZ6GLg= X-Google-Smtp-Source: AGHT+IErMfZ3loDaTrSv3KHBEdJ1LfWL1ioV4g237/hNfOUTDxm68D8SqBhPDJOfnOdGilQOPjYK1H49il1/Nwc9i2w= X-Received: by 2002:a81:b704:0:b0:5ff:81ba:d89f with SMTP id v4-20020a81b704000000b005ff81bad89fmr4931362ywh.5.1706545436959; Mon, 29 Jan 2024 08:23:56 -0800 (PST) MIME-Version: 1.0 References: <20240127151055.358066-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Mon, 29 Jan 2024 08:23:21 -0800 Message-ID: Subject: Re: [PATCH] Handle function symbol reference in readonly data section To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3014.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Jan 29, 2024 at 8:03=E2=80=AFAM Jakub Jelinek wr= ote: > > On Mon, Jan 29, 2024 at 06:36:47AM -0800, H.J. Lu wrote: > > TARGET_ASM_SELECT_RTX_SECTION is for constant in RTL. > > It should have a non-public label reference which can't be used > > by other TUs. The same section can contain other constants. > > If there is a COMAT issue, linker will catch it. > > Let me try to explain on short assembly snippet what I believe your patch= is > doing and what I'm afraid of. I believe your patch when we need to emit > a RTL constant foo or foo+1 or foo+2 (where foo is defined in a comdat > section) instead of emitting using say foo in assembly puts those > constants into .data.rel.ro.local section determined by the decl that is > referenced. > Now, when first_tu.o wins and emits the qux comdat, it will contain > the .data.rel.ro.local.foo which bar function refers to, but in second_tu= .o > it wants to refer to different offsets from the same function and loses. > > I simply believe the constants need to be in section based on what refers > to those symbols, not the value of those constants, and that is what we u= sed > to do before your patch (and I'd like to understand what's wrong with wha= t > GCC emits and why). > > first_tu.s: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > .section .text.foo,"axG",@progbits,qux,comdat > .p2align 4 > .type foo, @function > foo: > xorl %eax, %eax > ret > .size foo, .-foo > .text > .p2align 4 > .type bar, @function > bar: > movq .LC0(%rip), %xmm0 > ret > .size bar, .-bar > .section .data.rel.ro.local.foo,"awG",@progbits,qux,comdat > .align 8 > .LC0: > .quad foo > > second_tu.s: > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > .section .text.foo,"axG",@progbits,qux,comdat > .p2align 4 > .type foo, @function > foo: > xorl %eax, %eax > ret > .size foo, .-foo > .text > .p2align 4 > .type baz, @function > baz: > movq .LC0(%rip), %xmm0 > ret I don't think this is valid. We can't reference a non-public symbol outside of a COMDAT group. It is OK to reference foo or foo + 1, but not .LC0. > .size baz, .-baz > .section .data.rel.ro.local.foo,"awG",@progbits,qux,comdat > .align 8 > .LC0: > .quad foo+1 > .text > .p2align 4 > .type corge, @function > corge: > movq .LC1(%rip), %xmm0 > ret > .size corge, .-corge > .section .data.rel.ro.local.foo,"awG",@progbits,qux,comdat > .align 8 > .LC1: > .quad foo+2 > gcc -shared -o test.so first_tu.s second_tu.s > `.data.rel.ro.local.foo' referenced in section `.text' of /tmp/cceeUWyH.o= : defined in discarded section `.data.rel.ro.local.foo[qux]' of /tmp/cceeUW= yH.o > `.data.rel.ro.local.foo' referenced in section `.text' of /tmp/cceeUWyH.o= : defined in discarded section `.data.rel.ro.local.foo[qux]' of /tmp/cceeUW= yH.o > collect2: error: ld returned 1 exit status > > Jakub > --=20 H.J.