From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by sourceware.org (Postfix) with ESMTPS id 190BC386F401 for ; Thu, 24 Sep 2020 13:59:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 190BC386F401 Received: by mail-io1-xd41.google.com with SMTP id q4so3406913iop.5 for ; Thu, 24 Sep 2020 06:59:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=qAvV6KQLvQzh97Zofj5Qlg1X3XCwszsEaEuqOxR0BH8=; b=n7a6tJPONGcT4Z4mGsNJLd7B8DMjg6eszENLQBGxov43VDreq3fyGg0ll3+hfZ10VK m90oRbi19J8B8/ZuyEFr1pcYezxrXbhqY7QxuRPJXW6ReVt6DHR3ZmkMV6ktgh2pgmlM ZB+uX85CTwqr+jdYM6AfH2JZTWhx/lcVknHYnWKUMBAQYz2voPqrM9P8XVxhxValtJ/0 7If9ePXFBOEav3gv54YvoXHBtifUj2uXEtCIg6sJ/NcgFd5UskV43TfZTdRgR97wuP8N ilyQJpp70qsW9HZO03mT/iiNBxQVHH7JJkMAFKDZA/RafqaJsBO0dVqFPgc2EurxzXdA PMCA== X-Gm-Message-State: AOAM531gHYgZBZx9JMwu4VxzU26ZUuJB1YvHMw3PyaUrI3q/P2ZWLRcb egkEjj3RNSJvkH5mlJzA/JqPKtTC6GYnt3NZUWU= X-Google-Smtp-Source: ABdhPJxXSg0DhncIkzlx0uG8/dhsCGFiqnohDjnAn/JezFJfzKzCNBEbAWPQE5xD4MWUI7v2nvErDA6IX4NQs9NpkH4= X-Received: by 2002:a6b:b787:: with SMTP id h129mr3376541iof.202.1600955983445; Thu, 24 Sep 2020 06:59:43 -0700 (PDT) MIME-Version: 1.0 References: <20200923095818.npbwybrm63vb4ejm@jozef-acer-manjaro> <20200923165211.fr4rqzp5uqqmrufq@jozef-acer-manjaro> <20200923184735.4k2tji4yro452bep@jozef-acer-manjaro> <20200923200437.mnegrmwebjuzmfeu@jozef-acer-manjaro> <20200924134914.fmkyo4xqimjatf7u@jozef-acer-manjaro> In-Reply-To: <20200924134914.fmkyo4xqimjatf7u@jozef-acer-manjaro> From: "H.J. Lu" Date: Thu, 24 Sep 2020 06:59:07 -0700 Message-ID: Subject: Re: [PATCH] Support SHF_GNU_RETAIN ELF section flag To: "H.J. Lu" , Michael Matz , Binutils Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.2 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 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: Thu, 24 Sep 2020 13:59:45 -0000 On Thu, Sep 24, 2020 at 6:49 AM Jozef Lawrynowicz wrote: > > On Thu, Sep 24, 2020 at 06:18:05AM -0700, H.J. Lu via Binutils wrote: > > On Wed, Sep 23, 2020 at 1:17 PM H.J. Lu wrote: > > > > > > On Wed, Sep 23, 2020 at 1:04 PM Jozef Lawrynowicz > > > wrote: > > > > > > > > On Wed, Sep 23, 2020 at 12:03:28PM -0700, H.J. Lu via Binutils wrote: > > > > > On Wed, Sep 23, 2020 at 11:47 AM Jozef Lawrynowicz > > > > > wrote: > > > > > > > > > > > > On Wed, Sep 23, 2020 at 10:13:37AM -0700, H.J. Lu via Binutils wrote: > > > > > > > On Wed, Sep 23, 2020 at 9:52 AM Jozef Lawrynowicz > > > > > > > wrote: > > > > > > > > > > > > > > > > On Wed, Sep 23, 2020 at 01:51:56PM +0000, Michael Matz wrote: > > > > > > > > > Hello, > > > > > > > > > > > > > > > > > > On Wed, 23 Sep 2020, H.J. Lu via Binutils wrote: > > > > > > > > > > > > > > > > > > > > I think that: > > > > > > > > > > > > > > > > > > > > > > > .section .text,"ax" > > > > > > > > > > > > ... > > > > > > > > > > > > foo: > > > > > > > > > > > > ... > > > > > > > > > > > > .retain > > > > > > > > > > > > retained_fn: > > > > > > > > > > > > ... > > > > > > > > > > > > > > > > > > > > > > is some nice syntactic sugar compared to: > > > > > > > > > > > > > > > > > > > > > > > .section .text,"ax" > > > > > > > > > > > > ... > > > > > > > > > > > > foo: > > > > > > > > > > > > ... > > > > > > > > > > > > .section .text,"axR" > > > > > > > > > > > > retained_fn: > > > > > > > > > > > > ... > > > > > > > > > > > > > > > > > > > > > > It's also partly for convenience; we have other directives which are > > > > > > > > > > > synonyms or short-hand for each other. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > You don't need to keep the whole section when only one symbol should > > > > > > > > > > be kept. Please drop the .retain directive. GCC, as and ld should do the > > > > > > > > > > right thing with > > > > > > > > > > > > > > > > > > > > .section .text,"ax" > > > > > > > > > > ... > > > > > > > > > > foo: > > > > > > > > > > ... > > > > > > > > > > .section .text,"axR" > > > > > > > > > > > > > > > > > > > > retained_fn: > > > > > > > > > > > > > > > > > > > > where foo can be dropped and retained_fn will be kept. > > > > > > > > > > > > > > > > > > This is not what we discussed at the ABI list, the flag is per section, so > > > > > > > > > either the whole section is retained or not. What you describe is > > > > > > > > > something else that would work on a per symbol basis, which would have to > > > > > > > > > be specified in a different way and might or might not be a good idea. > > > > > > > > > But let's not conflate these two. > > > > > > > > > > > > > > > > Also, the linker cannot currently dissect a section and remove a > > > > > > > > particular unused symbol anyway. Since garbage collection only operates > > > > > > > > on the section level, marking the section itself as "retained" seems > > > > > > > > most appropriate. > > > > > > > > > > > > > > It can be done. If you put your branch on > > > > > > > > > > > > > > https://gitlab.com/x86-binutils/binutils-gdb > > > > > > > > > > > > > > I can help you implement it. > > > > > > > > > > > > It's not something I have time to look into at the moment, for now the > > > > > > aim is just to prevent garbage collection of sections. > > > > > > > > > > Linker and assembler already support it. You just need to add SHF_GNU_RETAIN > > > > > to the framework. Check how SHF_GNU_MBIND works. > > > > > > > > Sorry, I don't understand. > > > > > > > > Are you saying that LD already supports the garbage collection of > > > > individual unused symbol definitions from input sections? Whilst > > > > retaining other symbol definitions which are required by the program? > > > > I cannot find any reference to this. > > > > > > > > How does that relate to SHF_GNU_MBIND? I looked at all the references > > > > to "mbind" in Binutils and nothing seemed related garbage collection of > > > > sections, since SHF_GNU_MBIND is just used to indicate a particular > > > > section should be placed in a special memory area. > > > > > > For > > > > > > section .text,"ax" > > > ... > > > foo: > > > ... > > > .section .text,"axR" > > > retained_fn: > > > > > > you need to create a new .text section with SHF_GNU_RETAIN for > > > retained_fn. See get_section in obj-elf.c. If you want to avoid > > > > See users/hjl/elf/master branch at: > > > > https://gitlab.com/x86-binutils/binutils-gdb/-/commits/users/hjl/elf/master > > > > I removed the .retain directive. > > Thanks, the formalization of section flag merging in the assembler is > nice. > > My only comment is that I used the "STT_*" syntax in the .type directive > instead of % because some targets didn't like the % syntax and emmited > an error. I don't remember which, maybe it was mmix-elf, in which case > we don't care :) Some targets don't support @object. %object works for all targets. > When I re-test I'll see if the errors pop up again. > > I still need to add the GNU OSABI handling, but with that and your > patches we are probably ready to apply after a final official sign-off. > > How would that work logistically, I apply my patch and you apply yours > after? Or do we align off-master and apply as one patch? > Please get an account on gitlab.com and send me your account name. Then you can put your branch in https://gitlab.com/x86-binutils/binutils-gdb and we can work together to finish it. -- H.J.