From patchwork Mon Aug 5 23:49:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1969272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=golang-org.20230601.gappssmtp.com header.i=@golang-org.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=sTsFJE6U; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WdCqP7104z1ybS for ; Tue, 6 Aug 2024 09:50:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77E433858430 for ; Mon, 5 Aug 2024 23:50:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id 2F0D3385840F for ; Mon, 5 Aug 2024 23:50:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F0D3385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=golang.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=golang.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2F0D3385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722901804; cv=none; b=E3F6o4ph4ntMEYwV9TAqL5iqtmqNLsqmaGUcUqekd9SBIAQcbp5Oy794NFRKxIU6ciAhvRtjR69WVJGhWQCJ2KUFstaYUS84VdHEM/FAPnvUvA9SqdZtaZKx34sHYLe2UJ8gIZQRKjDMhxP1KiV5GC1XNPcg2IOb7gOdKLqSYHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722901804; c=relaxed/simple; bh=q1aW+fwYT+ScGKl6EJuUyWLnhsjbv9sgAPo1nsrtPj0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=idl6nyH29soZx/NLdCEOmL6uYscsPz93Ov74HdR6qHBLbNlr07M5uXNP8FfhkQjfyvttoIQaUs6HGEtxlH64nWuv3XV4VUs5u9S2mtg0R98hlMq/pvbk+Rlyu7h3t4Mjjh0mXWcuQKhsklTB8dKMy/JekA9ASP7JmFxzgIneYnU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-67b709024bfso353127b3.3 for ; Mon, 05 Aug 2024 16:50:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golang-org.20230601.gappssmtp.com; s=20230601; t=1722901801; x=1723506601; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=6AwKbBhtuULDbwD6M90OhY27oVZNzxoxNcukzYsnAmw=; b=sTsFJE6U+TUn6MBf5MvJ8NSekQxJM3HuSmAKVwAUx97prFAOgnb/DW63SHDbg0dqAp 4uMrGGLTSGXX9pSqbkIZbAj30LPq/SM6KPXiAnXoQI/skofV6jMi0tH3guL9s06Yj1jf mNDd2gvkzNMTLtz5sheSkFMgs2SpwUUZSPuD8jVnogHieQEIOz3vciz8vMOPRB5qqGr2 zvyOiEQuamS6PVbEHjkmeYO6C8Wujk7feXy9V4EFy5dBLSF+85Sbw9IK1MvAx46+f2LT y/y3vu81K/OIkZhACxeIdpQwG8HxN7j4pxrI0le3HOPmnsDQC91qp8u4ainccFJNUjXh pR0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722901801; x=1723506601; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6AwKbBhtuULDbwD6M90OhY27oVZNzxoxNcukzYsnAmw=; b=shoKUXIooIHm5v+oCDqYC+pWfk+mhE5MIsn1Wrs0jwT/IzwUW80w7udLXybRmAgQAT l9svYIqQeG3yEnN2Z8VgwH7s8Pyz9icdCrT0RU/bXnrB6uhCX7b1PVJyLT7fZ8jhqZPs dlWSJBzwoeYZJZG/GCroZFt7Dvrr5XckF5K+Kg2ZdhnOSdxe5+7W3P1GO5LkDna7aJuC QL3ULQCcsM+DulAicpmnI/qrBHBj/fk+kSU7yiRufrr+TgO++JLNYsRQOJXnpRN/f5og IKsIURX2TOd0IMDH5FE8XDwX84sDu1TexB4MoKSCFfXgUeCnCCOg+BLUiWZFyypNRFaO fgOg== X-Gm-Message-State: AOJu0YxnOoEssiZVmXxtzgTUMA5y1BGcxx2P3yb2pt8zt0DTGTi3GEjE PMijpJANlxiZwkoLGL7MVXVw/E5Mfphx9b1V2LtT3SzuwAG7Ac4GrF9BMQAFEOQj4CiWiy/IUkH Cv8wU1EH3Plw5nF+oPw74ZGNmTxvwQuhtn8w5oDORCgtcm5rZ7yM= X-Google-Smtp-Source: AGHT+IHb9vt0WuK62ARsRrX8Kv3ppBc0oLVkDz6Smw8ET10P6CG7lgDBtW6vNQ5deIAaho7W9d3vf5eSq6I3B9EsuXc= X-Received: by 2002:a81:b406:0:b0:627:778f:b0a8 with SMTP id 00721157ae682-68964392725mr142302857b3.42.1722901801127; Mon, 05 Aug 2024 16:50:01 -0700 (PDT) MIME-Version: 1.0 From: Ian Lance Taylor Date: Mon, 5 Aug 2024 16:49:48 -0700 Message-ID: Subject: libbacktrace patch committed: Avoid -Wpointer-arith errors To: gcc-patches X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch, based on one by Kirill Müller, adds -Wpointer-arith to the libbacktrace warning options, and adds casts to avoid the cases where the warning currently fires. Bootstrapped and ran libbacktrace testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian * configure.ac (ACX_PROG_CC_WARNING_OPTS): Add -Wpointer-arith. * pecoff.c (coff_add): Cast void pointers. * xcoff.c (xcoff_add): Likewise. * configure: Regenerate. 3a51aaf5f4ccd3d2ed871727c16f9c6f9ed54e50 diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index bfd7f35d2d2..69eb2023677 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -145,7 +145,8 @@ AC_SUBST(EXTRA_FLAGS) ACX_PROG_CC_WARNING_OPTS([-W -Wall -Wwrite-strings -Wstrict-prototypes \ -Wmissing-prototypes -Wold-style-definition \ -Wmissing-format-attribute -Wcast-qual \ - -Wno-attributes -Wno-unknown-attributes], + -Wno-attributes -Wno-unknown-attributes \ + -Wpointer-arith], [WARN_FLAGS]) AC_ARG_ENABLE([werror], diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c index ccd5ccbce2c..15a73ff0b2a 100644 --- a/libbacktrace/pecoff.c +++ b/libbacktrace/pecoff.c @@ -704,7 +704,7 @@ coff_add (struct backtrace_state *state, int descriptor, magic_ok = memcmp (magic, "PE\0", 4) == 0; fhdr_off += 4; - memcpy (&fhdr, fhdr_view.data + 4, sizeof fhdr); + memcpy (&fhdr, (const unsigned char *) fhdr_view.data + 4, sizeof fhdr); } else { @@ -738,7 +738,7 @@ coff_add (struct backtrace_state *state, int descriptor, sects_view_valid = 1; opt_hdr = (const b_coff_optional_header *) sects_view.data; sects = (const b_coff_section_header *) - (sects_view.data + fhdr.size_of_optional_header); + ((const unsigned char *) sects_view.data + fhdr.size_of_optional_header); is_64 = 0; memset (&image_base, 0, sizeof image_base); @@ -781,7 +781,8 @@ coff_add (struct backtrace_state *state, int descriptor, goto fail; syms_view_valid = 1; - str_size = coff_read4 (syms_view.data + syms_size); + str_size = coff_read4 ((const unsigned char *) syms_view.data + + syms_size); str_off = syms_off + syms_size; diff --git a/libbacktrace/xcoff.c b/libbacktrace/xcoff.c index 01443c48401..84ce07b8e2c 100644 --- a/libbacktrace/xcoff.c +++ b/libbacktrace/xcoff.c @@ -1203,7 +1203,9 @@ xcoff_add (struct backtrace_state *state, int descriptor, off_t offset, goto fail; syms_view_valid = 1; - memcpy (&str_size, syms_view.data + syms_size, 4); + memcpy (&str_size, + (const unsigned char *) syms_view.data + syms_size, + 4); str_off = fhdr.f_symptr + syms_size;