From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59559 invoked by alias); 8 Apr 2016 14:13:28 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 59014 invoked by uid 89); 8 Apr 2016 14:13:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=excluding, asection X-HELO: mail-pf0-f171.google.com Received: from mail-pf0-f171.google.com (HELO mail-pf0-f171.google.com) (209.85.192.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 08 Apr 2016 14:13:22 +0000 Received: by mail-pf0-f171.google.com with SMTP id e128so76833440pfe.3 for ; Fri, 08 Apr 2016 07:13:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=7cb1im+Zwsm3ZBQ3ZPQZRxMAdqwQKefOdbjJ/mpbzyk=; b=HWKModo/rclpYl+z+ER49g8fp5s4pxH93rm7kZudb61dknx+eQH+jknbta2mC9wEfD b+gQEXw6oGnW4t4j/ydIrkpi+rV2xlIITFSZn54sSJux1czqqhm76ua1HOh/5vGWsMP+ B1ywT1wLEFrARbFMtOngFRH4E/Yfp0lHcb8XCE3qlLcpYnrlwFqUrDa0zd7Juld28oMO hK7RZd5L5XWz+WscAOucnP865v5n1959KofL6twmI09bWzRfqt4A6F0/sAqoom8EIJye l+DePoQxD02CkbtgJwE2pQAkB/QWQ9PIB7sb5rfwx0QDR/JvFwq3WHgcr1HcvHqm+132 KviQ== X-Gm-Message-State: AD7BkJL3Ez1XcL5ZGLrBoPH7Xw8K3tjSbVOxjwxMYgqCLQ39EIrkl8eIM6Zs2hFVQpX1gA== X-Received: by 10.98.79.205 with SMTP id f74mr13120455pfj.68.1460124800345; Fri, 08 Apr 2016 07:13:20 -0700 (PDT) Received: from bubble.grove.modra.org (CPE-58-160-146-233.sa.bigpond.net.au. [58.160.146.233]) by smtp.gmail.com with ESMTPSA id 62sm19154923pfk.83.2016.04.08.07.13.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 07:13:19 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id A48A4EA0157; Fri, 8 Apr 2016 23:43:14 +0930 (ACST) Date: Fri, 08 Apr 2016 14:13:00 -0000 From: Alan Modra To: binutils@sourceware.org Subject: PR18452, ld allows overlapping sections Message-ID: <20160408141314.GR18129@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00141.txt.bz2 This changes the way overlays are detected, enabling the new VMA check in lang_check_section_addresses in a lot more cases. The previous patch didn't fix the testcase in the PR, due to me being over-cautious and not wanting to trigger warnings for unusual overlays. I figure that if people do write really weird overlay scripts, then they can probably work out how to invoke ld with --no-check-sections. PR 18452 * ldlang.c (maybe_overlays): Delete. (lang_size_sections_1): Remove code setting maybe_overlays. (lang_check_section_addresses): Instead detect overlays by exact match of section VMAs here. Fix memory leak. diff --git a/ld/ldlang.c b/ld/ldlang.c index 5fbea3f..1947efc 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -75,7 +75,6 @@ static lang_statement_list_type **stat_save_ptr = &stat_save[0]; static struct unique_sections *unique_section_list; static struct asneeded_minfo *asneeded_list_head; static unsigned int opb_shift = 0; -static bfd_boolean maybe_overlays = FALSE; /* Forward declarations. */ static void exp_init_os (etree_type *); @@ -4742,6 +4741,7 @@ lang_check_section_addresses (void) bfd_vma p_start = 0; bfd_vma p_end = 0; lang_memory_region_type *m; + bfd_boolean overlays; if (bfd_count_sections (link_info.output_bfd) <= 1) return; @@ -4763,11 +4763,14 @@ lang_check_section_addresses (void) } if (count <= 1) - return; + { + free (sections); + return; + } qsort (sections, count, sizeof (*sections), sort_sections_by_lma); - /* First check sections LMAs. There should be no overlap of LMAs on + /* First check section LMAs. There should be no overlap of LMAs on loadable sections, even with overlays. */ for (p = NULL, i = 0; i < count; i++) { @@ -4797,11 +4800,28 @@ lang_check_section_addresses (void) } } - /* Now check sections VMAs if no overlays were detected. */ - if (!maybe_overlays) + /* If any non-zero size allocated section (excluding tbss) starts at + exactly the same VMA as another such section, then we have + overlays. Overlays generated by the OVERLAY keyword will have + this property. It is possible to intentionally generate overlays + that fail this test, but it would be unusual. */ + qsort (sections, count, sizeof (*sections), sort_sections_by_vma); + overlays = FALSE; + p_start = sections[0].sec->vma; + for (i = 1; i < count; i++) { - qsort (sections, count, sizeof (*sections), sort_sections_by_vma); + s_start = sections[i].sec->vma; + if (p_start == s_start) + { + overlays = TRUE; + break; + } + p_start = s_start; + } + /* Now check section VMAs if no overlays were detected. */ + if (!overlays) + { for (p = NULL, i = 0; i < count; i++) { s = sections[i].sec; @@ -4835,7 +4855,6 @@ lang_check_section_addresses (void) if (m->had_full_message) einfo (_("%X%P: region `%s' overflowed by %ld bytes\n"), m->name_list.name, (long)(m->current - (m->origin + m->length))); - } /* Make sure the new address is within the region. We explicitly permit the @@ -5149,18 +5168,6 @@ lang_size_sections_1 if (bfd_is_abs_section (os->bfd_section) || os->ignored) break; - if (r->last_os != NULL - && !IGNORE_SECTION (os->bfd_section) - && os->bfd_section->size != 0) - { - asection *last; - - last = r->last_os->output_section_statement.bfd_section; - if (dot + TO_ADDR (os->bfd_section->size) > last->vma - && dot < last->vma + TO_ADDR (last->size)) - maybe_overlays = TRUE; - } - /* Keep track of normal sections using the default lma region. We use this to set the lma for following sections. Overlays or other linker -- Alan Modra Australia Development Lab, IBM