Message ID | 20240717-sparc-cflags-v2-1-259407e6eb5f@protonmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | sparc/build: Rework CFLAGS for clang compatibility | expand |
On Wed, Jul 17, 2024 at 11:10:15PM +0700, Koakuma wrote: > Remove all usage of -fcall-used* flags so that all flags used are > portable between GCC and clang. > > The reasoning is as follows: > > In the (normal) 32-bit ABI, %g5 and %g7 is normally reserved, and in > the 64-bit ABI, %g7 is the reserved one. > Linux turns them into volatile registers by the way of -fcall-used-*, > but on the other hand, omitting the flags shouldn't be harmful; > compilers will now simply refuse to touch them, and any assembly > code that happens to touch them would still work like usual (because > Linux' conventions already treats them as volatile anyway). > > Signed-off-by: Koakuma <koachan@protonmail.com> As before, I tested this series with the vDSO patch mentioned before and a version of LLVM that supports the -m{,no-}v8plus flags and I was able to successfully boot a kernel in QEMU :) Tested-by: Nathan Chancellor <nathan@kernel.org> > --- > arch/sparc/Makefile | 4 ++-- > arch/sparc/vdso/Makefile | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile > index 757451c3ea1d..7318a8b452c3 100644 > --- a/arch/sparc/Makefile > +++ b/arch/sparc/Makefile > @@ -29,7 +29,7 @@ UTS_MACHINE := sparc > # versions of gcc. Some gcc versions won't pass -Av8 to binutils when you > # give -mcpu=v8. This silently worked with older bintutils versions but > # does not any more. > -KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7 > +KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu > KBUILD_CFLAGS += -Wa,-Av8 > > KBUILD_AFLAGS += -m32 -Wa,-Av8 > @@ -45,7 +45,7 @@ export BITS := 64 > UTS_MACHINE := sparc64 > > KBUILD_CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow > -KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare > +KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -Wno-sign-compare > KBUILD_CFLAGS += -Wa,--undeclared-regs > KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3) > KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs > diff --git a/arch/sparc/vdso/Makefile b/arch/sparc/vdso/Makefile > index 243dbfc4609d..e009443145af 100644 > --- a/arch/sparc/vdso/Makefile > +++ b/arch/sparc/vdso/Makefile > @@ -46,7 +46,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 > -fno-omit-frame-pointer -foptimize-sibling-calls \ > -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO > > -SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7 > +SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 > > $(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) > > > -- > 2.45.2 >
Hi, Sorry for being silent on your two patch sets. I did not have time to look into them for 6.12. On 2024-07-17 18:10, Koakuma via B4 Relay wrote: > From: Koakuma <koachan@protonmail.com> > > Remove all usage of -fcall-used* flags so that all flags used are > portable between GCC and clang. > > The reasoning is as follows: > > In the (normal) 32-bit ABI, %g5 and %g7 is normally reserved, and in > the 64-bit ABI, %g7 is the reserved one. > Linux turns them into volatile registers by the way of -fcall-used-*, > but on the other hand, omitting the flags shouldn't be harmful; > compilers will now simply refuse to touch them, and any assembly > code that happens to touch them would still work like usual (because > Linux' conventions already treats them as volatile anyway). > > Signed-off-by: Koakuma <koachan@protonmail.com> > --- > arch/sparc/Makefile | 4 ++-- > arch/sparc/vdso/Makefile | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile > index 757451c3ea1d..7318a8b452c3 100644 > --- a/arch/sparc/Makefile > +++ b/arch/sparc/Makefile > @@ -29,7 +29,7 @@ UTS_MACHINE := sparc > # versions of gcc. Some gcc versions won't pass -Av8 to binutils when you > # give -mcpu=v8. This silently worked with older bintutils versions but > # does not any more. > -KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7 > +KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu Couldn't you use ifndef CONFIG_CC_IS_CLANG or perhaps better, use $(call cc-option,-fcall-used-g5) and $(call cc-option,-fcall-used-g7) to not remove the possibility for gcc to make use of these registers? > KBUILD_CFLAGS += -Wa,-Av8 > > KBUILD_AFLAGS += -m32 -Wa,-Av8 > @@ -45,7 +45,7 @@ export BITS := 64 > UTS_MACHINE := sparc64 > > KBUILD_CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow > -KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare > +KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -Wno-sign-compare Similarly here > KBUILD_CFLAGS += -Wa,--undeclared-regs > KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3) > KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs > diff --git a/arch/sparc/vdso/Makefile b/arch/sparc/vdso/Makefile > index 243dbfc4609d..e009443145af 100644 > --- a/arch/sparc/vdso/Makefile > +++ b/arch/sparc/vdso/Makefile > @@ -46,7 +46,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 > -fno-omit-frame-pointer -foptimize-sibling-calls \ > -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO > > -SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7 > +SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 and here. > > $(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) > > Thanks, Andreas
Andreas Larsson <andreas@gaisler.com> wrote: > Couldn't you use ifndef CONFIG_CC_IS_CLANG or perhaps better, use > $(call cc-option,-fcall-used-g5) and $(call cc-option,-fcall-used-g7) to > not remove the possibility for gcc to make use of these registers? Sure sure! It works okay that way too. But before I send a v3, let me wait for clarification for the docs issue for the other patch.
diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile index 757451c3ea1d..7318a8b452c3 100644 --- a/arch/sparc/Makefile +++ b/arch/sparc/Makefile @@ -29,7 +29,7 @@ UTS_MACHINE := sparc # versions of gcc. Some gcc versions won't pass -Av8 to binutils when you # give -mcpu=v8. This silently worked with older bintutils versions but # does not any more. -KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu -fcall-used-g5 -fcall-used-g7 +KBUILD_CFLAGS += -m32 -mcpu=v8 -pipe -mno-fpu KBUILD_CFLAGS += -Wa,-Av8 KBUILD_AFLAGS += -m32 -Wa,-Av8 @@ -45,7 +45,7 @@ export BITS := 64 UTS_MACHINE := sparc64 KBUILD_CFLAGS += -m64 -pipe -mno-fpu -mcpu=ultrasparc -mcmodel=medlow -KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -fcall-used-g7 -Wno-sign-compare +KBUILD_CFLAGS += -ffixed-g4 -ffixed-g5 -Wno-sign-compare KBUILD_CFLAGS += -Wa,--undeclared-regs KBUILD_CFLAGS += $(call cc-option,-mtune=ultrasparc3) KBUILD_AFLAGS += -m64 -mcpu=ultrasparc -Wa,--undeclared-regs diff --git a/arch/sparc/vdso/Makefile b/arch/sparc/vdso/Makefile index 243dbfc4609d..e009443145af 100644 --- a/arch/sparc/vdso/Makefile +++ b/arch/sparc/vdso/Makefile @@ -46,7 +46,7 @@ CFL := $(PROFILING) -mcmodel=medlow -fPIC -O2 -fasynchronous-unwind-tables -m64 -fno-omit-frame-pointer -foptimize-sibling-calls \ -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO -SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 -fcall-used-g5 -fcall-used-g7 +SPARC_REG_CFLAGS = -ffixed-g4 -ffixed-g5 $(vobjs): KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(SPARC_REG_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)