Skip to contentSkip to conversation

x86/flat.lds: Silence warnings about empty loadable segments

PATCH Applied Thomas Huth 3 participants 5 messages Mar 29, 2023 – Apr 6, 2023 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/flat.lds: Silence warnings about empty loadable segments

Recent versions of objcopy (e.g. from Fedora 37) complain:

objcopy: x86/vmx.elf: warning: empty loadable segment detected at
vaddr=0x400000, is this intentional?

Seems like we can silence these warnings by properly specifying program headers in the linker script.

---
 x86/flat.lds | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
x86/flat.lds +10 -4
index 337bc44f..017a8500 100644
@@ -1,18 +1,24 @@
+PHDRS
+{
+    text PT_LOAD FLAGS(5);
+    data PT_LOAD FLAGS(6);
+}
+
 SECTIONS
 {
     . = 4M + SIZEOF_HEADERS;
     stext = .;
-    .text : { *(.init) *(.text) *(.text.*) }
+    .text : { *(.init) *(.text) *(.text.*) } :text
     etext = .;
     . = ALIGN(4K);
     .data : {
           *(.data)
           exception_table_start = .;
           *(.data.ex)
-	  exception_table_end = .;
-	  }
+          exception_table_end = .;
+    } :data
     . = ALIGN(16);
-    .rodata : { *(.rodata) }
+    .rodata : { *(.rodata) } :data
     . = ALIGN(16);
     .bss : { *(.bss) }
     . = ALIGN(4K);
Signature · 1 line
2.31.1
reviewer Applied
#1 lore raw
Quoted 9 lines · Thomas Huth

Recent versions of objcopy (e.g. from Fedora 37) complain:

objcopy: x86/vmx.elf: warning: empty loadable segment detected at
vaddr=0x400000, is this intentional?

Seems like we can silence these warnings by properly specifying program headers in the linker script.

[...]

Applied to kvm-x86 next, thanks!

On the topic of annoying warnings, this one is also quite annoying:

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

I thought "-z noexecstack" would make it go away, but either I'm wrong or I'm not getting the flag set in the right place.

[1/1] x86/flat.lds: Silence warnings about empty loadable segments

      https://github.com/kvm-x86/kvm-unit-tests/commit/0a06949aafac

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

#2 lore raw
Quoted 6 lines · Sean Christopherson
Quoted 5 lines · Thomas Huth

Recent versions of objcopy (e.g. from Fedora 37) complain:

objcopy: x86/vmx.elf: warning: empty loadable segment detected at
vaddr=0x400000, is this intentional?

Quoted 6 lines
Quoted 4 lines

Seems like we can silence these warnings by properly specifying program headers in the linker script.

[...]

Applied to kvm-x86 next, thanks!

Thanks for picking it up!

Quoted 7 lines

On the topic of annoying warnings, this one is also quite annoying:

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

I thought "-z noexecstack" would make it go away, but either I'm wrong or I'm not getting the flag set in the right place.

I never saw that warning here before, but I'm currently also still using an older version of GCC and binutils here since my development machine is still using RHEL 8 ...

Anyway, does this happen for the normal builds, or for the efi builds? I can see a .note.GNU-stack entry in x86/efi/elf_x86_64_efi.lds ... maybe we need something similar in x86/flat.lds ?

Thomas

#3 lore raw
Quoted 21 lines · Thomas Huth
Quoted 6 lines · Sean Christopherson
Quoted 5 lines · Thomas Huth

Recent versions of objcopy (e.g. from Fedora 37) complain:

objcopy: x86/vmx.elf: warning: empty loadable segment detected at
vaddr=0x400000, is this intentional?

Quoted 6 lines
Quoted 4 lines

Seems like we can silence these warnings by properly specifying program headers in the linker script.

[...]

Applied to kvm-x86 next, thanks!

Thanks for picking it up!

Quoted 5 lines

On the topic of annoying warnings, this one is also quite annoying:

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

Quoted 8 lines
Quoted 2 lines

I thought "-z noexecstack" would make it go away, but either I'm wrong or I'm not getting the flag set in the right place.

I never saw that warning here before, but I'm currently also still using an older version of GCC and binutils here since my development machine is still using RHEL 8 ...

Anyway, does this happen for the normal builds, or for the efi builds?

Normal builds with gcc 12. I figured out what I got wrong, the "-z noexecstack" needs to be passed to the linker, not the compiler/assembler. This does the trick, I'll post an official patch later today:

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)
Quoted 2 lines

I can see a .note.GNU-stack entry in x86/efi/elf_x86_64_efi.lds ... maybe we need something similar in x86/flat.lds ?

I believe that just telling the linker that those sections don't need relocation info. I suspect it's unnecessary copy+paste from UEFI sources.

The linker warning from setjmp64.o (and cstart64.o) is yelling about _not_ having .note.GNU-stack, which is a magic section that tells the linker that the binary doesn't need an executable stack. If I'm reading the NOTE correctly, it's saying that the ability to have an executable stack is soon going away.

maintainer
#4 lore raw
Quoted 9 lines · Sean Christopherson
Quoted 2 lines

I can see a .note.GNU-stack entry in x86/efi/elf_x86_64_efi.lds ... maybe we need something similar in x86/flat.lds ?

I believe that just telling the linker that those sections don't need relocation info. I suspect it's unnecessary copy+paste from UEFI sources.

The linker warning from setjmp64.o (and cstart64.o) is yelling about_not_ having .note.GNU-stack, which is a magic section that tells the linker that the binary doesn't need an executable stack. If I'm reading the NOTE correctly, it's saying that the ability to have an executable stack is soon going away.

More or less; if I remember correctly they want to flip the default from executable stack to non-executable stack. If you want an executable stack you'll have to add an ELF note or link with -z execstack.

All of this of course is irrelevant in a freestanding environment.

Paolo