Skip to contentSkip to conversation

x86emul: fix test harness build for gas 2.36

PATCH In review Jan Beulich 2 participants 5 messages Apr 19, 2021 – May 7, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86emul: fix test harness build for gas 2.36

All of the sudden, besides .text and .rodata and alike, an always present .note.gnu.property section has appeared. This section, when converting to binary format output, gets placed according to its linked address, causing the resulting blobs to be about 128Mb in size. The resulting headers with a C representation of the binary blobs then are, of course all a multiple of that size (and take accordingly long to create). I didn't bother waiting to see what size the final test_x86_emulator binary then would have had.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=27753.

Rather than figuring out whether gas supports -mx86-used-note=, simply remove the section while creating *.bin.

tools/tests/x86_emulator/testcase.mk +2 -2
@@ -12,11 +12,11 @@ all: $(TESTCASE).bin
 %.bin: %.c
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $<
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $*.tmp $*.o
-	$(OBJCOPY) -O binary $*.tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $*.tmp $@
 	rm -f $*.tmp
 
 %-opmask.bin: opmask.S
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $< -o $(basename $@).o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $(basename $@).tmp $(basename $@).o
-	$(OBJCOPY) -O binary $(basename $@).tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $(basename $@).tmp $@
 	rm -f $(basename $@).tmp
#1 lore raw
Quoted 22 lines · Jan Beulich

All of the sudden, besides .text and .rodata and alike, an always present .note.gnu.property section has appeared. This section, when converting to binary format output, gets placed according to its linked address, causing the resulting blobs to be about 128Mb in size. The resulting headers with a C representation of the binary blobs then are, of course all a multiple of that size (and take accordingly long to create). I didn't bother waiting to see what size the final test_x86_emulator binary then would have had.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=27753.

Rather than figuring out whether gas supports -mx86-used-note=, simply remove the section while creating *.bin.

tools/tests/x86_emulator/testcase.mk +0 -0
@@ -12,11 +12,11 @@ all: $(TESTCASE).bin
 %.bin: %.c
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $<
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $*.tmp $*.o

tools/tests/x86_emulator/testcase.mk all: $(TESTCASE).bin · line 22

Quoted 10 lines
tools/tests/x86_emulator/testcase.mk +2 -2
-	$(OBJCOPY) -O binary $*.tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $*.tmp $@
 	rm -f $*.tmp
 
 %-opmask.bin: opmask.S
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $< -o $(basename $@).o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $(basename $@).tmp $(basename $@).o
-	$(OBJCOPY) -O binary $(basename $@).tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $(basename $@).tmp $@
 	rm -f $(basename $@).tmp

Hmm - this is very ugly.  We don't really want to be stripping this information, because it covers various properties of the binary which need not to be lost, including stack-clash mitigations, and CET status.

We might be able to get away with saying that we're operating strictly with defaults, and folding these *.bin's back into a program which is also linked with defaults, at which point the resulting binary ought to end up with a compatible .note.gnu.property section, but I'm not sure how convinced I am by this argument.

~Andrew

#2 lore raw
Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Jan Beulich

All of the sudden, besides .text and .rodata and alike, an always present .note.gnu.property section has appeared. This section, when converting to binary format output, gets placed according to its linked address, causing the resulting blobs to be about 128Mb in size. The resulting headers with a C representation of the binary blobs then are, of course all a multiple of that size (and take accordingly long to create). I didn't bother waiting to see what size the final test_x86_emulator binary then would have had.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=27753.

Rather than figuring out whether gas supports -mx86-used-note=, simply remove the section while creating *.bin.

tools/tests/x86_emulator/testcase.mk +1 -1
@@ -12,11 +12,11 @@ all: $(TESTCASE).bin
 %.bin: %.c
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $<
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $*.tmp $*.o
-	$(OBJCOPY) -O binary $*.tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $*.tmp $@
 	rm -f $*.tmp
 
Quoted 10 lines

tools/tests/x86_emulator/testcase.mk all: $(TESTCASE).bin · line 22

Quoted 6 lines
tools/tests/x86_emulator/testcase.mk +1 -1
 %-opmask.bin: opmask.S
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $< -o $(basename $@).o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $(basename $@).tmp $(basename $@).o
-	$(OBJCOPY) -O binary $(basename $@).tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $(basename $@).tmp $@
 	rm -f $(basename $@).tmp

Hmm - this is very ugly.  We don't really want to be stripping this information, because it covers various properties of the binary which need not to be lost, including stack-clash mitigations, and CET status.

Could you clarify who you think wants to consume this information from these format-less binary blobs? They're strictly internal to the test harness.

Quoted 5 lines

We might be able to get away with saying that we're operating strictly with defaults, and folding these *.bin's back into a program which is also linked with defaults, at which point the resulting binary ought to end up with a compatible .note.gnu.property section, but I'm not sure how convinced I am by this argument.

Well, if we want to make it complicated, we could of course extract the notes into a separate ELF object, and include that object in the linking process. But these notes are wrong anyway: Whichever insns the blobs use, test_x86_emulator does _not_ need CPU support for them, as it'll suitably avoid executing any of the blobs. Similarly stack and CET related information is not of interest for the blobs, only for the "normal" object files.

Jan

#3 lore raw

Ping: [PATCH] x86emul: fix test harness build for gas 2.36

Quoted 49 lines · Jan Beulich
Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Jan Beulich

All of the sudden, besides .text and .rodata and alike, an always present .note.gnu.property section has appeared. This section, when converting to binary format output, gets placed according to its linked address, causing the resulting blobs to be about 128Mb in size. The resulting headers with a C representation of the binary blobs then are, of course all a multiple of that size (and take accordingly long to create). I didn't bother waiting to see what size the final test_x86_emulator binary then would have had.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=27753.

Rather than figuring out whether gas supports -mx86-used-note=, simply remove the section while creating *.bin.

tools/tests/x86_emulator/testcase.mk +1 -1
@@ -12,11 +12,11 @@ all: $(TESTCASE).bin
 %.bin: %.c
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $<
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $*.tmp $*.o
-	$(OBJCOPY) -O binary $*.tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $*.tmp $@
 	rm -f $*.tmp
 
Quoted 10 lines

tools/tests/x86_emulator/testcase.mk all: $(TESTCASE).bin · line 22

Quoted 6 lines
tools/tests/x86_emulator/testcase.mk +1 -1
 %-opmask.bin: opmask.S
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $< -o $(basename $@).o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $(basename $@).tmp $(basename $@).o
-	$(OBJCOPY) -O binary $(basename $@).tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $(basename $@).tmp $@
 	rm -f $(basename $@).tmp

Hmm - this is very ugly.  We don't really want to be stripping this information, because it covers various properties of the binary which need not to be lost, including stack-clash mitigations, and CET status.

Could you clarify who you think wants to consume this information from these format-less binary blobs? They're strictly internal to the test harness.

Quoted 5 lines

We might be able to get away with saying that we're operating strictly with defaults, and folding these *.bin's back into a program which is also linked with defaults, at which point the resulting binary ought to end up with a compatible .note.gnu.property section, but I'm not sure how convinced I am by this argument.

Quoted 7 lines

Well, if we want to make it complicated, we could of course extract the notes into a separate ELF object, and include that object in the linking process. But these notes are wrong anyway: Whichever insns the blobs use, test_x86_emulator does _not_ need CPU support for them, as it'll suitably avoid executing any of the blobs. Similarly stack and CET related information is not of interest for the blobs, only for the "normal" object files.

Besides there not having been any response from you so far, I'd like to point out that stripping the section is also what H.J. suggests in the referenced bugzilla entry. (As said there, I don't view this as an excuse to break use cases like ours by default, but that's orthogonal.)

Jan

#4 lore raw

Re: Ping: [PATCH] x86emul: fix test harness build for gas 2.36

Quoted 58 lines · Jan Beulich
Quoted 49 lines · Jan Beulich
Quoted 27 lines · Andrew Cooper
Quoted 26 lines · Jan Beulich

All of the sudden, besides .text and .rodata and alike, an always present .note.gnu.property section has appeared. This section, when converting to binary format output, gets placed according to its linked address, causing the resulting blobs to be about 128Mb in size. The resulting headers with a C representation of the binary blobs then are, of course all a multiple of that size (and take accordingly long to create). I didn't bother waiting to see what size the final test_x86_emulator binary then would have had.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=27753.

Rather than figuring out whether gas supports -mx86-used-note=, simply remove the section while creating *.bin.

tools/tests/x86_emulator/testcase.mk +1 -1
@@ -12,11 +12,11 @@ all: $(TESTCASE).bin
 %.bin: %.c
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $<
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $*.tmp $*.o
-	$(OBJCOPY) -O binary $*.tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $*.tmp $@
 	rm -f $*.tmp
 
Quoted 10 lines

tools/tests/x86_emulator/testcase.mk all: $(TESTCASE).bin · line 22

Quoted 6 lines
tools/tests/x86_emulator/testcase.mk +1 -1
 %-opmask.bin: opmask.S
 	$(CC) $(filter-out -M% .%,$(CFLAGS)) -c $< -o $(basename $@).o
 	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o $(basename $@).tmp $(basename $@).o
-	$(OBJCOPY) -O binary $(basename $@).tmp $@
+	$(OBJCOPY) -O binary -R .note.gnu.property $(basename $@).tmp $@
 	rm -f $(basename $@).tmp

Hmm - this is very ugly.  We don't really want to be stripping this information, because it covers various properties of the binary which need not to be lost, including stack-clash mitigations, and CET status.

Could you clarify who you think wants to consume this information from these format-less binary blobs? They're strictly internal to the test harness.

Quoted 5 lines

We might be able to get away with saying that we're operating strictly with defaults, and folding these *.bin's back into a program which is also linked with defaults, at which point the resulting binary ought to end up with a compatible .note.gnu.property section, but I'm not sure how convinced I am by this argument.

Quoted 7 lines

Well, if we want to make it complicated, we could of course extract the notes into a separate ELF object, and include that object in the linking process. But these notes are wrong anyway: Whichever insns the blobs use, test_x86_emulator does _not_ need CPU support for them, as it'll suitably avoid executing any of the blobs. Similarly stack and CET related information is not of interest for the blobs, only for the "normal" object files.

Quoted 4 lines

Besides there not having been any response from you so far, I'd like to point out that stripping the section is also what H.J. suggests in the referenced bugzilla entry. (As said there, I don't view this as an excuse to break use cases like ours by default, but that's orthogonal.)

Unless I hear back constructive feedback over the next week (while I'll be on PTO), I'm going to commit this as is, if need be without any acks, the week after. We shouldn't leave this broken; if you think you see better ways to address the original issue, you can always submit an incremental change later on.

Jan