Skip to contentSkip to conversation

riscv: add correct as-options for assembly in modules

PATCH Superseded Ben Dooks 2 participants 5 messages Jul 12, 2021 – Jul 16, 2021 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 1/1 riscv: add correct as-options for assembly in modules

When trying to load modules built for riscv which include assembly the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'" due to R_RISCV_ALIGN relocations being generated by the assembler.

In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading") the fix for gcc adds -mno-relax to the command line when building C files. However this was never applied to assembly flags, and gcc does no pass -mno-relax to gas when presented with a .S file.

The fix (other than making gcc always pass -mno-relax to gas) is to add -Wa,-mno-relax to gcc to make sure the as is invoked with the right options.

---
 arch/riscv/Makefile | 1 +
 1 file changed, 1 insertion(+)
arch/riscv/Makefile +1 -0
index 1f5c03082976..fca40511a8c6 100644
@@ -60,6 +60,7 @@ ifeq ($(CONFIG_PERF_EVENTS),y)
 endif
 
 KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
+KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
 
 # GCC versions that support the "-mstrict-align" option default to allowing
 # unaligned accesses.  While unaligned accesses are explicitly allowed in the
Signature · 7 lines
2.30.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
author
#1 lore raw
Quoted 9 lines · Ben Dooks

When trying to load modules built for riscv which include assembly the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'" due to R_RISCV_ALIGN relocations being generated by the assembler.

In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading") the fix for gcc adds -mno-relax to the command line when building C files. However this was never applied to assembly flags, and gcc does no pass -mno-relax to gas when presented with a .S file.

Quoted 5 lines

The fix (other than making gcc always pass -mno-relax to gas) is to add -Wa,-mno-relax to gcc to make sure the as is invoked with the right options.

Just wanted to find out if anyone has had time to review this. If this is ok, should we also send to -stable ?

Quoted 17 lines
---
  arch/riscv/Makefile | 1 +
  1 file changed, 1 insertion(+)
arch/riscv/Makefile +1 -0
index 1f5c03082976..fca40511a8c6 100644
@@ -60,6 +60,7 @@ ifeq ($(CONFIG_PERF_EVENTS),y)
  endif
 
  KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-relax)
+KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax)
 
  # GCC versions that support the "-mstrict-align" option default to allowing
  # unaligned accesses.  While unaligned accesses are explicitly allowed in the
Signature · 9 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ben Dooks
Quoted 2 lines · Ben Dooks

When trying to load modules built for riscv which include assembly

nits: RISC-V

Quoted 7 lines

the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'" due to R_RISCV_ALIGN relocations being generated by the assembler.

In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading") the fix for gcc adds -mno-relax to the command line when building C files. However this was never applied to assembly flags, and gcc does no pass -mno-relax to gas when presented with a .S file.

does not pass

FYI

The GCC bug was fixed recently via:
https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

Quoted 10 lines

The fix (other than making gcc always pass -mno-relax to gas) is to add -Wa,-mno-relax to gcc to make sure the as is invoked with the right options.

---
 arch/riscv/Makefile | 1 +
 1 file changed, 1 insertion(+)

Otherwise,

author
#3 lore raw
Quoted 9 lines · Bin Meng
Quoted 2 lines · Ben Dooks

When trying to load modules built for riscv which include assembly

nits: RISC-V

Quoted 3 lines

the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'" due to R_RISCV_ALIGN relocations being generated by the assembler.

Quoted 6 lines
Quoted 4 lines

In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading") the fix for gcc adds -mno-relax to the command line when building C files. However this was never applied to assembly flags, and gcc does no pass -mno-relax to gas when presented with a .S file.

does not pass

I'll see if I can make this simpler. Should this get done for a v2?

Quoted 4 lines

FYI

The GCC bug was fixed recently via:
https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

thanks, I think it still useful to fix this in the kernel.

Quoted 14 lines
Quoted 10 lines

The fix (other than making gcc always pass -mno-relax to gas) is to add -Wa,-mno-relax to gcc to make sure the as is invoked with the right options.

---
  arch/riscv/Makefile | 1 +
  1 file changed, 1 insertion(+)

Otherwise,

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html
#4 lore raw
Quoted 11 lines · Ben Dooks
Quoted 9 lines · Bin Meng
Quoted 2 lines · Ben Dooks

When trying to load modules built for riscv which include assembly

nits: RISC-V

Quoted 3 lines

the kernel loader errors with "unexpected relocation type 'R_RISCV_ALIGN'" due to R_RISCV_ALIGN relocations being generated by the assembler.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

In commit 7a8e7da42250138 ("RISC-V: Fixes to module loading") the fix for gcc adds -mno-relax to the command line when building C files. However this was never applied to assembly flags, and gcc does no pass -mno-relax to gas when presented with a .S file.

does not pass

I'll see if I can make this simpler. Should this get done for a v2?

Yes, please send v2.

Quoted 20 lines
Quoted 4 lines

FYI

The GCC bug was fixed recently via:
https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

thanks, I think it still useful to fix this in the kernel.

Quoted 13 lines
Quoted 10 lines

The fix (other than making gcc always pass -mno-relax to gas) is to add -Wa,-mno-relax to gcc to make sure the as is invoked with the right options.

---
  arch/riscv/Makefile | 1 +
  1 file changed, 1 insertion(+)

Otherwise,

Regards,
Bin