Skip to contentSkip to conversation

tests/tcg: Fix new cross-compiler warnings

PATCH Applied Richard Henderson 3 participants 6 messages Jul 24, 2024 RISC-V

lore
Share & tools
lore
#0 lore raw

cover tests/tcg: Fix new cross-compiler warnings

Recent updates to debian cross-compilers have enabled some new warnings by default, which encourage good behaviour for userland binaries.

Neither are applicable for our system mode kernel images, but we do have a few userland tests that are affected.

The --noexecstack assembler flag takes care of adding the appropriate .note.GNU-stack elf note for us, rather than writing a dozen lines of assembly template, and so is a true fix rather than merely disabling the linker warning.

r~

Richard Henderson (2):
tests/tcg: Use --noexecstack with assembler files tests/tcg/loongarch64: Use --no-warn-rwx-segments to link system tests

 tests/tcg/Makefile.target                     | 2 +-
 tests/tcg/aarch64/Makefile.softmmu-target     | 2 +-
 tests/tcg/alpha/Makefile.softmmu-target       | 2 +-
 tests/tcg/arm/Makefile.softmmu-target         | 2 +-
 tests/tcg/arm/Makefile.target                 | 2 +-
 tests/tcg/i386/Makefile.softmmu-target        | 2 +-
 tests/tcg/loongarch64/Makefile.softmmu-target | 4 ++--
 tests/tcg/riscv64/Makefile.softmmu-target     | 2 +-
 tests/tcg/s390x/Makefile.softmmu-target       | 2 +-
 tests/tcg/x86_64/Makefile.softmmu-target      | 2 +-
 10 files changed, 11 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 tests/tcg: Use --noexecstack with assembler files

Add the --noexecstack assembler command-line option to avoid:

/usr/bin/ld: warning: boot.o: missing .note.GNU-stack section implies executable stack /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

which is enabled by default with current debian cross toolchains.

---
 tests/tcg/Makefile.target                     | 2 +-
 tests/tcg/aarch64/Makefile.softmmu-target     | 2 +-
 tests/tcg/alpha/Makefile.softmmu-target       | 2 +-
 tests/tcg/arm/Makefile.softmmu-target         | 2 +-
 tests/tcg/arm/Makefile.target                 | 2 +-
 tests/tcg/i386/Makefile.softmmu-target        | 2 +-
 tests/tcg/loongarch64/Makefile.softmmu-target | 2 +-
 tests/tcg/riscv64/Makefile.softmmu-target     | 2 +-
 tests/tcg/s390x/Makefile.softmmu-target       | 2 +-
 tests/tcg/x86_64/Makefile.softmmu-target      | 2 +-
 10 files changed, 10 insertions(+), 10 deletions(-)
tests/tcg/Makefile.target +1 -1
index cb8cfeb6da..1f8e5b3d30 100644
@@ -115,7 +115,7 @@ endif
 %: %.c
 	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
 %: %.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wa,--noexecstack $< -o $@ $(LDFLAGS)
 else
 # For system targets we include a different Makefile fragment as the
 # build options for bare programs are usually pretty different. They
tests/tcg/aarch64/Makefile.softmmu-target +1 -1
index dd6d595830..139e04d15f 100644
@@ -28,7 +28,7 @@ config-cc.mak: Makefile
 .PRECIOUS: $(CRT_OBJS)
 
 %.o: $(CRT_PATH)/%.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -c $< -o $@
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -Wa,--noexecstack -c $< -o $@
 
 # Build and link the tests
 %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
tests/tcg/alpha/Makefile.softmmu-target +1 -1
index 09193a62d6..a0eca4d6ea 100644
@@ -22,7 +22,7 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
 .PRECIOUS: $(CRT_OBJS)
 
 %.o: $(CRT_PATH)/%.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -c $< -o $@
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -Wa,--noexecstack -c $< -o $@
 
 # Build and link the tests
 %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
tests/tcg/arm/Makefile.softmmu-target +1 -1
index 547063c08c..b66074b0b4 100644
@@ -36,7 +36,7 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
 .PRECIOUS: $(CRT_OBJS)
 
 %.o: $(ARM_SRC)/%.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -c $< -o $@
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -Wa,--noexecstack -c $< -o $@
 
 # Build and link the tests
 %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
tests/tcg/arm/Makefile.target +1 -1
index 8e287191af..06ddf3e04f 100644
@@ -25,7 +25,7 @@ ARM_TESTS += test-arm-iwmmxt
 # Clang assembler does not support IWMXT, so use the external assembler.
 test-arm-iwmmxt: CFLAGS += -marm -march=iwmmxt -mabi=aapcs -mfpu=fpv4-sp-d16 $(CROSS_CC_HAS_FNIA)
 test-arm-iwmmxt: test-arm-iwmmxt.S
-	$(CC) $(CFLAGS) $< -o $@ $(LDFLAGS)
+	$(CC) $(CFLAGS) -Wa,--noexecstack $< -o $@ $(LDFLAGS)
 
 # Float-convert Tests
 ARM_TESTS += fcvt
tests/tcg/i386/Makefile.softmmu-target +1 -1
index 5266f2335a..4096a1cf31 100644
@@ -25,7 +25,7 @@ EXTRA_RUNS+=$(MULTIARCH_RUNS)
 .PRECIOUS: $(CRT_OBJS)
 
 %.o: $(CRT_PATH)/%.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wa,--noexecstack -c $< -o $@
 
 # Build and link the tests
 %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
tests/tcg/loongarch64/Makefile.softmmu-target +1 -1
index 908f3a8c0f..d5d5c1a7f6 100644
@@ -22,7 +22,7 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
 .PRECIOUS: $(CRT_OBJS)
 
 %.o: $(CRT_PATH)/%.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -c $< -o $@
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -x assembler-with-cpp -Wa,--noexecstack -c $< -o $@
 
 # Build and link the tests
 %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
tests/tcg/riscv64/Makefile.softmmu-target +1 -1
index d5b126e5f1..7c1d44d3f4 100644
@@ -10,7 +10,7 @@ LDFLAGS = -T $(LINK_SCRIPT)
 CFLAGS += -g -Og
 
 %.o: %.S
-	$(CC) $(CFLAGS) $< -c -o $@
+	$(CC) $(CFLAGS) $< -Wa,--noexecstack -c -o $@
 %: %.o $(LINK_SCRIPT)
 	$(LD) $(LDFLAGS) $< -o $@
 
tests/tcg/s390x/Makefile.softmmu-target +1 -1
index 4c8e15e625..f60f94b090 100644
@@ -6,7 +6,7 @@ CFLAGS+=-ggdb -O0
 LDFLAGS=-nostdlib -static
 
 %.o: %.S
-	$(CC) -march=z13 -m64 -c $< -o $@
+	$(CC) -march=z13 -m64 -Wa,--noexecstack -c $< -o $@
 
 %.o: %.c
 	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -march=z13 -m64 -c $< -o $@
tests/tcg/x86_64/Makefile.softmmu-target +1 -1
index 1bd763f2e6..ef6bcb4dc7 100644
@@ -25,7 +25,7 @@ EXTRA_RUNS+=$(MULTIARCH_RUNS)
 .PRECIOUS: $(CRT_OBJS)
 
 %.o: $(CRT_PATH)/%.S
-	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -Wa,--noexecstack -c $< -o $@
 
 # Build and link the tests
 %: %.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] tests/tcg: Use --noexecstack with assembler files

Quoted 8 lines · Richard Henderson

Add the --noexecstack assembler command-line option to avoid:

/usr/bin/ld: warning: boot.o: missing .note.GNU-stack section implies executable stack /usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

which is enabled by default with current debian cross toolchains.

Quoted 12 lines
---
  tests/tcg/Makefile.target                     | 2 +-
  tests/tcg/aarch64/Makefile.softmmu-target     | 2 +-
  tests/tcg/alpha/Makefile.softmmu-target       | 2 +-
  tests/tcg/arm/Makefile.softmmu-target         | 2 +-
  tests/tcg/arm/Makefile.target                 | 2 +-
  tests/tcg/i386/Makefile.softmmu-target        | 2 +-
  tests/tcg/loongarch64/Makefile.softmmu-target | 2 +-
  tests/tcg/riscv64/Makefile.softmmu-target     | 2 +-
  tests/tcg/s390x/Makefile.softmmu-target       | 2 +-
  tests/tcg/x86_64/Makefile.softmmu-target      | 2 +-
  10 files changed, 10 insertions(+), 10 deletions(-)
#3 lore raw

PATCH 2/2 tests/tcg/loongarch64: Use --no-warn-rwx-segments to link system tests

In reply to Richard Henderson

Recent debian cross-linker for loongarch issues

ld: warning: hello has a LOAD segment with RWX permissions

This is partially related to tests/tcg/loongarch64/system/kernel.ld, but is not fixed by explicitly adding a single LOAD PHDR. Disable the warning, since it does not apply to kernel images.

---
 tests/tcg/loongarch64/Makefile.softmmu-target | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/tcg/loongarch64/Makefile.softmmu-target +1 -1
index d5d5c1a7f6..6d4a20fde7 100644
@@ -16,7 +16,7 @@ LINK_SCRIPT=$(LOONGARCH64_SYSTEM_SRC)/kernel.ld
 LDFLAGS=-Wl,-T$(LINK_SCRIPT)
 TESTS+=$(LOONGARCH64_TESTS) $(MULTIARCH_TESTS)
 CFLAGS+=-nostdlib -g -O1 -march=loongarch64 -mabi=lp64d $(MINILIB_INC)
-LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
+LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc -Wl,--no-warn-rwx-segments
 
 # building head blobs
 .PRECIOUS: $(CRT_OBJS)
Signature · 1 line
2.43.0
Applied
#4 lore raw
In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

Recent updates to debian cross-compilers have enabled some new warnings by default, which encourage good behaviour for userland binaries.

Neither are applicable for our system mode kernel images, but we do have a few userland tests that are affected.

The --noexecstack assembler flag takes care of adding the appropriate .note.GNU-stack elf note for us, rather than writing a dozen lines of assembly template, and so is a true fix rather than merely disabling the linker warning.

Queued to maintainer/for-9.1, thanks.

Quoted 1 line
 10 files changed, 11 insertions(+), 11 deletions(-)
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Applied
#5 lore raw
In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

Recent updates to debian cross-compilers have enabled some new warnings by default, which encourage good behaviour for userland binaries.

Neither are applicable for our system mode kernel images, but we do have a few userland tests that are affected.

The --noexecstack assembler flag takes care of adding the appropriate .note.GNU-stack elf note for us, rather than writing a dozen lines of assembly template, and so is a true fix rather than merely disabling the linker warning.

Queued to maintainer/for-9.1, thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro