1. 19 Jan, 2015 40 commits
    • Without this, a 'break' instruction is executed very early in the boot and
      the boot hangs.
      
      The problem is that clang doesn't honour named registers on local variables
      and silently treats them as normal uninitialized variables. However, it
      does honour them on global variables.
      
      Signed-off-by: Daniel Sanders <daniel.sanders@imgtec.com>
      Daniel Sanders committed
    • Differentiate the 'u' GAS .macro argument from the '\u' C preprocessor unicode
      escape sequence by renaming it to '_u'.
      
      When the 'u' argument is evaluated, we end up writing '\u', which causes
      clang to emit -Wunicode warnings.
      
      This silences a couple of -Wunicode warnings reported by clang.
      The changed code can be preprocessed without warnings by both gcc and clang.
      
      Signed-off-by: Toma Tabacu <toma.tabacu@imgtec.com>
      Toma Tabacu committed
    • Replace variable self-assignments with explanatory comments.
      
      This silences a bunch of -Wself-assign warnings reported by clang.
      The changed code can be compiled without warnings by both gcc and clang.
      
      Signed-off-by: Toma Tabacu <toma.tabacu@imgtec.com>
      Toma Tabacu committed
    • Change the type of csum_ipv6_magic's 'proto' argument from unsigned short to
      __u32.
      
      This fixes a type mismatch between the 'htonl(proto)' inline asm input, which
      is __u32, and the 'proto' output, which is unsigned short.
      
      This error gets reported by clang, but not by gcc.
      The changed code can be compiled successfully by both gcc and clang.
      
      Signed-off-by: Toma Tabacu <toma.tabacu@imgtec.com>
      Toma Tabacu committed
    • Replace a 16-bit unsigned int member bitfield with an unsigned short member
      variable in the 'mips16e_instruction' union.
      
      This follows the example set by the 'mips_instruction' union, which doesn't use
      bitfields for its generic union members.
      
      This error gets reported by clang, but not by gcc.
      The changed code can be compiled successfully by both gcc and clang.
      
      Signed-off-by: Toma Tabacu <toma.tabacu@imgtec.com>
      Toma Tabacu committed
    • Fix for prfm error on AArch64
      
      The following error is generated with the mainline clang compiler
      for AArch64:
      
      arch/arm64/include/asm/processor.h:149:15:
      error: invalid operand in inline asm: 'prfm pldl1keep, ${0:a}
      '
      
      Per comments by Tim Northover on the LLVM Bug database:
      
      "It's rather unclear how it's better than "prfm pstl1keep, [%0]" though.
      Not all instructions can make use of any offset, so wouldn't we have to be
      conservative and always map it to "[xN]"?
      
      When %a0 is changed to [%x0] it uncovered a GCC bug:
      https://bugs.linaro.org/show_bug.cgi?id=635
      
      Changing the "p" to "r" resolves the issue for both clang and GCC.
      
      Signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Mark Charlebois committed
    • Clang does not implicitly pass the -march flag to the assembler, but gcc does.
      
      Clang must be explicitly told to pass the flag to the assembler.
      Without the flag set the GNU assember reports the following error:
      
      /llvmlinux/build/targets/vexpress64/tmp/aes-ce-cipher-5b96de.s: Assembler messages:
      /llvmlinux/build/targets/vexpress64/tmp/aes-ce-cipher-5b96de.s:210: Error: selected processor does not support `aese v0.16b,v2.16b'
      /llvmlinux/build/targets/vexpress64/tmp/aes-ce-cipher-5b96de.s:210: Error: selected processor does not support `aesmc v0.16b,v0.16b'
      /llvmlinux/build/targets/vexpress64/tmp/aes-ce-cipher-5b96de.s:210: Error: selected processor does not support `aese v0.16b,v3.16b'
      ...
      clang-3.5: error: assembler command failed with exit code 1 (use -v to see invocation)
      make[3]: *** [arch/arm64/crypto/aes-ce-cipher.o] Error 1
      make[2]: *** [arch/arm64/crypto] Error 2
      
      The change was also tested with GCC. GCC requires the flag to be
      passed without -Xassembler. Both GCC and Clang work when -Wa is used.
      
      Not-signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Mark Charlebois committed
    • futex_init passes in uaddr = 0. The LLVM optimizer will see
      that *uaddr is 0, set the register to xzr and compilation
      will fail.
      
      Signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Not-signed-off-by: Behan Webster <behanw@converseincode.com>
      Mark Charlebois committed
    • Force register assignment for variables used in Extended Asm. The two functions
      were expecting and checking for GCC specific behavior in register allocation.
      
      By defining a local register variable:
      
        void foo(int arg0) {
          register int arg0_in_r0 asm ("r0") = arg0;
      
          // extended asm
          ...
        }
      
      It is possible to guarantee that 'arg0' will be placed in 'r0' and avoid
      checking for correct register assignment with 'asmeq'. The asm code generated
      is the same with -O2 except for the checks that are not needed.
      
      Not-signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
      Vinícius Tinti committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • As documented in GCC naked functions should only use Basic asm syntax. The
      Extended asm or mixture of Basic asm and "C" code is not guarantee. Currently
      this works because it was hard coded to follow and check GCC behavior for
      arguments and register placement.
      
      By replacing the naked function with an inline one it is possible to have the
      same result in a more portable and reliable way. Register placement checks
      are not needed since there is no hard code.
      
      Not-signed-off-by: Behan Webster <behanw@converseincode.com>
      Not-signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
      Behan Webster committed
    • Not-signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      behanw@converseincode.comBehan committed
    • My GCC-based build environment likes to call register r12 by the
      name "ip" in inline asm.  Behan Webster informed me that his Clang-
      based build environment likes "r12" instead.
      
      Try to make them both happy.
      
      Signed-off-by: Alex Elder <elder@linaro.org>
      Reviewed-by: Behan Webster <behanw@converseincode.com>
      Alex Elder committed
    • Define a global named register for current_stack_pointer. The use of this new
      variable guarantees that both gcc and clang can access this register in C code.
      
      KernelVersion: 3.17.0-rc6
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
      Reviewed-by: Mark Charlebois <charlebm@gmail.com>
      Acked-by: Will Deacon <will.deacon@arm.com>
      Acked-by: Nicolas Pitre <nico@linaro.org>
      Behan Webster committed
    • Protect more options for arm with cc-option so that we don't get errors when
      using clang instead of gcc.  Add more or different options when using clang as
      well.
      
      KernelVersion:
      Author: Behan Webster <behanw@converseincode.com>
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Reviewed-by: Mark Charlebois <charlebm@gmail.com>
      Behan Webster committed
    • These symbols are required when compiling the Linux kernel for arch ARM with
      clang.
      
      KernelVersion:
      Author: Mark Charlebois <charlebm@gmail.com>
      Signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Not-signed-off-by: Behan Webster <behanw@converseincode.com>
      Behan Webster committed
    • Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
      Vinícius Tinti committed
    • Clang's intrinsics ignore -mregparm=3 when they fall back to calling the
      out-of-line implementations. Putting the args on the stack when memcpy()
      expects them in registers is not a recipe for a happy kernel.
      
      This bites with -m32 too, so clang is presumably catastrophically
      broken for the i386 kernel until this is fixed, unless I'm missing
      something.
      
      For information/testing only; do not apply. With this, I can use
      'clang -m16' to build all the kernel's 16-bit code and get a successful
      boot.
      
      Not-signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
      Forward-ported-by: Jan-Simon Möller <dl9pf@gmx.de>
      Jan-Simon Möller committed
    • Along with gcc >= 4.3, clang also needs memcpy exported.
      
      Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>
      Reviewed-by: Behan Webster <behanw@converseincode.com>
      Cc: PaX Team <pageexec@freemail.hu>
      Jan-Simon Möller committed
    • Ignore the flags set in Kconfig for hweight if the compiler is clang.
      
      This is also reported as LLVM PR9457
      
      Author: Behan Webster <behanw@converseincode.com>
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Behan Webster committed
    • There are currently two ways to generate indices into kmalloc_caches
      (via kmalloc_index() and via the size_index table in slab_common.c) and on some
      arches (possibly only MIPS) they disagree with each other until
      create_kmalloc_caches() has been called. This patch moves the initialization
      of the size_index array slightly earlier so that the first few kmem_cache_node's
      can be safely allocated.
      
      The failing sequence was:
      * kmalloc_caches contains NULL elements
      * kmem_cache_init initialises the element that 'struct kmem_cache_node' will be
        allocated to. For 32-bit Mips, this is a 56-byte struct and kmalloc_index
        returns KMALLOC_SHIFT_LOW (7).
      * init_list is called which calls kmalloc_node to allocate a 'struct
        kmem_cache_node'.
      * kmalloc_slab selects the kmem_caches element using
        size_index[size_index_elem(size)]. For MIPS, size is 56, and the expression
        returns 6.
      * This element of kmalloc_caches is NULL and allocation fails.
      * If it had not already failed, it would have called create_kmalloc_caches()
        at this point which would have changed size_index[size_index_elem(size)] to 7.
      
      Signed-off-by: Daniel Sanders <daniel.sanders@imgtec.com>
      Daniel Sanders committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Behan Webster committed
    • This generates smaller resulting object code when compiled with clang.
      
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Convert Variable Length Array in Struct (VLAIS) to valid C by converting
      local struct definition to use a flexible array. The structure is only
      used to define a cast of a buffer so the size of the struct is not used
      to allocate storage.
      
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Signed-off-by: Mark Charebois <charlebm@gmail.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Replaced the use of a Variable Length Array In Struct (VLAIS) with a C99
      compliant equivalent.  This patch instead allocates the appropriate amount of
      memory using a char array using the SHASH_DESC_ON_STACK macro.
      
      The new code can be compiled with both gcc and clang.
      
      Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
      Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
      Reviewed-by: Mark Charlebois <charlebm@gmail.com>
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Acked-by: John Johansen <john.johansen@canonical.com>
      Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
      Vinícius Tinti committed
    • Not-signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Reviewed-by: Mark Charlebois <charlebm@gmail.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Replace the use of nested functions where a normal function will suffice.
      
      Nested functions are not liked by upstream kernel developers in general. Their
      use breaks the use of clang as a compiler, and doesn't make the code any
      better.
      
      This code now works for both gcc and clang.
      
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Reviewed-by: Mark Charlebois <charlebm@gmail.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • [MC] Do we need both -fheinous-gnu-extensions and the cast fix?
      
      The cast inside the inline ASM is not supported by clang. It is
      in fact ignored by GCC.
      
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Not-signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Signed-off-by: Behan Webster <behanw@converseincode.com>
      Suggested-by: Arnd Bergmann <arnd@arndb.de>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Clang will warn about unknown warnings but will not return false
      unless -Werror is set. GCC will return false if an unknown
      warning is passed.
      
      Adding -Werror make both compiler behave the same.
      
      Signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
      Mark Charlebois committed
    • When using clang with -no-integerated-as clang will use the gnu assembler instead
      of the integrated assembler. However clang will still perform asm error checking
      before sending the inline assembly language to gas.
      
      The generation of asm-offsets from within C code is dependent on gcc's blind
      passing of whatever is in asm() through to gas. Arbirary text is
      passed through which is then modified by a sed script into the appropriate .h
      and .S code. Since the arbitrary text is not valid assembly language, clang fails.
      
      This can be fixed by making the arbitrary text into an ASM comment and then
      updating the sed scripts accordingly to work as expected.
      
      This solution works for both gcc and clang.
      
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Reviewed-by: Mark Charlebois <charlebm@gmail.com>
      Reviewed-by: Jan-Simon Möller <dl9pf@gmx.de>
      Cc: Jan Moskyto Matejka <mq@suse.cz>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
      Cc: "H. Peter Anvin" <hpa@linux.intel.com>
      Cc: Tom Gundersen <teg@jklm.no>
      Cc: Masahiro Yamada <yamada.m@jp.panasonic.com>
      Cc: Arnd Bergmann <arnd@arndb.de>
      Behan Webster committed
    • Change default compiler options when using clang
      
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Behan Webster committed
    • Add rules to kbuild in order to generate LLVM bitcode files with the .ll
      extension when using clang.
      
        # from c code
        CC=clang make kernel/pid.ll
      
        # from asm code
        CC=clang make arch/x86/kernel/preempt.ll
      
      Signed-off-by: Vinícius Tinti <viniciustinti@gmail.com>
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Vinícius Tinti committed
    • cmd in COMPATIBLE_IOCTL is always a u32, so cast it so there isn't a warning
      about an overflow in XFORM.
      
      Signed-off-by: Mark Charlebois <charlebm@gmail.com>
      Signed-off-by: Behan Webster <behanw@converseincode.com>
      Acked-by: Arnd Bergmann <arnd@arndb.de>
      Mark Charlebois committed