From patchwork Tue Mar 24 21:15:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 5795 Received: (qmail 79485 invoked by alias); 24 Mar 2015 21:15:46 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 79473 invoked by uid 89); 24 Mar 2015 21:15:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Tue, 24 Mar 2015 22:15:41 +0100 From: Mark Wielaard To: Szabolcs Nagy Cc: "libc-alpha@sourceware.org" , Josh Stone Subject: Re: [PATCH] elf.h SHF_EXCLUDE signed int 31 bit shift triggers undefined behaviour. Message-ID: <20150324211541.GA2318@blokker.redhat.com> References: <1427193579-26102-1-git-send-email-mjw@redhat.com> <55117118.1080706@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <55117118.1080706@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) On Tue, Mar 24, 2015 at 02:13:44PM +0000, Szabolcs Nagy wrote: > > On 24/03/15 10:39, Mark Wielaard wrote: > > Any use of SHF_EXCLUDE in code that tries to check it against sh_flags > > will trigger undefined behaviour because it is defined as a 31 bit shift > > against an signed integer. Fix by explicitly using an unsigned int. > > there is another proposed patch for this > > https://sourceware.org/ml/libc-alpha/2015-03/msg00287.html I missed that one. It does seem more ambitious than what I am proposing. It is probably a good idea to change every constant to the appropriate unsigned type. But the testing requirements seem hard to satisfy and it looks like that patch is stalled because of that. Could this simpler patch that just fixes the one constant that does have a real problem in practice when used be fixed independently? I like building my project with gcc -fsanitize=undefined and the usage of SHF_EXCLUDE is preventing that atm. > > ChangeLog | 4 ++++ > > elf/elf.h | 2 +- > > 2 files changed, 5 insertions(+), 1 deletion(-) > > > > i think changelog entries are supposed to be submitted separately OK. How about the following then? I would appreciate it if someone could push that for me since I don't have glibc commit access. Thanks, Mark 2015-03-24 Mark Wielaard * elf/elf.h (SHF_EXCLUDE): Use unsigned 1 for shift. diff --git a/elf/elf.h b/elf/elf.h index 496f08d..960a3c3 100644 --- a/elf/elf.h +++ b/elf/elf.h @@ -371,7 +371,7 @@ typedef struct #define SHF_MASKPROC 0xf0000000 /* Processor-specific */ #define SHF_ORDERED (1 << 30) /* Special ordering requirement (Solaris). */ -#define SHF_EXCLUDE (1 << 31) /* Section is excluded unless +#define SHF_EXCLUDE (1U << 31) /* Section is excluded unless referenced or allocated (Solaris).*/ /* Section group handling. */