Skip to contentSkip to conversation

x86: Link with "-z noexecstack" to suppress irrelevant linker warnings

PATCH Applied Sean Christopherson 2 participants 3 messages Apr 6, 2023 – Jun 7, 2023 KVM

lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 x86: Link with "-z noexecstack" to suppress irrelevant linker warnings

Explicitly tell the linker KUT doesn't need an executable stack to suppress gcc-12 warnings about the default behavior of having an executable stack being deprecated. The entire thing is irrelevant for KUT (and other freestanding environments) as KUT creates its own stacks, i.e. there's no loader/libc that consumes the magic ".note.GNU-stack" section.

ld -nostdlib -m elf_x86_64 -T /home/seanjc/go/src/kernel.org/kvm-unit-tests/x86/flat.lds

     -o x86/vmx.elf x86/vmx.o x86/cstart64.o x86/access.o x86/vmx_tests.o lib/libcflat.a

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

---
 x86/Makefile.common | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/Makefile.common +1 -1
index 365e199f..c57d418a 100644
@@ -62,7 +62,7 @@ else
 # We want to keep intermediate file: %.elf and %.o
 .PRECIOUS: %.elf %.o
 
-%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS)
+%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS) -z noexecstack
 %.elf: %.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
 	$(LD) $(LDFLAGS) -T $(SRCDIR)/x86/flat.lds -o $@ \
 		$(filter %.o, $^) $(FLATLIBS)

base-commit: 4ba7058c61e8922f9c8397cfa1095fac325f809b

Signature · 1 line
2.40.0.577.gac1e443424-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Sean Christopherson

Explicitly tell the linker KUT doesn't need an executable stack to suppress gcc-12 warnings about the default behavior of having an executable stack being deprecated. The entire thing is irrelevant for KUT (and other freestanding environments) as KUT creates its own stacks, i.e. there's no loader/libc that consumes the magic ".note.GNU-stack" section.

ld -nostdlib -m elf_x86_64 -T /home/seanjc/go/src/kernel.org/kvm-unit-tests/x86/flat.lds

      -o x86/vmx.elf x86/vmx.o x86/cstart64.o x86/access.o x86/vmx_tests.o lib/libcflat.a

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

---
  x86/Makefile.common | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
x86/Makefile.common +0 -0
index 365e199f..c57d418a 100644

x86/Makefile.common else · line 68

Quoted 8 lines
x86/Makefile.common +1 -1
@@ -62,7 +62,7 @@ else
  # We want to keep intermediate file: %.elf and %.o
  .PRECIOUS: %.elf %.o
 
-%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS)
+%.elf: LDFLAGS = -nostdlib $(arch_LDFLAGS) -z noexecstack
  %.elf: %.o $(FLATLIBS) $(SRCDIR)/x86/flat.lds $(cstart.o)
  	$(LD) $(LDFLAGS) -T $(SRCDIR)/x86/flat.lds -o $@ \
  		$(filter %.o, $^) $(FLATLIBS)
author reviewer Applied
#2 lore raw
In reply to Sean Christopherson
Quoted 6 lines · Sean Christopherson

Explicitly tell the linker KUT doesn't need an executable stack to suppress gcc-12 warnings about the default behavior of having an executable stack being deprecated. The entire thing is irrelevant for KUT (and other freestanding environments) as KUT creates its own stacks, i.e. there's no loader/libc that consumes the magic ".note.GNU-stack" section.

Quoted 6 lines

ld -nostdlib -m elf_x86_64 -T /home/seanjc/go/src/kernel.org/kvm-unit-tests/x86/flat.lds

     -o x86/vmx.elf x86/vmx.o x86/cstart64.o x86/access.o x86/vmx_tests.o lib/libcflat.a

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

[...]

Applied to kvm-x86 next, thanks!

[1/1] x86: Link with "-z noexecstack" to suppress irrelevant linker warnings

      https://github.com/kvm-x86/kvm-unit-tests/commit/5f15933dccae

--
https://github.com/kvm-x86/kvm-unit-tests/tree/next