Makefile: Pass "-Wa, -mno-relax" to manually forward it to the GNU assembler when linking with LLD
PATCH 1/1 Makefile: Pass "-Wa, -mno-relax" to manually forward it to the GNU assembler when linking with LLD
When generating code with -mno-relax, GCC puts .option norelax in the generated assembly, and so doesn?t bother passing on -mno-relax to the assembler. This has the unfortunate effect that, when using GCC to assemble hand-written assembly, -mno-relax does nothing, and we have to pass -Wa,-mno-relax to manually forward it to the assembler.
This is an old GCC bug that was fixed [1] recently. For the time being, let's pass "-Wa,-mno-relax" to ASFLAGS for the GCC + LLD combination to work, e.g.:
$ make CC=riscv64-unknown-elf-gcc LLVM=1 PLATFORM=generic
[1] https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857
---
Makefile | 3 +++ 1 file changed, 3 insertions(+)
Makefile +3 -0
@@ -272,6 +272,9 @@ ASFLAGS += -mno-save-restore -mstrict-align ASFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA) ASFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) ASFLAGS += $(RELAX_FLAG) +ifeq ($(CC_IS_CLANG)$(LD_IS_LLD),ny) +ASFLAGS += -Wa,-mno-relax +endif ASFLAGS += $(GENFLAGS) ASFLAGS += $(platform-asflags-y) ASFLAGS += $(firmware-asflags-y)
Signature · 1 line
2.25.1
PATCH 1/1 Makefile: Pass "-Wa, -mno-relax" to manually forward it to the GNU assembler when linking with LLD
Quoted 27 lines · Bin Meng
When generating code with -mno-relax, GCC puts .option norelax in the generated assembly, and so doesn?t bother passing on -mno-relax to the assembler. This has the unfortunate effect that, when using GCC to assemble hand-written assembly, -mno-relax does nothing, and we have to pass -Wa,-mno-relax to manually forward it to the assembler.
This is an old GCC bug that was fixed [1] recently. For the time being, let's pass "-Wa,-mno-relax" to ASFLAGS for the GCC + LLD combination to work, e.g.:
$ make CC=riscv64-unknown-elf-gcc LLVM=1 PLATFORM=generic[1] https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857
Signed-off-by Bin Meng <[email protected]>---
Makefile| 3 +++1 file changed, 3 insertions(+)Makefile +0
-0
Makefile ASFLAGS += -mno-save-restore -mstrict-align · line 277
Quoted 6 lines
Makefile +3
-0@@ -272,6 +272,9 @@ ASFLAGS += -mno-save-restore -mstrict-align ASFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA) ASFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL) ASFLAGS += $(RELAX_FLAG) +ifeq ($(CC_IS_CLANG)$(LD_IS_LLD),ny) +ASFLAGS += -Wa,-mno-relax +endif
Hm, I was thinking:
ifneq ($(CC_IS_CLANG),y)
ifneq ($(RELAX_FLAG),)
ASFLAGS += -Wa,$(RELAX_FLAG)
endif
endif
That way you separate ?GCC needs the flag forwarded manually? from ?LLD needs code compiled with the flag? (as well as what the flag actually is, not that that matters).
Jess