From patchwork Tue Apr 3 16:07:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 894681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-475769-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CIAOsoXz"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40FvCK246fz9s21 for ; Wed, 4 Apr 2018 02:08:29 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=fwAfeWtfd9MB7/Xj+Dc/1uYZE6CGL hRkqCsOPpHtPUmQmlXz9Buo8m0b7hIsvtOxq9vtnxyo1t/x67zp4sTia3NiLoYri qmAsyDGy5hvM8yYXV7Q1Cl+AB9VRamQkJXJxlHqOW1R5HffwNw/C3hJRcSXHbVZH TnL3UUzdsWUvn0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=tZziPR6NmxkZV7VTtkDGj3BWLwQ=; b=CIA OsoXzvA5Vvrlhg+0nr16LGqWfmVJjG4FEUW44/buGlvKN2RWeRCIEaieuMro5dHd or6w+xllBQrM4zza+iDZgh4Tddy1AeL0AF072rdqXABtXfXefs8QFGbSCUwilQNF BqBHZbVOy2BvdzunlXdPExxqUzWB9vnEktkqTe6g= Received: (qmail 53624 invoked by alias); 3 Apr 2018 16:07:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 53528 invoked by uid 89); 3 Apr 2018 16:07:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=falls, We've, PIN, Weve X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Apr 2018 16:07:29 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AD72402290A; Tue, 3 Apr 2018 16:07:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.36.118.110]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17CC17C50; Tue, 3 Apr 2018 16:07:27 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w33G7PBH011608; Tue, 3 Apr 2018 18:07:26 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w33G7Pu6011607; Tue, 3 Apr 2018 18:07:25 +0200 Date: Tue, 3 Apr 2018 18:07:25 +0200 From: Jakub Jelinek To: Ian Lance Taylor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix libbacktrace zdebug decompression on big endian (PR other/85161) Message-ID: <20180403160725.GE8577@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! As mentioned in the PR, GCC (and clang) predefines {__BYTE_ORDER__,__ORDER_{LITTLE,BIG,PDP}_ENDIAN__} macros, and {,sys/,machine/}endian.h headers predefine {,__}{BYTE_ORDER,{LITTLE,BIG,PDP}_ENDIAN} macros (depending on which target and feature test macros). elf.c in GCC 8 used __BYTE_ORDER, which is endian.h macro, but didn't include that header and it on glibc just happened to be included indirectly because of default feature test macros from stdlib.h, and used non-existing __ORDER_BIG_ENDIAN macro; as __BYTE_ORDER is always non-zero when defined (1234, 4321 etc.), that means __builtin_bswap32 was never used. The following patch just uses the GCC/clang predefined macros if known to be big or little endian, and otherwise just falls back to portable code (that good compilers can still optimize). Bootstrapped/regtested on x86_64-linux and i686-linux and tested on powerpc64-linux, ok for trunk? 2018-04-03 Jakub Jelinek PR other/85161 * elf.c (elf_zlib_fetch): Fix up predefined macro names in test for big endian, only use 32-bit loads if endianity macros are predefined and indicate big or little endian. Jakub --- libbacktrace/elf.c.jj 2018-02-15 12:30:53.948579969 +0100 +++ libbacktrace/elf.c 2018-04-03 14:47:32.536550472 +0200 @@ -1086,12 +1086,19 @@ elf_zlib_fetch (const unsigned char **pp return 0; } +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \ + && defined(__ORDER_BIG_ENDIAN__) \ + && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \ + || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* We've ensured that PIN is aligned. */ next = *(const uint32_t *)pin; -#if __BYTE_ORDER == __ORDER_BIG_ENDIAN +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ next = __builtin_bswap32 (next); #endif +#else + next = pin[0] | (pin[1] << 8) | (pin[2] << 16) | (pin[3] << 24); +#endif val |= (uint64_t)next << bits; bits += 32;