From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17168 invoked by alias); 11 Apr 2005 17:37:43 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 16699 invoked from network); 11 Apr 2005 17:37:34 -0000 Received: from unknown (HELO rwcrmhc14.comcast.net) (216.148.227.89) by sourceware.org with SMTP; 11 Apr 2005 17:37:34 -0000 Received: from lucon.org ([24.6.212.230]) by comcast.net (rwcrmhc14) with ESMTP id <20050411173733014002uppne>; Mon, 11 Apr 2005 17:37:34 +0000 Received: by lucon.org (Postfix, from userid 1000) id 9D9FD63D5D; Mon, 11 Apr 2005 10:37:33 -0700 (PDT) Date: Mon, 11 Apr 2005 17:37:00 -0000 From: "H. J. Lu" To: binutils@sources.redhat.com Subject: Re: [hjl@lucon.org: Re: your patch to remove unused sections] Message-ID: <20050411173733.GA17706@lucon.org> References: <20050411140930.GA14672@lucon.org> <20050411144356.GC861@bubble.modra.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050411144356.GC861@bubble.modra.org> User-Agent: Mutt/1.4.1i X-SW-Source: 2005-04/txt/msg00244.txt.bz2 On Tue, Apr 12, 2005 at 12:13:56AM +0930, Alan Modra wrote: > On Mon, Apr 11, 2005 at 07:09:30AM -0700, H. J. Lu wrote: > > Hi Alan, > > > > Have you looked at this patch? > > Yes, I was going to ask for a revision, but wanted to check whether my > idea was feasible before asking you to make a change, which would remove > the following loop: > > > + /* .bss and similar sections won't have the linker_mark > > + field set. We have to check if its output section is > > + included in output_bfd. */ > > + for (sec = output_bfd->sections; sec != NULL; sec = sec->next) > > + if (sec == sym->section->output_section) > > + break; > > I haven't had time to check, but here's the idea anyway: After removing > an unused output section s with bfd_section_list_remove (output_bfd, s), > clear s->next. Then > > if (sym->section->output_section->next == NULL > && *output_bfd->section_tail != sym->section->output_section) It should be if (sym->section->output_section->next == NULL && output_bfd->section_tail != &sym->section->output_section->next) > { > /* The section has been removed. */ > } This patch works for me. H.J. ---- 2005-04-11 H.J. Lu * linker.c (_bfd_generic_link_output_symbols): Also check if the output section of an input section has been removed from the output file. * section.c (bfd_section_list_remove): Clear the next field of the removed section. (bfd_section_removed_from_list): New. * bfd-in2.h: Regenerated. --- bfd/linker.c.generic 2005-02-11 09:28:14.000000000 -0800 +++ bfd/linker.c 2005-04-11 09:47:58.000000000 -0700 @@ -2363,12 +2363,14 @@ _bfd_generic_link_output_symbols (bfd *o abort (); /* If this symbol is in a section which is not being included - in the output file, then we don't want to output the symbol. - - Gross. .bss and similar sections won't have the linker_mark - field set. */ - if ((sym->section->flags & SEC_HAS_CONTENTS) != 0 - && ! sym->section->linker_mark) + in the output file, then we don't want to output the + symbol. .bss and similar sections won't have the linker_mark + field set. We also check if its output section has been + removed from the output file. */ + if (((sym->section->flags & SEC_HAS_CONTENTS) != 0 + && ! sym->section->linker_mark) + || bfd_section_removed_from_list (output_bfd, + sym->section->output_section)) output = FALSE; if (output) --- bfd/section.c.generic 2005-03-03 08:56:09.000000000 -0800 +++ bfd/section.c 2005-04-11 10:25:52.573055557 -0700 @@ -546,6 +546,8 @@ CODE_FRAGMENT . *_ps = _s->next; \ . if (_s->next == NULL) \ . (ABFD)->section_tail = _ps; \ +. else \ +. _s->next = NULL; \ . } \ . while (0) .#define bfd_section_list_insert(ABFD, PS, S) \ @@ -559,6 +561,8 @@ CODE_FRAGMENT . (ABFD)->section_tail = &_s->next; \ . } \ . while (0) +.#define bfd_section_removed_from_list(ABFD, S) \ +. ((S)->next == NULL && &(S)->next != (ABFD)->section_tail) . */