xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tests/x86emul: Annotate test blobs as executable code
@ 2019-05-24 15:15 Andrew Cooper
  2019-05-24 15:15 ` [Xen-devel] " Andrew Cooper
  2019-05-24 15:50 ` Jan Beulich
  0 siblings, 2 replies; 7+ messages in thread
From: Andrew Cooper @ 2019-05-24 15:15 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné

This causes objdump to disassemble them, rather than rendering them as
straight hex data.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 tools/tests/x86_emulator/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/tests/x86_emulator/Makefile b/tools/tests/x86_emulator/Makefile
index 970ec3e..b54603d 100644
--- a/tools/tests/x86_emulator/Makefile
+++ b/tools/tests/x86_emulator/Makefile
@@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
 		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
 		      "$${prefix}_$(arch)$${flavor}[] = {"; \
 		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
-		 echo "};") >>$@.new; \
+		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \
 		rm -f $*.bin; \
 	    done; \
 	)
@@ -165,7 +165,7 @@ $(addsuffix -opmask.h,$(OPMASK)): %.h: opmask.S testcase.mk Makefile
 		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
 		      "$${prefix}_$(arch)$${flavor}[] = {"; \
 		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
-		 echo "};") >>$@.new; \
+		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \
 		rm -f $*.bin; \
 	    done; \
 	)
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [Xen-devel] [PATCH] tests/x86emul: Annotate test blobs as executable code
  2019-05-24 15:15 [PATCH] tests/x86emul: Annotate test blobs as executable code Andrew Cooper
@ 2019-05-24 15:15 ` Andrew Cooper
  2019-05-24 15:50 ` Jan Beulich
  1 sibling, 0 replies; 7+ messages in thread
From: Andrew Cooper @ 2019-05-24 15:15 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné

This causes objdump to disassemble them, rather than rendering them as
straight hex data.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 tools/tests/x86_emulator/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/tests/x86_emulator/Makefile b/tools/tests/x86_emulator/Makefile
index 970ec3e..b54603d 100644
--- a/tools/tests/x86_emulator/Makefile
+++ b/tools/tests/x86_emulator/Makefile
@@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
 		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
 		      "$${prefix}_$(arch)$${flavor}[] = {"; \
 		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
-		 echo "};") >>$@.new; \
+		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \
 		rm -f $*.bin; \
 	    done; \
 	)
@@ -165,7 +165,7 @@ $(addsuffix -opmask.h,$(OPMASK)): %.h: opmask.S testcase.mk Makefile
 		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
 		      "$${prefix}_$(arch)$${flavor}[] = {"; \
 		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
-		 echo "};") >>$@.new; \
+		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \
 		rm -f $*.bin; \
 	    done; \
 	)
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] tests/x86emul: Annotate test blobs as executable code
  2019-05-24 15:15 [PATCH] tests/x86emul: Annotate test blobs as executable code Andrew Cooper
  2019-05-24 15:15 ` [Xen-devel] " Andrew Cooper
@ 2019-05-24 15:50 ` Jan Beulich
  2019-05-24 15:50   ` [Xen-devel] " Jan Beulich
  1 sibling, 1 reply; 7+ messages in thread
From: Jan Beulich @ 2019-05-24 15:50 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne

>>> On 24.05.19 at 17:15, <andrew.cooper3@citrix.com> wrote:
> --- a/tools/tests/x86_emulator/Makefile
> +++ b/tools/tests/x86_emulator/Makefile
> @@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
>  		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
>  		      "$${prefix}_$(arch)$${flavor}[] = {"; \
>  		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
> -		 echo "};") >>$@.new; \
> +		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \

Hmm, this seems risky to me - I'd expect a decent compiler to mark
them as STT_OBJECT, and a decent assembler to choke on finding
disagreeing .type directives for the same symbol. Current binutils
looks to simply OR together all the values, and then decide in an
adhoc sequence which type to actually emit:

      if ((flags & BSF_THREAD_LOCAL) != 0)
	type = STT_TLS;
      else if ((flags & BSF_GNU_INDIRECT_FUNCTION) != 0)
	type = STT_GNU_IFUNC;
      else if ((flags & BSF_FUNCTION) != 0)
	type = STT_FUNC;
      else if ((flags & BSF_OBJECT) != 0)
	type = STT_OBJECT;
      else if ((flags & BSF_RELC) != 0)
	type = STT_RELC;
      else if ((flags & BSF_SRELC) != 0)
	type = STT_SRELC;
      else
	type = STT_NOTYPE;

I don't think that's sane behavior (albeit it guarantees @function to
win over @object), and hence I'd say it can change at any time.

I wanted to suggest forcing the type change via objcopy, but to
my surprise I couldn't find a respective option.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Xen-devel] [PATCH] tests/x86emul: Annotate test blobs as executable code
  2019-05-24 15:50 ` Jan Beulich
@ 2019-05-24 15:50   ` Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2019-05-24 15:50 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne

>>> On 24.05.19 at 17:15, <andrew.cooper3@citrix.com> wrote:
> --- a/tools/tests/x86_emulator/Makefile
> +++ b/tools/tests/x86_emulator/Makefile
> @@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
>  		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
>  		      "$${prefix}_$(arch)$${flavor}[] = {"; \
>  		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
> -		 echo "};") >>$@.new; \
> +		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \

Hmm, this seems risky to me - I'd expect a decent compiler to mark
them as STT_OBJECT, and a decent assembler to choke on finding
disagreeing .type directives for the same symbol. Current binutils
looks to simply OR together all the values, and then decide in an
adhoc sequence which type to actually emit:

      if ((flags & BSF_THREAD_LOCAL) != 0)
	type = STT_TLS;
      else if ((flags & BSF_GNU_INDIRECT_FUNCTION) != 0)
	type = STT_GNU_IFUNC;
      else if ((flags & BSF_FUNCTION) != 0)
	type = STT_FUNC;
      else if ((flags & BSF_OBJECT) != 0)
	type = STT_OBJECT;
      else if ((flags & BSF_RELC) != 0)
	type = STT_RELC;
      else if ((flags & BSF_SRELC) != 0)
	type = STT_SRELC;
      else
	type = STT_NOTYPE;

I don't think that's sane behavior (albeit it guarantees @function to
win over @object), and hence I'd say it can change at any time.

I wanted to suggest forcing the type change via objcopy, but to
my surprise I couldn't find a respective option.

Jan



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Xen-devel] [PATCH] tests/x86emul: Annotate test blobs as executable code
  2019-08-02 18:31 ` Andrew Cooper
@ 2019-08-05  9:01   ` Jan Beulich
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Beulich @ 2019-08-05  9:01 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monné

On 02.08.2019 20:31, Andrew Cooper wrote:
> On 03/07/2019 11:47, Jan Beulich wrote:
>>>>> On 24.05.19 at 17:15, <andrew.cooper3@citrix.com> wrote:
>>> --- a/tools/tests/x86_emulator/Makefile
>>> +++ b/tools/tests/x86_emulator/Makefile
>>> @@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
>>>   		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
>>>   		      "$${prefix}_$(arch)$${flavor}[] = {"; \
>>>   		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
>>> -		 echo "};") >>$@.new; \
>>> +		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \
>> While I think we've sufficiently agreed on future gas behavior
>> that I'd consider this change fine to make as long as you add
>> an intermediate step going through STT_NOTYPE, I'd like to note
>> that your mileage from this will only be about 50%: While the
>> 64-bit blobs will disassemble fine, I'm afraid the 32-bit ones
>> will be somewhat garbled. Sadly there's no annotation or alike
>> (like Arm's mapping symbols) that one could use to make
>> disassemblers switch bitness for separate blocks of code.
> 
> Thats fine.
> 
> Disassembling twice, once with -mi386 works well, as the symbol names
> still get emitted sensibly.  I even use -m i8086 for bits of Xen's
> trampoline.
> 
> Its rare to need to look at a different disassembly, but its very easy
> to do so if you need to.
> 
> Can I take this reply as an ack for using the STT_NOTYPE intermediate step?

Yes - sorry for not being explicit in this regard.

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Xen-devel] [PATCH] tests/x86emul: Annotate test blobs as executable code
  2019-07-03 10:47 Jan Beulich
@ 2019-08-02 18:31 ` Andrew Cooper
  2019-08-05  9:01   ` Jan Beulich
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Cooper @ 2019-08-02 18:31 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel, Wei Liu, Roger Pau Monné

On 03/07/2019 11:47, Jan Beulich wrote:
>>>> On 24.05.19 at 17:15, <andrew.cooper3@citrix.com> wrote:
>> --- a/tools/tests/x86_emulator/Makefile
>> +++ b/tools/tests/x86_emulator/Makefile
>> @@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
>>  		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
>>  		      "$${prefix}_$(arch)$${flavor}[] = {"; \
>>  		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
>> -		 echo "};") >>$@.new; \
>> +		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \
> While I think we've sufficiently agreed on future gas behavior
> that I'd consider this change fine to make as long as you add
> an intermediate step going through STT_NOTYPE, I'd like to note
> that your mileage from this will only be about 50%: While the
> 64-bit blobs will disassemble fine, I'm afraid the 32-bit ones
> will be somewhat garbled. Sadly there's no annotation or alike
> (like Arm's mapping symbols) that one could use to make
> disassemblers switch bitness for separate blocks of code.

Thats fine.

Disassembling twice, once with -mi386 works well, as the symbol names
still get emitted sensibly.  I even use -m i8086 for bits of Xen's
trampoline.

Its rare to need to look at a different disassembly, but its very easy
to do so if you need to.

Can I take this reply as an ack for using the STT_NOTYPE intermediate step?

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Xen-devel] [PATCH] tests/x86emul: Annotate test blobs as executable code
@ 2019-07-03 10:47 Jan Beulich
  2019-08-02 18:31 ` Andrew Cooper
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Beulich @ 2019-07-03 10:47 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monné

>>> On 24.05.19 at 17:15, <andrew.cooper3@citrix.com> wrote:
> --- a/tools/tests/x86_emulator/Makefile
> +++ b/tools/tests/x86_emulator/Makefile
> @@ -149,7 +149,7 @@ $(addsuffix .h,$(TESTCASES)): %.h: %.c testcase.mk Makefile
>  		(echo 'static const unsigned int __attribute__((section(".test, \"ax\", @progbits #")))' \
>  		      "$${prefix}_$(arch)$${flavor}[] = {"; \
>  		 od -v -t x $*.bin | sed -e 's/^[0-9]* /0x/' -e 's/ /, 0x/g' -e 's/$$/,/'; \
> -		 echo "};") >>$@.new; \
> +		 echo "}; asm(\".type $${prefix}_$(arch)$${flavor}, STT_FUNC;\");") >>$@.new; \

While I think we've sufficiently agreed on future gas behavior
that I'd consider this change fine to make as long as you add
an intermediate step going through STT_NOTYPE, I'd like to note
that your mileage from this will only be about 50%: While the
64-bit blobs will disassemble fine, I'm afraid the 32-bit ones
will be somewhat garbled. Sadly there's no annotation or alike
(like Arm's mapping symbols) that one could use to make
disassemblers switch bitness for separate blocks of code.

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-08-05  9:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 15:15 [PATCH] tests/x86emul: Annotate test blobs as executable code Andrew Cooper
2019-05-24 15:15 ` [Xen-devel] " Andrew Cooper
2019-05-24 15:50 ` Jan Beulich
2019-05-24 15:50   ` [Xen-devel] " Jan Beulich
2019-07-03 10:47 Jan Beulich
2019-08-02 18:31 ` Andrew Cooper
2019-08-05  9:01   ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).