[PATCH] RISC-V: Stop emitting attributes

Palmer Dabbelt palmer at rivosinc.com
Thu Feb 23 14:13:55 PST 2023


On Thu, 23 Feb 2023 13:18:01 PST (-0800), Conor Dooley wrote:
> On Thu, Feb 23, 2023 at 11:51:12AM -0800, Palmer Dabbelt wrote:
>> The RISC-V ELF attributes don't contain any useful information.  New
>> toolchains ignore them, but they frequently trip up various older/mixed
>> toolchains.  So just turn them off.
>> 
>> Signed-off-by: Palmer Dabbelt <palmer at rivosinc.com>
>> ---
>>  arch/riscv/Makefile | 5 +++++
>>  1 file changed, 5 insertions(+)
>> 
>> diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
>> index 76989561566b..1fc504e2b85e 100644
>> --- a/arch/riscv/Makefile
>> +++ b/arch/riscv/Makefile
>> @@ -81,6 +81,11 @@ ifeq ($(CONFIG_PERF_EVENTS),y)
>>          KBUILD_CFLAGS += -fno-omit-frame-pointer
>>  endif
>>  
>> +# The RISC-V attributes frequently cause compatibility issues and provide no
>> +# information, so just turn them off.
>> +KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
>> +KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
>> +
>>  KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
>>  KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
>
> As requested, the build issues I see w/ this patch applied & ld 2.35:
>   LD      arch/riscv/purgatory/purgatory.ro
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/purgatory/memcpy.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/purgatory/memset.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/purgatory/strcmp.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/purgatory/strlen.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/purgatory/strncmp.o
>   CHECK   /stuff/linux/ipc/ipc_sysctl.c
> make[6]: *** [/stuff/linux/arch/riscv/purgatory/Makefile:95: arch/riscv/purgatory/purgatory.ro] Error 1
> make[6]: Target 'arch/riscv/purgatory/' not remade because of errors.
> make[5]: *** [/stuff/linux/scripts/Makefile.build:504: arch/riscv/purgatory] Error 2

I'm not actually reproducing these locally because I don't want to mess 
with the toolchain, but I think

diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile
index 1fc504e2b85e..7b53f0be56b2 100644
--- a/arch/riscv/Makefile
+++ b/arch/riscv/Makefile
@@ -84,7 +84,9 @@ endif
 # The RISC-V attributes frequently cause compatibility issues and provide no
 # information, so just turn them off.
 KBUILD_CFLAGS += $(call cc-option,-mno-riscv-attribute)
+KBUILD_AFLAGS += $(call cc-option,-mno-riscv-attribute)
 KBUILD_CFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
+KBUILD_AFLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)

 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
 KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)

should fix the purgatory bits.  There might be a better way to do that, 
though, as the AS in purgatory ends up calling CC...

>   CC      arch/riscv/mm/dma-noncoherent.o
>   AR      arch/riscv/kernel/probes/built-in.a
>   CHECK   /stuff/linux/lib/zlib_inflate/inffast.c
>   VDSOLD  arch/riscv/kernel/vdso/vdso.so.dbg
>   VDSOLD  arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/kernel/vdso/getcpu.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/kernel/vdso/flush_icache.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/kernel/vdso/note.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv32i2p0_m2p0_a2p0_f2p0_d2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/kernel/compat_vdso/getcpu.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv32i2p0_m2p0_a2p0_f2p0_d2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/kernel/compat_vdso/flush_icache.o
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: -march=rv32i2p0_m2p0_a2p0_f2p0_d2p0_zmmul1p0: Invalid or unknown z ISA extension: 'zmmul'
> /stuff/toolchains/binutils-2.35/bin/riscv64-linux-gnu-ld: failed to merge target specific data of file arch/riscv/kernel/compat_vdso/note.o

and I think this one sohuld do it

diff --git a/arch/riscv/kernel/compat_vdso/Makefile b/arch/riscv/kernel/compat_vdso/Makefile
index 260daf3236d3..7f34f3c7c882 100644
--- a/arch/riscv/kernel/compat_vdso/Makefile
+++ b/arch/riscv/kernel/compat_vdso/Makefile
@@ -14,6 +14,10 @@ COMPAT_LD := $(LD)
 COMPAT_CC_FLAGS := -march=rv32g -mabi=ilp32
 COMPAT_LD_FLAGS := -melf32lriscv

+# Disable attributes, as they're useless and break the build.
+COMPAT_CC_FLAGS += $(call cc-option,-mno-riscv-attribute)
+COMPAT_CC_FLAGS += $(call as-option,-Wa$(comma)-mno-arch-attr)
+
 # Files to link into the compat_vdso
 obj-compat_vdso = $(patsubst %, %.o, $(compat_vdso-syms)) note.o

>   OBJCOPY arch/riscv/kernel/compat_vdso/compat_vdso.so
>   OBJCOPY arch/riscv/kernel/vdso/vdso.so
> riscv64-unknown-linux-gnu-objcopy: 'arch/riscv/kernel/compat_vdso/compat_vdso.so.dbg': No such file
> riscv64-unknown-linux-gnu-objcopy: 'arch/riscv/kernel/vdso/vdso.so.dbg': No such file
> make[7]: *** [/stuff/linux/arch/riscv/kernel/compat_vdso/Makefile:48: arch/riscv/kernel/compat_vdso/compat_vdso.so] Error 1
>
> Specifically this is what I am running:
> CONFIG_CC_VERSION_TEXT="riscv64-unknown-linux-gnu-gcc (ge4703bd0e15-dirty) 13.0.1 20230122 (experimental)"
> CONFIG_CC_IS_GCC=y
> CONFIG_GCC_VERSION=130001
> CONFIG_AS_IS_GNU=y
> CONFIG_AS_VERSION=24050
> CONFIG_LD_IS_BFD=y
> CONFIG_LD_VERSION=23500

With both of those I get no attributes in vmlinux, so hopefully things 
have been sorted out.  It's stuck at palmer/riscv-no_attributes-v2, in 
case that's easier.

>
> Cheers,
> Conor.



More information about the linux-riscv mailing list