Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISCV assembler error (illegal operands auipc) compiling arch/riscv/kernel/vdso/vgettimeofday.c #1112

Closed
tklauser opened this issue Jul 29, 2020 · 5 comments

Comments

@tklauser
Copy link
Member

@tklauser tklauser commented Jul 29, 2020

On linux-next (next-20200728):

make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- CC=clang-11 V=1 LD=riscv64-linux-gnu-ld
[...]
  clang-11 -Wp,-MMD,arch/riscv/kernel/vdso/.vgettimeofday.o.d  -nostdinc -isystem /usr/lib/llvm-11/lib/clang/11.0.0/include -I./arch/riscv/include -I./arch/riscv/include/generated  -I./include -I./arch/riscv/include/uapi -I./arch/riscv/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -Qunused-arguments -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Wno-format-security -std=gnu89 --target=riscv64-linux-gnu --prefix=/usr/bin/ --gcc-toolchain=/usr -no-integrated-as -Werror=unknown-warning-option -mabi=lp64 -march=rv64imac -mno-save-restore -DCONFIG_PAGE_OFFSET=0xffffffe000000000 -mcmodel=medany -fno-omit-frame-pointer -fno-delete-null-pointer-checks -Wno-frame-address -Wno-address-of-packed-member -O2 -Wframe-larger-than=2048 -fstack-protector-strong -Wno-format-invalid-specifier -Wno-gnu -mno-global-merge -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -ftrivial-auto-var-init=pattern -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-array-bounds -fno-strict-overflow -fno-merge-all-constants -fno-stack-check -Werror=date-time -Werror=incompatible-pointer-types -fmacro-prefix-map=./= -Wno-initializer-overrides -Wno-format -Wno-sign-compare -Wno-format-zero-length -Wno-pointer-to-enum-cast -Wno-tautological-constant-out-of-range-compare -fPIC -include /home/tklauser/src/linux/lib/vdso/gettimeofday.c   -fsanitize=kernel-address      -DKBUILD_MODFILE='"arch/riscv/kernel/vdso/vgettimeofday"' -DKBUILD_BASENAME='"vgettimeofday"' -DKBUILD_MODNAME='"vgettimeofday"' -c -o arch/riscv/kernel/vdso/vgettimeofday.o arch/riscv/kernel/vdso/vgettimeofday.c
/tmp/vgettimeofday-1ae0d2.s: Assembler messages:
/tmp/vgettimeofday-1ae0d2.s:28: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:28: Error: illegal operands `auipc a2,%got_pcrel_hi(__stack_chk_guard)'
/tmp/vgettimeofday-1ae0d2.s:44: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:44: Error: illegal operands `auipc a2,%got_pcrel_hi(__vdso_clock_gettime)'
/tmp/vgettimeofday-1ae0d2.s:371: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:371: Error: illegal operands `auipc a1,%got_pcrel_hi(__stack_chk_guard)'
/tmp/vgettimeofday-1ae0d2.s:556: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:556: Error: illegal operands `auipc a2,%got_pcrel_hi(__stack_chk_guard)'
/tmp/vgettimeofday-1ae0d2.s:571: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:571: Error: illegal operands `auipc a1,%got_pcrel_hi(__vdso_gettimeofday)'
/tmp/vgettimeofday-1ae0d2.s:879: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:879: Error: illegal operands `auipc a1,%got_pcrel_hi(__stack_chk_guard)'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)
make[3]: *** [scripts/Makefile.build:281: arch/riscv/kernel/vdso/vgettimeofday.o] Error 1
make[2]: *** [scripts/Makefile.build:497: arch/riscv/kernel/vdso] Error 2
make[1]: *** [scripts/Makefile.build:497: arch/riscv/kernel] Error 2
make: *** [Makefile:1756: arch/riscv] Error 2

@tklauser tklauser changed the title RISCV assembler issues (illegal operands auipc) compiling arch/riscv/kernel/vdso/vgettimeofday.c RISCV assembler error (illegal operands auipc) compiling arch/riscv/kernel/vdso/vgettimeofday.c Jul 29, 2020
@tklauser
Copy link
Member Author

@tklauser tklauser commented Jul 29, 2020

/tmp/vgettimeofday-1ae0d2.s:28: Error: bad expression
/tmp/vgettimeofday-1ae0d2.s:28: Error: illegal operands `auipc a2,%got_pcrel_hi(__stack_chk_guard)'

These are caused by missing -fno-stack-protector when building vDSO, addressed by https://lore.kernel.org/linux-riscv/20200729075129.11538-1-tklauser@distanz.ch/T/#u

Still looking into the ones regarding __vdso_clock_gettime and __vdso_gettimeofday.

@nickdesaulniers
Copy link
Member

@nickdesaulniers nickdesaulniers commented Jul 29, 2020

It looks like you're doing a non-IAS build; our CI coverage is doing make LLVM=1 LLVM_IAS=1 builds for RISCV, so I'm not surprised that clang may be emitting assembler that's not valid for GNU as. -fstack-protector is also causing issues recently in #1092 . I'm not sure turning off the stack protector is the ultimate fix (sounds like we should fix Clang) rather than a workaround. Please use scripts/get_maintainer.pl when sending patches in order to cc our mailing list (clang-built-linux@googlegroups.com).

@tklauser
Copy link
Member Author

@tklauser tklauser commented Jul 30, 2020

It looks like you're doing a non-IAS build; our CI coverage is doing make LLVM=1 LLVM_IAS=1 builds for RISCV, so I'm not surprised that clang may be emitting assembler that's not valid for GNU as. -fstack-protector is also causing issues recently in #1092 . I'm not sure turning off the stack protector is the ultimate fix (sounds like we should fix Clang) rather than a workaround.

Thanks for the info, with LLVM_IAS it works indeed. I was assuming we might need to disable the stack protector for the vDSO since this seems to be what other archs do.

Please use scripts/get_maintainer.pl when sending patches in order to cc our mailing list (clang-built-linux@googlegroups.com).

Will do, thanks.

ruscur pushed a commit to ruscur/linux that referenced this issue Aug 3, 2020
Currently, building the vDSO with clang leads assembler errors like the
following:

  /tmp/vgettimeofday-1ae0d2.s: Assembler messages:
  /tmp/vgettimeofday-1ae0d2.s:28: Error: bad expression
  /tmp/vgettimeofday-1ae0d2.s:28: Error: illegal operands `auipc a2,%got_pcrel_hi(__stack_chk_guard)'

Disable the stack-protector for vDSO to fix these.

Link: ClangBuiltLinux#1112
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
ruscur pushed a commit to ruscur/linux that referenced this issue Aug 5, 2020
Currently, building the vDSO with clang leads assembler errors like the
following:

  /tmp/vgettimeofday-1ae0d2.s: Assembler messages:
  /tmp/vgettimeofday-1ae0d2.s:28: Error: bad expression
  /tmp/vgettimeofday-1ae0d2.s:28: Error: illegal operands `auipc a2,%got_pcrel_hi(__stack_chk_guard)'

Disable the stack-protector for vDSO to fix these.

Link: ClangBuiltLinux#1112
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
esmil added a commit to esmil/linux that referenced this issue Aug 15, 2020
Currently, building the vDSO with clang leads assembler errors like the
following:

  /tmp/vgettimeofday-1ae0d2.s: Assembler messages:
  /tmp/vgettimeofday-1ae0d2.s:28: Error: bad expression
  /tmp/vgettimeofday-1ae0d2.s:28: Error: illegal operands `auipc a2,%got_pcrel_hi(__stack_chk_guard)'

Disable the stack-protector for vDSO to fix these.

Link: ClangBuiltLinux#1112
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
@nathanchance
Copy link
Member

@nathanchance nathanchance commented Aug 26, 2020

Looks like our mailing list was never CC'd on that patch: https://lore.kernel.org/linux-riscv/20200729075129.11538-1-tklauser@distanz.ch/

It has been merged into mainline: https://git.kernel.org/linus/40284a072c42f6177184fb1f62ba94c69e0c0277

As it turns out, that patch fixes #1092. This appears normal for the vDSO based on arm, arm64, and x86 so I would not consider this a bug in clang or anything.

@tklauser
Copy link
Member Author

@tklauser tklauser commented Aug 26, 2020

Thank you @nathanchance and sorry about not Cc'ing the mailing list on the patch. Will make sure to do so for any future patches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants