From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id BDE603858D29 for ; Mon, 15 Mar 2021 07:28:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BDE603858D29 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-166-64ycyS72PGqvXuP-Q43qCg-1; Mon, 15 Mar 2021 03:28:14 -0400 X-MC-Unique: 64ycyS72PGqvXuP-Q43qCg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CFBB801817; Mon, 15 Mar 2021 07:28:13 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-112-163.ams2.redhat.com [10.36.112.163]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9BB8A620DE; Mon, 15 Mar 2021 07:28:12 +0000 (UTC) From: Florian Weimer To: Fangrui Song via Libc-alpha Cc: Fangrui Song Subject: Re: [PATCH] Set the retain attribute on _elf_set_element if CC supports [BZ #27492] References: <20210315011050.309228-1-maskray@google.com> Date: Mon, 15 Mar 2021 08:28:18 +0100 In-Reply-To: <20210315011050.309228-1-maskray@google.com> (Fangrui Song via Libc-alpha's message of "Sun, 14 Mar 2021 18:10:50 -0700") Message-ID: <878s6ozxil.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: , X-List-Received-Date: Mon, 15 Mar 2021 07:28:18 -0000 * Fangrui Song via Libc-alpha: > So that text_set_element/data_set_element/bss_set_element defined > variables will be retained by the linker. > > Note: 'used' and 'retain' are orthogonal: 'used' makes sure the variable > will not be optimized out; 'retain' prevents section garbage collection > if the linker support SHF_GNU_RETAIN. This needs recent-ish GCC 11, see commit 6347f4a0904fce17e ("Add retain attribute to place symbols in SHF_GNU_RETAIN section). > +#ifdef __has_attribute > +#if __has_attribute (retain) > +# ifdef SHARED Indentation is off there. It's probably simpler to define a new macro, like ELEMENT_SECTION_ATTRIBUTES, and use that unconditionally, perhaps like this? #ifndef __ASSEMBLER__ # if defined (__has_attribute) && __has_attribute (retain) # define ELEMENT_SECTION_ATTRIBUTES used, retain # else # define ELEMENT_SECTION_ATTRIBUTES used # endif #endif Have you checked that __has_attribute (retain) is only true on GCC if the underlying linker has retain support and the attribute does not produce a warning? Thanks, Florian