From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 79343 invoked by alias); 9 Jan 2017 22:21:49 -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 79329 invoked by uid 89); 9 Jan 2017 22:21:49 -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=parens, UD:.shnum, bias, UD:1..shnum X-HELO: mail-pf0-f196.google.com Received: from mail-pf0-f196.google.com (HELO mail-pf0-f196.google.com) (209.85.192.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Jan 2017 22:21:47 +0000 Received: by mail-pf0-f196.google.com with SMTP id f144so6574909pfa.2 for ; Mon, 09 Jan 2017 14:21:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tGOb9QZFLR1t1ZcneaBzXPK/NtmNClH29y0Kjnmfcqo=; b=gZynZltSi26EgWEm5Y9sVKAvDuFmtX7vO/mDFumvLb1Ppx7jlcvwZngBgkehn60S2G uouYIXFeeukrvMB17FA2gdb3cUq2jtscDTBArq6c3JxD52hjgu5wPU8pYXl653834P1m HxinxIE8g6/4UOpGsSB29PXa7JF+y1hhkdcjcTxZnR7CmYoRfZ/ZduwTRvKAd69BzQop UQge4KPMcI1Csf9CtMEW9gbjI6W+VAK7q/KOcvmAuzInQmXjvEoBliIKeJbKMFU58F/E X/XHDbkbX/MnlvAZdiYmarv8XrF9HQEW4E5S3YSwNnKdz2TQBNOdea+YfdUlyqDrJ7Uf Tr7A== X-Gm-Message-State: AIkVDXKOSBw/5KXCrp+PgveQfSl7teijgldeRVqg1xqvmq+8h34P+WDYSJqhJYAcDTqxtA== X-Received: by 10.84.231.134 with SMTP id g6mr45476159plk.40.1484000505886; Mon, 09 Jan 2017 14:21:45 -0800 (PST) Received: from bubble.grove.modra.org (CPE-58-160-71-80.tyqh2.lon.bigpond.net.au. [58.160.71.80]) by smtp.gmail.com with ESMTPSA id 135sm183148462pgc.7.2017.01.09.14.21.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jan 2017 14:21:45 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 30D31C1682; Tue, 10 Jan 2017 08:51:41 +1030 (ACDT) Date: Mon, 09 Jan 2017 22:21:00 -0000 From: Alan Modra To: Cary Coutant Cc: Binutils Subject: Re: [GOLD] PowerPC64 TOC indirect to TOC relative code editing Message-ID: <20170109222141.GA32333@bubble.grove.modra.org> References: <20170108101404.GU31129@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00121.txt.bz2 On Mon, Jan 09, 2017 at 09:29:24AM -0800, Cary Coutant wrote: > > + if (start == 0) > > + start = 1; > > + if (start >= shnum) > > + return; > > Isn't (start >= shnum) a "can't happen" case? Why not just > gold_assert(start < shnum)? No, I don't think so. An object with shnum 0 or 1 is a valid ELF file as far as I known. > > + unsigned int i = start; > > + do > > { > > + const unsigned char* p = pshdrs + i * This::shdr_size; > > ... > > + } while ((i = i + 1 == shnum ? 1 : i + 1) != start); > > } > > Not a fan of that do...while loop. (Hmmm, what happens if shnum == 1?) shnum == 1 is excluded earlier. > At the least, the condition could use an extra pair of parens to make > it more readable. I think I'd prefer the original for loop, running > from 1..shnum, but add the bias and calculate p at the top of the > loop. Huh, I first wrote a patch that used the original for loop and decided it was cleaner to use do {} while(). You need an extra variable too, which probably will not be eliminated by a compiler. if (start == 0) start = 1; for (unsigned int i = 1; i < shnum; ++i) { unsigned int rel_shndx = i + start - 1; if (rel_shndx >= shnum) rel_shndx = i - shnum + 1; const unsigned char* p = pshdrs + rel_shndx * This::shdr_size; If I keep the do..while, where did you want the parens? Like this? } while ((i = (i + 1 == shnum) ? 1 : i + 1) != start); Now that you've seen the for loop option, which do you prefer? -- Alan Modra Australia Development Lab, IBM