[kvm-unit-tests PATCH v1 2/3] s390x/Makefile: snippets: Avoid creation of .eh_frame and .eh_frame_hdr sections

Marc Hartmayer
2024-06-04T11:59:58Z

Use `-fno-asynchronous-unwind-tables` and `-fno-exceptions` to avoid creating
`.eh_frame` and `.eh_frame_hdr` sections. They are not used by the snippets and
the creation of the sections may result in the creation of an RWX
segment (depending on the toolchain used).

Before this change:

$ make -j s390x/snippets/c/spec_ex.elf >/dev/null && readelf -l s390x/snippets/c/spec_ex.elf
/usr/bin/s390x-linux-gnu-ld: warning: s390x/snippets/c/spec_ex.elf has a LOAD segment with RWX permissions

Elf file type is EXEC (Executable file)
Entry point 0x4000
There are 4 program headers, starting at offset 64

Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000001000 0x0000000000000000 0x0000000000000000
0x00000000000001b0 0x00000000000001b0 RW 0x1000
LOAD 0x0000000000002000 0x0000000000004000 0x0000000000004000
0x000000000000104c 0x0000000000001060 RWE 0x1000
GNU_EH_FRAME 0x0000000000003038 0x0000000000005038 0x0000000000005038
0x0000000000000014 0x0000000000000014 R 0x4
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x10

Section to Segment mapping:
Segment Sections...
00 .lowcore
01 .text .eh_frame .eh_frame_hdr .bss
02 .eh_frame_hdr
03

After this change, there is no warning and no RWX ELF segment:

$ make -j s390x/snippets/c/spec_ex.elf >/dev/null && readelf -l s390x/snippets/c/spec_ex.elf
Elf file type is EXEC (Executable file)
Entry point 0x4000
There are 4 program headers, starting at offset 64

Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flags Align
LOAD 0x0000000000001000 0x0000000000000000 0x0000000000000000
0x00000000000001b0 0x00000000000001b0 RW 0x1000
LOAD 0x0000000000002000 0x0000000000004000 0x0000000000004000
0x00000000000000a8 0x00000000000000a8 R E 0x1000
LOAD 0x0000000000000000 0x0000000000005000 0x0000000000005000
0x0000000000000000 0x0000000000000010 RW 0x1000
GNU_STACK 0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 RW 0x10

Section to Segment mapping:
Segment Sections...
00 .lowcore
01 .text
02 .bss
03

Linker used:

$ s390x-linux-gnu-ld -v
GNU ld version 2.41-1.fc40

Therefore the commit 9801dbbe9ea4 ("s390x: Specify program headers with flags to
avoid linker warnings") can be reverted.
---
Note: we have to double check whether__builtin_frame_address() in s390x/stack.c
needs the .eh_frame or not.
---
Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
---
s390x/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/s390x/Makefile b/s390x/Makefile
index 784818b2883e..f1bbf5e9f457 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -148,10 +148,10 @@ endif

# the asm/c snippets %.o have additional generated files as dependencies
$(SNIPPET_DIR)/asm/%.o: $(SNIPPET_DIR)/asm/%.S $(asm-offsets)
- $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
+ $(CC) $(CFLAGS) -c -nostdlib -fno-asynchronous-unwind-tables -fno-exceptions -o $@ $<

$(SNIPPET_DIR)/c/%.o: $(SNIPPET_DIR)/c/%.c $(asm-offsets)
- $(CC) $(CFLAGS) -c -nostdlib -o $@ $<
+ $(CC) $(CFLAGS) -c -nostdlib -fno-asynchronous-unwind-tables -fno-exceptions -o $@ $<

$(SNIPPET_DIR)/asm/%.elf: $(SNIPPET_DIR)/asm/%.o $(SNIPPET_DIR)/asm/flat.lds
$(CC) $(LDFLAGS) -o $@ -T $(SNIPPET_DIR)/asm/flat.lds $<
--
2.34.1