From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 9C22B3835409 for ; Tue, 2 Mar 2021 09:47:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9C22B3835409 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id BA4EFAFCE for ; Tue, 2 Mar 2021 09:47:44 +0000 (UTC) Subject: [PATCH 2/6] bfd: prune COFF/PE section flags setting To: Binutils References: <67c184ec-e370-46ee-46d3-bd001ef80445@suse.com> From: Jan Beulich Message-ID: Date: Tue, 2 Mar 2021 10:47:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <67c184ec-e370-46ee-46d3-bd001ef80445@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3033.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_MSPIKE_H3, 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: 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: Tue, 02 Mar 2021 09:47:47 -0000 It is my understanding that IMAGE_SCN_LNK_* are supposed to communicate information to the (static) linker, and become at best meaningless in PE images. I wouldn't call loaders wrong which would refuse to process sections with any of these bits set. While there's no replacement for IMAGE_SCN_LNK_COMDAT, use IMAGE_SCN_MEM_DISCARDABLE in place of IMAGE_SCN_LNK_REMOVE in this case. bfd/ 2021-02-XX Jan Beulich * coffcode.h (sec_to_styp_flags): Don't set IMAGE_SCN_LNK_* in final PE images. --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -672,22 +672,31 @@ sec_to_styp_flags (const char *sec_name, /* skip ROM */ /* skip constRUCTOR */ /* skip CONTENTS */ +#ifndef COFF_IMAGE_WITH_PE + /* I don't think any of the IMAGE_SCN_LNK_* flags set below should be set + when the output is PE. Only object files should have them, for the linker + to consume. */ if ((sec_flags & SEC_IS_COMMON) != 0) styp_flags |= IMAGE_SCN_LNK_COMDAT; +#endif if ((sec_flags & SEC_DEBUGGING) != 0) styp_flags |= IMAGE_SCN_MEM_DISCARDABLE; - if ((sec_flags & SEC_EXCLUDE) != 0 && !is_dbg) - styp_flags |= IMAGE_SCN_LNK_REMOVE; - if ((sec_flags & SEC_NEVER_LOAD) != 0 && !is_dbg) + if ((sec_flags & (SEC_EXCLUDE | SEC_NEVER_LOAD)) != 0 && !is_dbg) +#ifdef COFF_IMAGE_WITH_PE + styp_flags |= IMAGE_SCN_MEM_DISCARDABLE; +#else styp_flags |= IMAGE_SCN_LNK_REMOVE; +#endif /* skip IN_MEMORY */ /* skip SORT */ +#ifndef COFF_IMAGE_WITH_PE if (sec_flags & SEC_LINK_ONCE) styp_flags |= IMAGE_SCN_LNK_COMDAT; if ((sec_flags & (SEC_LINK_DUPLICATES_DISCARD | SEC_LINK_DUPLICATES_SAME_CONTENTS | SEC_LINK_DUPLICATES_SAME_SIZE)) != 0) styp_flags |= IMAGE_SCN_LNK_COMDAT; +#endif /* skip LINKER_CREATED */