LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 44853 - -mno-save-restore spams a RISCV Linux kernel build
Summary: -mno-save-restore spams a RISCV Linux kernel build
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: Driver (show other bugs)
Version: trunk
Hardware: Other All
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-09 01:12 PST by Nathan Chancellor
Modified: 2020-02-12 10:36 PST (History)
7 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Chancellor 2020-02-09 01:12:12 PST
When building the Linux kernel for RISCV, there is a bunch of warning spam around -mno-save-restore, which is explicitly specified in arch/riscv/Makefile.

$ make -j$(nproc) -s ARCH=riscv CC=clang-11 CROSS_COMPILE=riscv64-linux-gnu- O=out.riscv distclean defconfig all
...
'-save-restore' is not a recognized feature for this target (ignoring feature)                                                                      
'-save-restore' is not a recognized feature for this target (ignoring feature)                           
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
...

I assume this warning is coming from the backend since -msave-restore warns from clang.

$ echo | clang-11 --target=riscv64-linux-gnu -msave-restore -c -x c -o /dev/null -
clang: warning: the clang compiler does not support '-msave-restore'
'+save-restore' is not a recognized feature for this target (ignoring feature)
$ echo | clang-11 --target=riscv64-linux-gnu -mno-save-restore -c -x c -o /dev/null -
'-save-restore' is not a recognized feature for this target (ignoring feature)

This warning happens on every translation unit so it is very noisy. We could silence it by just not passing -mno-save-restore when building with clang but that seems fragile in case -msave-restore ever became default. We’ll do whatever you feel is best though.
Comment 1 Sam Elliott 2020-02-10 05:01:46 PST
Please can you tell me exactly which LLVM version (including git revision, if you're on master) you are using? 

HEAD, as of today (f2af4f8a45dbd0d1de950a64f1b4fbf618c70657) does not include any code to translate `-m{no-}save-restore` into target features, only a warning is emitted (https://github.com/llvm/llvm-project/blob/f2af4f8a45dbd0d1de950a64f1b4fbf618c70657/clang/lib/Driver/ToolChains/Arch/RISCV.cpp#L437-441)

Have you applied some patches of your own?
Comment 2 Nathan Chancellor 2020-02-10 14:44:25 PST
No, both the LLVM toolchain and Linux kernel are completely vanilla.

$ clang --version | head -n1
ClangBuiltLinux clang version 11.0.0 (git://github.com/llvm/llvm-project 8b81ebfe7eba089ed2016d523cc5ee9d05e957a7)

$ git describe --contains
v5.6-rc1^0

$ make -j$(nproc) -s ARCH=riscv CC=clang CROSS_COMPILE=riscv64-linux-gnu- O=out.riscv distclean defconfig init/main.o
...
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
'-save-restore' is not a recognized feature for this target (ignoring feature)
...

The full command from that translation unit, if it is relevant:

clang -Wp,-MD,init/.main.o.d  -nostdinc -isystem /home/nathan/cbl/git/tc-build/install/lib/clang/11.0.0/include -I../arch/riscv/include -I./arch/riscv/include/generated -I../include -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=/home/nathan/cbl/git/tc-build/install/bin/ --gcc-toolchain=/home/nathan/cbl/git/tc-build/install -no-integrated-as -Werror=unknown-warning-option -mabi=lp64 -march=rv64imac -mno-save-restore -DCONFIG_PAGE_OFFSET=0xffffffe000000000 -mcmodel=medany -fno-delete-null-pointer-checks -Wno-address-of-packed-member -O2 -Wframe-larger-than=2048 -fno-stack-protector -Wno-format-invalid-specifier -Wno-gnu -Wno-tautological-compare -mno-global-merge -Wno-unused-const-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -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 -fno-function-sections -fno-data-sections -I ../init -I ./init    -DKBUILD_MODFILE='"init/main"' -DKBUILD_BASENAME='"main"' -DKBUILD_MODNAME='"main"' -c -o init/main.o ../init/main.c
Comment 3 Sam Elliott 2020-02-12 09:41:33 PST
I cannot find "-save-restore" in any of the clang or llvm source code as of commit `8b81ebfe7eba089ed2016d523cc5ee9d05e957a7`, or any of the clangbuiltlinux source code either (it would be in `-mattr` or the like).

I think maybe this warning is coming from some cached `target-features` somewhere, in a LLVM IR file or the like.

The "save-restore" feature has only been parts of patches until today, I believe, so I don't think any mainline clang version has been generating code with the save-restore feature yet.

That said, `save-restore` has now landed, so maybe now these warnings will go away on HEAD? Do let me know how you get on on today's HEAD.
Comment 4 Nathan Chancellor 2020-02-12 10:36:12 PST
Yes, these warnings are gone with my version of clang at bc316c21570b3ff93a7e064a6fb2f6b56d26d850, I'll close this, thank you!