public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] testsuite, JIT, Darwin: Adjust asm tests for Mach-O.
@ 2021-08-18 19:45 Iain Sandoe
  2021-08-18 22:44 ` David Malcolm
  0 siblings, 1 reply; 2+ messages in thread
From: Iain Sandoe @ 2021-08-18 19:45 UTC (permalink / raw)
  To: GCC Patches

Hi,

This provides adjusted assembler fragments that are suitable
for x86_64 Mach-O.

** as an aside, I wonder if it would be possible to configure some
   conditional on __ELF__, __MACH__, and CPU arch to pull in some
   object-cpu.inc so that we can generalize this for all hosts.

this version tested on x86_64-darwin, x86_64-linux,
OK for master?
thanks
Iain

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

gcc/testsuite/ChangeLog:

	* jit.dg/test-asm.c: Provide Mach-O fragment.
	* jit.dg/test-asm.cc: Likewise.
---
 gcc/testsuite/jit.dg/test-asm.c  | 13 +++++++++++++
 gcc/testsuite/jit.dg/test-asm.cc | 12 ++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/gcc/testsuite/jit.dg/test-asm.c b/gcc/testsuite/jit.dg/test-asm.c
index 35a9f9d8605..43255dc7561 100644
--- a/gcc/testsuite/jit.dg/test-asm.c
+++ b/gcc/testsuite/jit.dg/test-asm.c
@@ -438,6 +438,18 @@ verify_code_4 (gcc_jit_context *ctxt, gcc_jit_result *result)
 static void
 create_test_i386_basic_asm_5 (gcc_jit_context *ctxt)
 {
+#if __APPLE__
+  /* Darwin's assemblers do not support push/pop section, do not use .type
+     and external symbols should use __USER_LABEL_PREFIX__.  */
+  gcc_jit_context_add_top_level_asm (ctxt, NULL,
+                                     "\t.text\n"
+                                     "\t.globl _add_asm\n"
+                                     "_add_asm:\n"
+                                     "\tmovq %rdi, %rax\n"
+                                     "\tadd %rsi, %rax\n"
+                                     "\tret\n"
+                                     "\t# some asm here\n");
+#else
   /* Quote from here in docs/topics/asm.rst: example 5: jit.  */
   gcc_jit_context_add_top_level_asm (ctxt, NULL,
                                      "\t.pushsection .text\n"
@@ -450,6 +462,7 @@ create_test_i386_basic_asm_5 (gcc_jit_context *ctxt)
                                      "\t# some asm here\n"
                                      "\t.popsection\n");
   /* Quote up to here in docs/topics/asm.rst: example 5: jit.  */
+#endif
 }
 
 static void
diff --git a/gcc/testsuite/jit.dg/test-asm.cc b/gcc/testsuite/jit.dg/test-asm.cc
index be487e3fb69..a3b45dacf07 100644
--- a/gcc/testsuite/jit.dg/test-asm.cc
+++ b/gcc/testsuite/jit.dg/test-asm.cc
@@ -400,6 +400,17 @@ static void
 create_test_i386_basic_asm_5 (gcc_jit_context *c_ctxt)
 {
   gccjit::context ctxt (c_ctxt);
+#if __APPLE__
+  /* Darwin's assemblers do not support push/pop section, do not use .type
+     and external symbols should use __USER_LABEL_PREFIX__.  */
+  ctxt.add_top_level_asm ("\t.text\n"
+                          "\t.globl _add_asm\n"
+                          "_add_asm:\n"
+                          "\tmovq %rdi, %rax\n"
+                          "\tadd %rsi, %rax\n"
+                          "\tret\n"
+                          "\t# some asm here\n");
+#else
   /* Quote from here in docs/cp/topics/asm.rst: example 5: jit.  */
   ctxt.add_top_level_asm ("\t.pushsection .text\n"
                           "\t.globl add_asm\n"
@@ -411,6 +422,7 @@ create_test_i386_basic_asm_5 (gcc_jit_context *c_ctxt)
                           "\t# some asm here\n"
                           "\t.popsection\n");
   /* Quote up to here in docs/cp/topics/asm.rst: example 5: jit.  */
+#endif
 }
 
 static void
-- 
2.24.3 (Apple Git-128)


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

* Re: [PATCH] testsuite, JIT, Darwin: Adjust asm tests for Mach-O.
  2021-08-18 19:45 [PATCH] testsuite, JIT, Darwin: Adjust asm tests for Mach-O Iain Sandoe
@ 2021-08-18 22:44 ` David Malcolm
  0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2021-08-18 22:44 UTC (permalink / raw)
  To: Iain Sandoe, GCC Patches

On Wed, 2021-08-18 at 20:45 +0100, Iain Sandoe wrote:
> Hi,
> 
> This provides adjusted assembler fragments that are suitable
> for x86_64 Mach-O.
> 
> ** as an aside, I wonder if it would be possible to configure some
>    conditional on __ELF__, __MACH__, and CPU arch to pull in some
>    object-cpu.inc so that we can generalize this for all hosts.

I don't know how far I want to go down this route - the purpose of the
tests is to verify that the API works, analogously to inline asm in a C
source file, but the asm fragments are always going to be very target-
dependent, given that it's asm, and probably rather host-dependent.  I
took the easy way out by getting the tests working on x86_64-pc-linux-
gnu (host and target), and (ahem) hoping nothing else was too badly
broken.  Sorry about that.

If there's a simple way to clean it up that would be great.

Note that the functions in the testcase code are also included by the
Sphinx documentation as examples of API usage (see the asm.rst
references in comments) - though for some reason that doesn't seem to
be working in the built HTML docs on gcc.gnu.org.

> 
> this version tested on x86_64-darwin, x86_64-linux,
> OK for master?

The patch as-is looks OK to me.
Dave




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

end of thread, other threads:[~2021-08-18 22:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-18 19:45 [PATCH] testsuite, JIT, Darwin: Adjust asm tests for Mach-O Iain Sandoe
2021-08-18 22:44 ` David Malcolm

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 read-only IMAP folder(s) and NNTP newsgroup(s).