Skip to contentSkip to conversation

build: suppress GNU ld 2.39 warnings

PATCH In review Jan Beulich 2 participants 5 messages Sep 29, 2022 – Oct 4, 2022

lore
Share & tools
lore
#0 lore raw

cover build: suppress GNU ld 2.39 warnings

Like done previously for the hypervisor and elsewhere.

1: suppress GNU ld 2.39 warning about RWX load segments 2: silence GNU ld 2.39 warning about executable stacks

Jan

#1 lore raw

PATCH 1/2 build: suppress GNU ld 2.39 warning about RWX load segments

We cannot really avoid such and we're also not really at risk because of them, as we control page table permissions ourselves rather than relying on a loader of some sort.

build/common.mk +6 -0
@@ -20,9 +20,15 @@ COMMON_FLAGS := -pipe -I$(ROOT)/include
 cc-option = $(shell if [ -z "`echo 'int p=1;' | $(CC) $(1) -S -o /dev/null -x c - 2>&1`" ]; \
 			then echo y; else echo n; fi)
 
+ld-option = $(shell if $(LD) -v $(1) >/dev/null 2>&1; then echo y; else echo n; fi)
+
 # Disable PIE, but need to check if compiler supports it
 COMMON_CFLAGS-$(call cc-option,-no-pie) += -no-pie
 
+# Suppress warnings about LOAD segments with RWX permissions, as what we build
+# aren't normal user-mode executables.
+LDFLAGS-$(call ld-option,--warn-rwx-segments) := --no-warn-rwx-segments
+
 COMMON_AFLAGS := $(COMMON_FLAGS) -D__ASSEMBLY__
 COMMON_CFLAGS := $(COMMON_FLAGS) $(COMMON_CFLAGS-y)
 COMMON_CFLAGS += -Wall -Wextra -Werror -std=gnu99 -Wstrict-prototypes -O3 -g
#2 lore raw

PATCH 2/2 build: silence GNU ld 2.39 warning about executable stacks

In reply to Jan Beulich

While for C files the compiler is supposed to arrange for emitting respective information, for assembly sources we're responsible ourselves.

For the new use of cc-option to work we cannot pass -S to the compiler anymore. We need the compiler to actually invoke the assembler, so switch to using -c.

build/common.mk +8 -2
@@ -15,9 +15,11 @@ $(foreach env,$(HVM_ENVIRONMENTS),$(eval
 $(foreach env,$(32BIT_ENVIRONMENTS),$(eval $(env)_arch := x86_32))
 $(foreach env,$(64BIT_ENVIRONMENTS),$(eval $(env)_arch := x86_64))
 
+comma := ,
+
 COMMON_FLAGS := -pipe -I$(ROOT)/include -I$(ROOT)/arch/x86/include -MMD -MP
 
-cc-option = $(shell if [ -z "`echo 'int p=1;' | $(CC) $(1) -S -o /dev/null -x c - 2>&1`" ]; \
+cc-option = $(shell if [ -z "`echo 'int p=1;' | $(CC) $(1) -c -o /dev/null -x c - 2>&1`" ]; \
 			then echo y; else echo n; fi)
 
 ld-option = $(shell if $(LD) -v $(1) >/dev/null 2>&1; then echo y; else echo n; fi)
@@ -25,11 +27,15 @@ ld-option = $(shell if $(LD) -v $(1) >/d
 # Disable PIE, but need to check if compiler supports it
 COMMON_CFLAGS-$(call cc-option,-no-pie) += -no-pie
 
+# Arrange for assembly files to have a proper .note.GNU-stack section added,
+# to silence warnings otherwise issued by GNU ld 2.39 and newer.
+COMMON_AFLAGS-$(call cc-option,-Wa$(comma)--noexecstack) += -Wa,--noexecstack
+
 # Suppress warnings about LOAD segments with RWX permissions, as what we build
 # aren't normal user-mode executables.
 LDFLAGS-$(call ld-option,--warn-rwx-segments) := --no-warn-rwx-segments
 
-COMMON_AFLAGS := $(COMMON_FLAGS) -D__ASSEMBLY__
+COMMON_AFLAGS := $(COMMON_FLAGS) -D__ASSEMBLY__ $(COMMON_AFLAGS-y)
 COMMON_CFLAGS := $(COMMON_FLAGS) $(COMMON_CFLAGS-y)
 COMMON_CFLAGS += -Wall -Wextra -Werror -std=gnu99 -Wstrict-prototypes -O3 -g
 COMMON_CFLAGS += -fno-common -fno-asynchronous-unwind-tables -fno-strict-aliasing
#3 lore raw
In reply to Jan Beulich
Quoted 4 lines · Jan Beulich

Like done previously for the hypervisor and elsewhere.

1: suppress GNU ld 2.39 warning about RWX load segments 2: silence GNU ld 2.39 warning about executable stacks

I've taken these, and dropped the -no-pie, but there's something else too.

$readelf -Wa tests/example/test-hvm64-example
...

No version information found in this file.

Displaying notes found in: .note
  Owner                Data size     Description
  GNU                  0x00000020    NT_GNU_PROPERTY_TYPE_0
Properties: x86 feature used: x86, <corrupt type (0) datasz: 0xc0010002>

readelf: Warning: note with invalid namesz and/or descsz found at offset 0x30
readelf: Warning:  type: 0x12, namesize: 0x00000004, descsize:
0x00000004, alignment: 8

It's only hvm64 which reads as corrupt, so I think there's some collateral damage with the conversion between ELF64 and ELF32.

~Andrew

#4 lore raw
Quoted 18 lines · Andrew Cooper
Quoted 4 lines · Jan Beulich

Like done previously for the hypervisor and elsewhere.

1: suppress GNU ld 2.39 warning about RWX load segments 2: silence GNU ld 2.39 warning about executable stacks

I've taken these, and dropped the -no-pie, but there's something else too.

$readelf -Wa tests/example/test-hvm64-example
...

No version information found in this file.

Displaying notes found in: .note
  Owner                Data size     Description
  GNU                  0x00000020    NT_GNU_PROPERTY_TYPE_0
Properties: x86 feature used: x86, <corrupt type (0) datasz: 0xc0010002>

Quoted 8 lines

readelf: Warning: note with invalid namesz and/or descsz found at offset 0x30
readelf: Warning:  type: 0x12, namesize: 0x00000004, descsize:
0x00000004, alignment: 8

It's only hvm64 which reads as corrupt, so I think there's some collateral damage with the conversion between ELF64 and ELF32.

Iirc there was a binary-incompatible change (accompanying an incompatible change to the ELF spec) to how notes are generated / processed for 64-bit objects (some hand waving involved here, as this did happen quite a while back). I assume the .note section(s) will need converting (to insert / remove padding) in the course of converting between ELF32 and ELF64.

Jan