From patchwork Tue Sep 8 20:20:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1360061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=A507M8Jo; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BmGkf2dRDz9sR4 for ; Wed, 9 Sep 2020 06:21:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66E6A3951822; Tue, 8 Sep 2020 20:21:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66E6A3951822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599596472; bh=gXJ8Bm/gLHRQ8UeP6x0aY7FQ4cBsuMl4ULzFPYTFyTA=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A507M8Jo+okRnwbvd3KNAQxgQk5zwRVu/c0gx88rqvLV1oDVGwIy47CsFCRgFvUwu +e3BhKiQAlnFfgf00ynWefNRv64UTspDGZMLtwI9oo2hVZCtdUNKHsPfh8JPuJ5Xjb R0KpXv8x8PSjezZWaUEzYCUADSHgXeFC5bv5Xu5U= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 353C2385042B for ; Tue, 8 Sep 2020 20:21:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 353C2385042B Received: by mail-ed1-x534.google.com with SMTP id a12so345733eds.13 for ; Tue, 08 Sep 2020 13:21:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=gXJ8Bm/gLHRQ8UeP6x0aY7FQ4cBsuMl4ULzFPYTFyTA=; b=uc+zIrlqC7nXaVxB6bwZ1dghIQ258pBE02fiJUAFwSGgzRFzIY+i6GqA80NLCt20Lq 6gQPtd1n0jI/dzYlVy23QsyZq3oYftz7xqlXJYNx9f6280o2rCbxzvzeV0sPd/Zojhe3 11Ch67z9YFVZ5XJYdSIYRPiUeDkV9etEwKiVp2SxSiCHCs+5KrqPUsGLrRAi6lPLf/E2 AyYC9EfUlJVV5JLjHM960xOP8Rup3hKScPHWfiUtDrfudGFRLR4y5QmrW5X3T06k0zST oJmPdkZYQWdONRpQXm7boUiKZJ0GQnyajUBjbWTPBWci/1NsCyC8iAGfdo+ZpIVDQCFL 7wqQ== X-Gm-Message-State: AOAM530NaEI2nC7P/bDLNDLY8WNrB8Oos6VsmFBWRFykH3DkAfu2URjn KnMS/VXc4p52HnRcXe89XN7F/xCWEFqbwokYtgERHa5FjNe4Fw== X-Google-Smtp-Source: ABdhPJyN2zwzsbElWTkZ0AdaBkYi5d9K1A/zsxZoYsDaMbcdXApMAa+LanL6E2P54h5o9O0BteD34HfeD9FNuWxaBYg= X-Received: by 2002:a50:fe07:: with SMTP id f7mr815687edt.173.1599596468829; Tue, 08 Sep 2020 13:21:08 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 8 Sep 2020 13:20:57 -0700 Message-ID: Subject: libbacktrace patch committed: Correctly swap Mach-O fat 32-bit file offset To: gcc-patches X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, UNWANTED_LANGUAGE_BODY autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Level: *** X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This libbacktrace patch correctly swaps the 32-bit file offset in a Mach-O fat file. This is based on a patch by Francois-Xavier Coudert , who analyzed the problem. This is for PR 96973. Bootstrapped and ran libbacktrace tests on x86_64-pc-linux-gnu. Committed to mainline. Ian PR libbacktrace/96973 * macho.c (macho_add_fat): Correctly swap 32-bit file offset. diff --git a/libbacktrace/macho.c b/libbacktrace/macho.c index bd737226ca6..20dd3262d58 100644 --- a/libbacktrace/macho.c +++ b/libbacktrace/macho.c @@ -793,13 +793,24 @@ macho_add_fat (struct backtrace_state *state, const char *filename, for (i = 0; i < nfat_arch; ++i) { - struct macho_fat_arch_64 fat_arch; uint32_t fcputype; + uint64_t foffset; if (is_64) - memcpy (&fat_arch, - (const char *) arch_view.data + i * arch_size, - arch_size); + { + struct macho_fat_arch_64 fat_arch_64; + + memcpy (&fat_arch_64, + (const char *) arch_view.data + i * arch_size, + arch_size); + fcputype = fat_arch_64.cputype; + foffset = fat_arch_64.offset; + if (swapped) + { + fcputype = __builtin_bswap32 (fcputype); + foffset = __builtin_bswap64 (foffset); + } + } else { struct macho_fat_arch fat_arch_32; @@ -807,26 +818,18 @@ macho_add_fat (struct backtrace_state *state, const char *filename, memcpy (&fat_arch_32, (const char *) arch_view.data + i * arch_size, arch_size); - fat_arch.cputype = fat_arch_32.cputype; - fat_arch.cpusubtype = fat_arch_32.cpusubtype; - fat_arch.offset = (uint64_t) fat_arch_32.offset; - fat_arch.size = (uint64_t) fat_arch_32.size; - fat_arch.align = fat_arch_32.align; - fat_arch.reserved = 0; + fcputype = fat_arch_32.cputype; + foffset = (uint64_t) fat_arch_32.offset; + if (swapped) + { + fcputype = __builtin_bswap32 (fcputype); + foffset = (uint64_t) __builtin_bswap32 ((uint32_t) foffset); + } } - fcputype = fat_arch.cputype; - if (swapped) - fcputype = __builtin_bswap32 (fcputype); - if (fcputype == cputype) { - uint64_t foffset; - /* FIXME: What about cpusubtype? */ - foffset = fat_arch.offset; - if (swapped) - foffset = __builtin_bswap64 (foffset); backtrace_release_view (state, &arch_view, error_callback, data); return macho_add (state, filename, descriptor, foffset, match_uuid, base_address, skip_symtab, error_callback, data,