From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3915 invoked by alias); 17 Mar 2009 17:12:40 -0000 Received: (qmail 3842 invoked by uid 22791); 17 Mar 2009 17:12:39 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from eu1sys200aog105.obsmtp.com (HELO eu1sys200aog105.obsmtp.com) (207.126.144.119) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Mar 2009 17:12:33 +0000 Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob105.postini.com ([207.126.147.11]) with SMTP ID DSNKSb/Z/llAABpokKtNdO91rc63CEtEem58@postini.com; Tue, 17 Mar 2009 17:12:33 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 26ABFDA9D for ; Tue, 17 Mar 2009 17:11:32 +0000 (GMT) Received: from mail2.gnb.st.com (mail2.gnb.st.com [164.129.119.59]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 725D14C7B2 for ; Tue, 17 Mar 2009 17:12:29 +0000 (GMT) Received: from [164.129.122.46] (gnx2504.gnb.st.com [164.129.122.46]) by mail2.gnb.st.com (MOS 3.8.7a) with ESMTP id DAW69517 (AUTH lyon); Tue, 17 Mar 2009 18:13:25 +0100 (CET) Message-ID: <49BFD9FD.7050705@st.com> Date: Tue, 17 Mar 2009 17:12:00 -0000 From: Christophe LYON User-Agent: Thunderbird 2.0.0.19 (X11/20081209) MIME-Version: 1.0 To: Binutils Subject: ARM long branch stubs: cleanup2 Content-Type: multipart/mixed; boundary="------------020809090600020701030906" X-IsSubscribed: yes 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 X-SW-Source: 2009-03/txt/msg00330.txt.bz2 This is a multi-part message in MIME format. --------------020809090600020701030906 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 180 Hi all, I propose the attached small patch which improves readability of some loops. It's probably a matter of taste, but I find this version easier to understand. Christophe. --------------020809090600020701030906 Content-Type: text/plain; name="loops.changelog" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="loops.changelog" Content-length: 133 2009-03-17 Christophe Lyon bfd/ * elf32-arm.c (group_sections): Rewrite loops for better readability. --------------020809090600020701030906 Content-Type: text/plain; name="loops.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="loops.patch" Content-length: 2814 Index: bfd/elf32-arm.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-arm.c,v retrieving revision 1.182 diff -u -p -r1.182 elf32-arm.c --- bfd/elf32-arm.c 17 Mar 2009 14:50:48 -0000 1.182 +++ bfd/elf32-arm.c 17 Mar 2009 17:08:10 -0000 @@ -3525,7 +3525,6 @@ group_sections (struct elf32_arm_link_ha { asection *tail = *list; asection *head; - asection *tp; if (tail == bfd_abs_section_ptr) continue; @@ -3535,38 +3534,35 @@ group_sections (struct elf32_arm_link_ha section may be required for an interrupt vector in bare metal code. */ #define NEXT_SEC PREV_SEC - head = tail; - tp = NULL; - for (;;) - { - asection *h = PREV_SEC (head); - NEXT_SEC (head) = tp; - if (h == NULL) - break; - tp = head; - head = h; - } + head = NULL; + while (tail != NULL) + { + /* Pop from tail */ + asection *item = tail; + tail = PREV_SEC(item); + + /* Push on head */ + NEXT_SEC(item) = head; + head = item; + } while (head != NULL) { asection *curr; asection *next; - bfd_size_type total; + bfd_vma stub_group_start = head->output_offset; + bfd_vma end_of_next; curr = head; - total = 0; - while ((next = NEXT_SEC (curr)) != NULL) + while (NEXT_SEC (curr) != NULL) { - if ( (total + next->output_offset - curr->output_offset - + next->size) - < stub_group_size ) - { - total += next->output_offset - curr->output_offset; - } - else + next = NEXT_SEC(curr); + end_of_next = next->output_offset + next->size; + if (end_of_next - stub_group_start >= stub_group_size) + /* End of NEXT is too far from start, so stop */ break; - - curr = next; + /* Add NEXT to the group. */ + curr = next; } /* OK, the size from the start to the start of CURR is less @@ -3588,20 +3584,17 @@ group_sections (struct elf32_arm_link_ha bytes after the stub section can be handled by it too. */ if (!stubs_always_after_branch) { - total = head->size; + stub_group_start = curr->output_offset + curr->size; + while (next != NULL) { - if ( (total + next->output_offset - head->output_offset - + next->size) - < stub_group_size ) - { - total += next->output_offset - head->output_offset; - } - else + end_of_next = next->output_offset + next->size; + if (end_of_next - stub_group_start >= stub_group_size) + /* End of NEXT is too far from stubs, so stop */ break; - + /* Add NEXT to the stub group */ head = next; - next = NEXT_SEC (head); + next = NEXT_SEC(head); htab->stub_group[head->id].link_sec = curr; } } --------------020809090600020701030906--