[llvmlinux] Compilling kernel Problem: value '65536' out of range for constraint 'I' -II

yaojun jyao224 at qq.com
Wed Mar 16 07:19:23 UTC 2016


> I try to compile android kernel on arm64.
> I am getting weird errors while cross compiling android kernel.
> The problem is:
> /arch/arm64/include/asm/spinlock.h:61:28: error: value '65536' out of range
> for constraint 'I' : "Q" (lock->owner), "I" (1 << TICKET_SHIFT)
> My context:
> firstly, I compiled nexus4 kernel successfully by using Automated build
> framework. Then I try to patch nexus5X(git branch:
> android-msm-bullhead-3.10-marshmallow-mr1) by using aarch64 patches.
> secondly, I try to use two different cross toolchain:
> gcc-linaro-5.2-2015.11-1x64_64_aarch64-linux-gnu AND
> aarch64-linux-android-4.9.  All failed.


I wrote this problem at Mon Mar 7 07:12:12 UTC 2016.
I am trying to deal with this problem, but I have no idea.
I write a test code :
             typedef struct {
               uint16_t owner;
               uint16_t next;
             } __attribute__((aligned(4))) arch_spinlock_t;


             int arch_spin_trylock(arch_spinlock_t *lock) {
               unsigned int tmp;
               arch_spinlock_t lockval;


               asm volatile(
                   "1:     ldaxr   %w0, %2\n"
                   "       eor     %w1, %w0, %w0, ror #16\n"
                   "       cbnz    %w1, 2f\n"
                   "       add     %w0, %w0, %3\n"
                   "       stxr    %w1, %w0, %2\n"
                   "       cbnz    %w1, 1b\n"
                   "2:"
                   : "=&r"(lockval), "=&r"(tmp), "+Q"(*lock)
                   : "I"(1 << 16)
                   : "memory");


               return !tmp;
             }

and compile it :
$ clang -target arm64-linux-gnu constraint_i_test.c -v
The output shows:
  clang version 3.9.0 (http://llvm.org/git/clang.git ef1d726359c15e390de5086e9f381e80076b7a45) (http://llvm.org/git/llvm.git f7ae2f50a069857526c2e49dda039ed47746f130)
  Target: arm64--linux-gnu
  Thread model: posix
  InstalledDir: /usr/local/bin
  Found candidate GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/4.8
  Found candidate GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/4.8.4
  Selected GCC installation: /usr/lib/gcc-cross/aarch64-linux-gnu/4.8
  Candidate multilib: .;@m64
  Selected multilib: .;@m64
   "/usr/local/bin/clang-3.9" -cc1 -triple arm64--linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name constraint_i_test.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu generic -target-feature +neon -target-abi aapcs -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/local/bin/../lib/clang/3.9.0 -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.9.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/yaojun -ferror-limit 19 -fmessage-length 205 -fallow-half-arguments-and-returns -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/constraint_i_test-0be913.o -x c constraint_i_test.c
  clang -cc1 version 3.9.0 based upon LLVM 3.9.0svn default target x86_64-unknown-linux-gnu
  ignoring nonexistent directory "/include"
  #include "..." search starts here:
  #include <...> search starts here:
   /usr/local/include
   /usr/local/bin/../lib/clang/3.9.0/include
   /usr/include
  End of search list.
   "/usr/lib/gcc-cross/aarch64-linux-gnu/4.8/../../../../aarch64-linux-gnu/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m aarch64linux -dynamic-linker /lib/ld-linux-aarch64.so.1 -o a.out /usr/lib/gcc-cross/aarch64-linux-gnu/4.8/../../../../aarch64-linux-gnu/lib/crt1.o /usr/lib/gcc-cross/aarch64-linux-gnu/4.8/../../../../aarch64-linux-gnu/lib/crti.o /usr/lib/gcc-cross/aarch64-linux-gnu/4.8/crtbegin.o -L/usr/lib/gcc-cross/aarch64-linux-gnu/4.8 -L/lib/../lib64 -L/usr/lib/gcc-cross/aarch64-linux-gnu/4.8/../../../../aarch64-linux-gnu/lib -L/usr/lib/gcc-cross/aarch64-linux-gnu/4.8/../../.. -L/usr/local/bin/../lib -L/lib -L/usr/lib /tmp/constraint_i_test-0be913.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc-cross/aarch64-linux-gnu/4.8/crtend.o /usr/lib/gcc-cross/aarch64-linux-gnu/4.8/../../../../aarch64-linux-gnu/lib/crtn.o

It works well.


Then I download LLVMLinux kernel tree, and compile it :
$ make ARCH=arm64 GCC_TOOLCHAIN=/usr/aarch64-linux-gnu/bin/ HSOTCC=clang CC=clang menuconfig
$ make ARCH=arm64 GCC_TOOLCHAIN=/usr/aarch64-linux-gnu/bin/ HSOTCC=clang CC=clang
It shows:
  In file included from arch/arm64/kernel/asm-offsets.c:21:
  In file included from include/linux/sched.h:19:
  In file included from include/linux/timex.h:56:
  In file included from include/uapi/linux/timex.h:56:
  In file included from include/linux/time.h:5:
  In file included from include/linux/seqlock.h:35:
  In file included from include/linux/spinlock.h:87:
  ./arch/arm64/include/asm/spinlock.h:61:28: error: value '65536' out of range for constraint 'I'
          : "Q" (lock->owner), "I" (1 << TICKET_SHIFT)
                                               ^~~~~~~~~~~~~~~~~
  ./arch/arm64/include/asm/spinlock.h:80:9: error: value '65536' out of range for constraint 'I'
          : "I" (1 << TICKET_SHIFT)
                  ^~~~~~~~~~~~~~~~~

When I compile Android kernel by using gcc-linaro-aarch64-linux-gnu-4.9-2014.08_linux cross toolchain, It shows the same information.
I use automated build framework.
The command info is:
  I: Building kernel with clang...
  (cd /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X &&  time  make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-      GCC_TOOLCHAIN=/home/yaojun/llvm-target/nexus5X/llvmlinux/arch/aarch64/toolchain/linaro/gcc-linaro-aarch64-linux-gnu-4.9-2014.08_linux -l8 -j9 CONFIG_DEBUG_INFO=1  CONFIG_DEBUG_SECTION_MISMATCH=y CONFIG_NO_ERROR_ON_MISMATCH=y  KBUILD_OUTPUT=/home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/build/kernel-clang  HOSTCC="clang" CC="clang "   )

 clang  -Wp,-MD,arch/arm64/kernel/.asm-offsets.s.d  -nostdinc -isystem /usr/local/bin/../lib/clang/3.9.0/include -I/home/yaojun/llvm-  target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/include -Iarch/arm64/include/generated  -I/home/yaojun/llvm-  target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include -Iinclude -I/home/yaojun/llvm-  target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I/home/yaojun/llvm-  target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/uapi -Iinclude/generated/uapi -include /home/yaojun/llvm-  target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/kconfig.h  -I/home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/. -I. -D__KERNEL__ -no-integrated-as -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -Oz -Wno-maybe-uninitialized -mgeneral-regs-only -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-tautological-compare -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -Wno-pointer-sign    -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(asm_offsets)"  -D"KBUILD_MODNAME=KBUILD_STR(asm_offsets)" -fverbose-asm -S -o arch/arm64/kernel/asm-offsets.s /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/kernel/asm-offsets.c
 clang-3.9: warning: argument unused during compilation: '-mgeneral-regs-only'
 warning: unknown warning option '-Wno-maybe-uninitialized'; did you mean '-Wno-uninitialized'? [-Wunknown-warning-option]
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/kernel/asm-offsets.c:21:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/sched.h:17:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/timex.h:56:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/uapi/linux/timex.h:56:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/time.h:5:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/seqlock.h:29:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/spinlock.h:50:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/preempt.h:9:
 In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/thread_info.h:54:
 /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/include/asm/thread_info.h:79:32: warning: variable 'sp' is uninitialized when used here [-Wuninitialized]
        return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
                                                  ^~
/home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/include/asm/thread_info.h:78:27: note: initialize the variable 'sp' to silence this warning
        register unsigned long sp asm ("sp");
                                                      ^
                                                      = 0
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/kernel/asm-offsets.c:21:
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/sched.h:17:
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/timex.h:56:
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/uapi/linux/timex.h:56:
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/time.h:5:
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/seqlock.h:29:
In file included from /home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/include/linux/spinlock.h:87:
/home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/include/asm/spinlock.h:61:28: error: value '65536' out of range for constraint 'I'
        : "Q" (lock->owner), "I" (1 << TICKET_SHIFT)
                                            ^~~~~~~~~~~~~~~~~
/home/yaojun/llvm-target/nexus5X/llvmlinux/targets/nexus5X/src/android_kernel_nexus5X/arch/arm64/include/asm/spinlock.h:79:9: error: value '65536' out of range for constraint 'I'
        : "I" (1 << TICKET_SHIFT)
                ^~~~~~~~~~~~~~~~~



I believe that there are something wrong with cross toolchain.
I compile Android kernel (android-msm-bullhead-3.10-marshmallow-mr1) by gcc and official cross toolchain. Done.
Then I compile it again by using clang and official cross toolchain, it failed.  
I guess I don't give the compiler option correctly. Does it right?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfoundation.org/pipermail/llvmlinux/attachments/20160316/8be007f7/attachment-0001.html>


More information about the LLVMLinux mailing list