All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@kernel.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Arnd Bergmann <arnd@arndb.de>, Mike Leach <mike.leach@linaro.org>,
	Leo Yan <leo.yan@linaro.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>,
	coresight@lists.linaro.org,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	Bill Wendling <morbo@google.com>
Subject: Re: [PATCH] coresight: etm4x: work around clang-12+ build failure
Date: Thu, 25 Feb 2021 23:04:19 +0100	[thread overview]
Message-ID: <CAK8P3a2XD7yA7s4d1t1Ogy0vnX-YGYRaHkY9Civ0H4Z9VJ22Tw@mail.gmail.com> (raw)
In-Reply-To: <CAKwvOdm_yh6gw_ecjeKgepRb12Q69Wk64x7xj=L2CDjBekiioA@mail.gmail.com>

On Thu, Feb 25, 2021 at 10:23 PM 'Nick Desaulniers' via Clang Built
Linux <clang-built-linux@googlegroups.com> wrote:
>
> On Thu, Feb 25, 2021 at 8:45 AM Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > Good morning,
> >
> > On Thu, Feb 25, 2021 at 10:42:58AM +0100, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <arnd@arndb.de>
> > >
> > > clang-12 fails to build the etm4x driver with -fsanitize=array-bounds:
>
> Is a sanitizer enabled, that would trap on OOB?
>
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1310

As described over there, this happens only with the array-bounds
sanitizer.

Actually, looking at it again now, in the reduced test case, the inline
assembly is not even parsable, it only works because it never gets
emitted without  -fsanitize=array-bounds, and the alternative
code path is used in

#define read_etm4x_sysreg_offset(offset, _64bit)
         \
        ({
         \
                u64 __val;
         \

         \
                if (__builtin_constant_p((offset)))
         \
                        __val =
read_etm4x_sysreg_const_offset((offset));       \
                else
         \
                        __val = etm4x_sysreg_read((offset), true,
(_64bit));    \
                __val;
         \
         })

read_etm4x_sysreg_const_offset() eventually turns into something
like

asm("msr_s " __stringify(offset));

so the offset has to be something that can be parsed by the
assembler. __builtin_constant_p() checks that it is a constant
value at compile-time, and in this case it can be because there
is a small upper bound and clang just unrolls the loop.

I don't think there is an alternative to __builtin_constant_p()
that can be used to decide if the argument is something that
can be used as a constant expression in an inline assembly.

            Arnd

WARNING: multiple messages have this Message-ID (diff)
From: Arnd Bergmann <arnd@kernel.org>
To: Nick Desaulniers <ndesaulniers@google.com>
Cc: Sai Prakash Ranjan <saiprakash.ranjan@codeaurora.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	coresight@lists.linaro.org, LKML <linux-kernel@vger.kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	Bill Wendling <morbo@google.com>, Leo Yan <leo.yan@linaro.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	Mike Leach <mike.leach@linaro.org>
Subject: Re: [PATCH] coresight: etm4x: work around clang-12+ build failure
Date: Thu, 25 Feb 2021 23:04:19 +0100	[thread overview]
Message-ID: <CAK8P3a2XD7yA7s4d1t1Ogy0vnX-YGYRaHkY9Civ0H4Z9VJ22Tw@mail.gmail.com> (raw)
In-Reply-To: <CAKwvOdm_yh6gw_ecjeKgepRb12Q69Wk64x7xj=L2CDjBekiioA@mail.gmail.com>

On Thu, Feb 25, 2021 at 10:23 PM 'Nick Desaulniers' via Clang Built
Linux <clang-built-linux@googlegroups.com> wrote:
>
> On Thu, Feb 25, 2021 at 8:45 AM Mathieu Poirier
> <mathieu.poirier@linaro.org> wrote:
> >
> > Good morning,
> >
> > On Thu, Feb 25, 2021 at 10:42:58AM +0100, Arnd Bergmann wrote:
> > > From: Arnd Bergmann <arnd@arndb.de>
> > >
> > > clang-12 fails to build the etm4x driver with -fsanitize=array-bounds:
>
> Is a sanitizer enabled, that would trap on OOB?
>
> > >
> > > Link: https://github.com/ClangBuiltLinux/linux/issues/1310

As described over there, this happens only with the array-bounds
sanitizer.

Actually, looking at it again now, in the reduced test case, the inline
assembly is not even parsable, it only works because it never gets
emitted without  -fsanitize=array-bounds, and the alternative
code path is used in

#define read_etm4x_sysreg_offset(offset, _64bit)
         \
        ({
         \
                u64 __val;
         \

         \
                if (__builtin_constant_p((offset)))
         \
                        __val =
read_etm4x_sysreg_const_offset((offset));       \
                else
         \
                        __val = etm4x_sysreg_read((offset), true,
(_64bit));    \
                __val;
         \
         })

read_etm4x_sysreg_const_offset() eventually turns into something
like

asm("msr_s " __stringify(offset));

so the offset has to be something that can be parsed by the
assembler. __builtin_constant_p() checks that it is a constant
value at compile-time, and in this case it can be because there
is a small upper bound and clang just unrolls the loop.

I don't think there is an alternative to __builtin_constant_p()
that can be used to decide if the argument is something that
can be used as a constant expression in an inline assembly.

            Arnd

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-02-25 22:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-25  9:42 [PATCH] coresight: etm4x: work around clang-12+ build failure Arnd Bergmann
2021-02-25  9:42 ` Arnd Bergmann
2021-02-25 16:45 ` Mathieu Poirier
2021-02-25 16:45   ` Mathieu Poirier
2021-02-25 20:08   ` Arnd Bergmann
2021-02-25 20:08     ` Arnd Bergmann
2021-02-25 21:23   ` Nick Desaulniers
2021-02-25 21:23     ` Nick Desaulniers
2021-02-25 22:04     ` Arnd Bergmann [this message]
2021-02-25 22:04       ` Arnd Bergmann
2021-02-25 17:20 ` Suzuki K Poulose
2021-02-25 17:20   ` Suzuki K Poulose

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAK8P3a2XD7yA7s4d1t1Ogy0vnX-YGYRaHkY9Civ0H4Z9VJ22Tw@mail.gmail.com \
    --to=arnd@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=arnd@arndb.de \
    --cc=clang-built-linux@googlegroups.com \
    --cc=coresight@lists.linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=saiprakash.ranjan@codeaurora.org \
    --cc=suzuki.poulose@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.