lkml.org 
[lkml]   [2019]   [Jul]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH] mips: avoid explicit UB in assignment of mips_io_port_base
    On Mon, Jul 29, 2019 at 02:10:12PM -0700, Nick Desaulniers wrote:
    > The code in question is modifying a variable declared const through
    > pointer manipulation. Such code is explicitly undefined behavior, and
    > is the lone issue preventing malta_defconfig from booting when built
    > with Clang:
    >
    > If an attempt is made to modify an object defined with a const-qualified
    > type through use of an lvalue with non-const-qualified type, the
    > behavior is undefined.
    >
    > LLVM is removing such assignments. A simple fix is to not declare
    > variables const that you plan on modifying. Limiting the scope would be
    > a better method of preventing unwanted writes to such a variable.
    >
    > Further, the code in question mentions "compiler bugs" without any links
    > to bug reports, so it is difficult to know if the issue is resolved in
    > GCC. The patch was authored in 2006, which would have been GCC 4.0.3 or
    > 4.1.1. The minimal supported version of GCC in the Linux kernel is
    > currently 4.6.
    >
    > For what its worth, there was UB before the commit in question, it just
    > added a barrier and got lucky IRT codegen. I don't think there's any
    > actual compiler bugs related, just runtime bugs due to UB.
    >
    > Link: https://github.com/ClangBuiltLinux/linux/issues/610
    > Fixes: 966f4406d903 ("[MIPS] Work around bad code generation for <asm/io.h>.")
    > Reported-by: Nathan Chancellor <natechancellor@gmail.com>
    > Debugged-by: Nathan Chancellor <natechancellor@gmail.com>
    > Suggested-by: Eli Friedman <efriedma@quicinc.com>
    > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

    Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>
    Tested-by: Nathan Chancellor <natechancellor@gmail.com>

    \
     
     \ /
      Last update: 2019-07-29 23:21    [W:2.305 / U:0.112 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site