From patchwork Sun Dec 11 18:03:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grazvydas Ignotas X-Patchwork-Id: 9469847 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B045A60761 for ; Sun, 11 Dec 2016 18:04:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A73F020564 for ; Sun, 11 Dec 2016 18:04:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BC8A2831C; Sun, 11 Dec 2016 18:04:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D9DA20564 for ; Sun, 11 Dec 2016 18:04:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2E34E6E10A; Sun, 11 Dec 2016 18:04:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5DB126E06A for ; Sun, 11 Dec 2016 18:04:03 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id a20so6271441wme.2 for ; Sun, 11 Dec 2016 10:04:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=XXLhEu1PcyRlpsrvuA5NFy1G6G7ogbwH0qO50wNlPEg=; b=bzbKB3ED/Y1rTWDJ+zBGaM8t50shVkSA+9HN/gbXCeV4O52ZmKLqdeepnszfMbKOEf TuFGDy4jpY7c/by3fu0elkdna/0XeSb8+RjMpmh5kOnkEkdlhgJvufJ2ij9v2DxaxDVM zel1/84ejYiqd6Rd+JxHIZ5fsmZgTTa33RNe5IwsNbta1lCNkD6W1e8e3VMs1TAl21Mo Z9NcqZa23lohnbgtLU9nfEIGyECcW+875vmQ9kOgXbglTRkLGUo5QDtIrZl7lWRXS6y4 sDk6I+9FZ6D5zCfmGaoimouoyNitTbpCoRFZ0lkRagAQr4uKGJi7REXxgIeyRUNaVONH 9wfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=XXLhEu1PcyRlpsrvuA5NFy1G6G7ogbwH0qO50wNlPEg=; b=SVHMpAGGr8KbpTRxAZufIZQe6HP5L5rCyHYtXoMUsR30iZJ4INCYWoUsmf0kWhw0Jg iZ2pAB4jzZq/X1vJq9lBr7rD1mXQ53UuVKkDe1m+ywB5hyR0JnFMmb1uVv2UMEeJ7GHM jyXcS/l4ebNTR2koj81OE4ZqveOqSSzyFIs4Fl3BQyzT3TR2n2aCvvo50xTo6RwI/iwb J/Sqj+BFOF/93nyMG5yRsJ0kh6C0N77x2uaO6ORWcAvUuAKrZ21DplNgzJ8NAwOARJqV IW0/JkYGn4UijQ9eM01/VsJd+OpyyboNlHZiNYg9JxH5kKQQUGWqy0SVBxtumFMJ7AxL HQ3g== X-Gm-Message-State: AKaTC00uHzmugnbbi7gkoFHWwkP32AlKhDPUV6J5LEUbwjjZ77SWuDrjPuCIaXqR18LknQ== X-Received: by 10.25.79.21 with SMTP id d21mr3414039lfb.49.1481479441456; Sun, 11 Dec 2016 10:04:01 -0800 (PST) Received: from localhost.localdomain ([5.20.238.37]) by smtp.gmail.com with ESMTPSA id y25sm8295562lja.13.2016.12.11.10.04.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Dec 2016 10:04:01 -0800 (PST) From: Grazvydas Ignotas To: dri-devel@lists.freedesktop.org Subject: [PATCH libdrm] xf86drm: fix aliasing violation Date: Sun, 11 Dec 2016 20:03:57 +0200 Message-Id: <1481479437-30537-2-git-send-email-notasas@gmail.com> X-Mailer: git-send-email 2.7.4 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Just tell the compiler that drm_event will alias the char buffer, so that it has no excuse to warn or generate bad code. Signed-off-by: Grazvydas Ignotas --- Android.mk | 1 + configure.ac | 9 +++++++++ libdrm_macros.h | 6 ++++++ xf86drmMode.c | 11 +++++++---- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Android.mk b/Android.mk index 2aa2bc9..ae7c3fe 100644 --- a/Android.mk +++ b/Android.mk @@ -42,6 +42,7 @@ LOCAL_C_INCLUDES := \ LOCAL_CFLAGS := \ -DHAVE_VISIBILITY=1 \ + -DHAVE_MAY_ALIAS=1 \ -DHAVE_LIBDRM_ATOMIC_PRIMITIVES=1 include $(BUILD_STATIC_LIBRARY) diff --git a/configure.ac b/configure.ac index e0597c3..2868036 100644 --- a/configure.ac +++ b/configure.ac @@ -507,6 +507,15 @@ if test "x$HAVE_ATTRIBUTE_VISIBILITY" = xyes; then AC_DEFINE(HAVE_VISIBILITY, 1, [Compiler supports __attribute__(("hidden"))]) fi +AC_MSG_CHECKING([whether $CC supports __attribute__((__may_alias__))]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([ + struct foo_may_alias { int i; } __attribute__((__may_alias__)) foo; +])], HAVE_ATTRIBUTE_MAY_ALIAS="yes"; AC_MSG_RESULT([yes]), AC_MSG_RESULT([no])); + +if test "x$HAVE_ATTRIBUTE_MAY_ALIAS" = xyes; then + AC_DEFINE(HAVE_MAY_ALIAS, 1, [Compiler supports __attribute__((__may_alias__))]) +fi + AC_SUBST(WARN_CFLAGS) AC_CONFIG_FILES([ Makefile diff --git a/libdrm_macros.h b/libdrm_macros.h index 639d090..eea47ee 100644 --- a/libdrm_macros.h +++ b/libdrm_macros.h @@ -29,6 +29,12 @@ # define drm_private #endif +#if defined(HAVE_MAY_ALIAS) +# define drm_may_alias __attribute__((__may_alias__)) +#else +# define drm_may_alias +#endif + /** * Static (compile-time) assertion. diff --git a/xf86drmMode.c b/xf86drmMode.c index fb22f68..a6bf5f7 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -52,6 +52,7 @@ #include #include +#include "libdrm_macros.h" #include "xf86drmMode.h" #include "xf86drm.h" #include @@ -885,9 +886,11 @@ int drmModeCrtcSetGamma(int fd, uint32_t crtc_id, uint32_t size, int drmHandleEvent(int fd, drmEventContextPtr evctx) { + struct drm_event_aliased { + struct drm_event e; + } drm_may_alias *e; char buffer[1024]; int len, i; - struct drm_event *e; struct drm_event_vblank *vblank; /* The DRM read semantics guarantees that we always get only @@ -901,8 +904,8 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx) i = 0; while (i < len) { - e = (struct drm_event *) &buffer[i]; - switch (e->type) { + e = (struct drm_event_aliased *) &buffer[i]; + switch (e->e.type) { case DRM_EVENT_VBLANK: if (evctx->version < 1 || evctx->vblank_handler == NULL) @@ -928,7 +931,7 @@ int drmHandleEvent(int fd, drmEventContextPtr evctx) default: break; } - i += e->length; + i += e->e.length; } return 0;