Bug 84288 - Support jit on Solaris
Summary: Support jit on Solaris
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: jit (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: David Malcolm
URL:
Keywords:
Depends on: 84379
Blocks:
  Show dependency treegraph
 
Reported: 2018-02-08 15:33 UTC by Rainer Orth
Modified: 2021-05-04 12:31 UTC (History)
0 users

See Also:
Host: *-*-solaris2.*
Target: *-*-solaris2.*
Build: *-*-solaris2.*
Known to work:
Known to fail:
Last reconfirmed: 2018-02-15 00:00:00


Attachments
Initial hacky patch (1.73 KB, patch)
2018-02-08 15:33 UTC, Rainer Orth
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Orth 2018-02-08 15:33:23 UTC
Created attachment 43373 [details]
Initial hacky patch

I just tried building mainline on Solaris (i386-pc-solaris2.11, but the issues
are most likely independent of the actual OS version) and ran into a couple of
issues:

* Solaris ld doesn't support --version-script.  However, the version script
  used for libgccjit.so, doesn't use any gld extensions, so one can just use
  -M instead.  I've added code to gcc/configure.ac to detect the proper option
  to use.

* Compilation failed here:

/vol/gcc/src/hg/trunk/local/gcc/jit/jit-playback.c: In member function 'void gcc::jit::playback::compile_to_file::copy_file(const char*, const char*)':
/vol/gcc/src/hg/trunk/local/gcc/jit/jit-playback.c:2111:25: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'std::size_t' {aka 'unsigned int'} [-Werror=format=]
     get_logger ()->log ("total bytes copied: %ld", total_sz_out);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~  ~~~~~~~~~~~~

  Fixed by casting total_sz_out to long.

* Solaris ld doesn't support --export-dynamic (and doesn't need it; ld behaves
  like the option is on out of the box).  Instead of configuring that, I chose
  to just use -rdynamic in jit.exp instead.

* If DejaGnu is installed into a non-system directory, dejagnu.h isn't found
  compiling the tests.  I've hacked around this by hardcoding a matching -I
  option in jit.exp.

* With DejaGnu 1.6.1, all tests FAIL like this:

/vol/gcc/include/dejagnu.h:43:12: error: 'xpassed' defined but not used [-Werror=unused-variable]
cc1: all warnings being treated as errors

  xpassed is only used in the C++ part of dejagnu.h.  This problem is still
  present in the current git master.  Wrapped in #ifdef __cplusplus in the 
  local copy for now.

* A couple of tests FAIL like this:

	FAILED: test-combination.c.exe iteration 1 of 5: make_tests_of_ptr_constants: actual: "(void *)deadbeef" != expected: "(void *)0xdeadbeef"
incorrect valuen
FAIL:  test-combination.c.exe iteration 1 of 5: make_tests_of_ptr_constants: actual: "(void *)deadbeef" != expected: "(void *)0xdeadbeef"

  The problem is that Solaris libc doesn't prefix pointers with 0x.  For the 
  moment, I've hacked around this with code inside __sun__ && __svr4__.  The
  proper way could be to introduce config/xm-sol2.h defining HOST_PTR_PRINTF
  and using that where appropriate.

* When gcc is configured with Solaris as and ld, a couple of tests FAIL like
  this:

	NOTE: test-compile-to-assembler.c.exe iteration 2 of 5: writing reproducer to ./test-compile-to-assembler.c.exe.reproducer.c
./test-compile-to-assembler.c.exe: error: in get, at cgraph.h:404
0xfcfd4d3a symtab_node::get(tree_node const*)
	/vol/gcc/src/hg/trunk/local/gcc/cgraph.h:401
0xfcfd4d3a decl_comdat_group(tree_node const*)
	/vol/gcc/src/hg/trunk/local/gcc/tree.c:708
0xfd0ce378 solaris_define_comdat_signature(comdat_entry**, void*)
	/vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:267
0xfd0ce6d6 void hash_table<comdat_entry_hasher, xcallocator>::traverse_noresize<void*, &(solaris_define_comdat_signature(comdat_entry**, void*))>(void*)
	/vol/gcc/src/hg/trunk/local/gcc/hash-table.h:969
0xfd0ce6d6 void hash_table<comdat_entry_hasher, xcallocator>::traverse<void*, &(solaris_define_comdat_signature(comdat_entry**, void*))>(void*)
	/vol/gcc/src/hg/trunk/local/gcc/hash-table.h:990
0xfd0ce6d6 solaris_file_end()
	/vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:291
[...]
FAIL: test-compile-to-assembler.c.exe: non-zero exit code: 7862 exp9 0 4


#0  0xfc2befe0 in exit () from /lib/libc.so.1
#1  0xfded54b5 in diagnostic_action_after_output (
    context=0xfe5df640 <global_diagnostic_context>, diag_kind=DK_ICE)
    at /vol/gcc/src/hg/trunk/local/gcc/diagnostic.c:533
#2  0xfded5e34 in diagnostic_report_diagnostic (context=<optimized out>, 
    diagnostic=<optimized out>)
    at /vol/gcc/src/hg/trunk/local/gcc/diagnostic.c:995
#3  0xfded618b in diagnostic_impl (richloc=0xfeffd814, opt=-1, 
    gmsgid=0xfce827f4 "in %s, at %s:%d", ap=0xfeffd810, kind=DK_ICE)
    at /vol/gcc/src/hg/trunk/local/gcc/diagnostic.c:1108
#4  0xfded65e8 in internal_error (gmsgid=0xfce827f4 "in %s, at %s:%d")
    at /vol/gcc/src/hg/trunk/local/gcc/diagnostic.c:1434
#5  0xfded7296 in fancy_abort (
    file=0xfcac4170 "/vol/gcc/src/hg/trunk/local/gcc/cgraph.h", line=404, 
    function=0xfcac9a80 <_ZZN11symtab_node3getEPK9tree_nodeE12__FUNCTION__> "get") at /vol/gcc/src/hg/trunk/local/gcc/diagnostic.c:1500
#6  0xfd7d4d3b in symtab_node::get (decl=0xf8000000)
    at /vol/gcc/src/hg/trunk/local/gcc/tree.h:3502

  decl is

 <error_mark f8000000>

#7  decl_comdat_group(tree_node const*) [clone .cold.496] ()
    at /vol/gcc/src/hg/trunk/local/gcc/tree.c:708
#8  0xfd8ce379 in solaris_define_comdat_signature (slot=0x80b39fc, aux=0x0)
    at /vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:267
#9  0xfd8ce6d7 in hash_table<comdat_entry_hasher, xcallocator>::traverse_noresize<void*, &(solaris_define_comdat_signature(comdat_entry**, void*))> (
    argument=0x0, this=<optimized out>)
    at /vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:290
#10 hash_table<comdat_entry_hasher, xcallocator>::traverse<void*, &(solaris_define_comdat_signature(comdat_entry**, void*))> (argument=0x0, 
    this=<optimized out>) at /vol/gcc/src/hg/trunk/local/gcc/hash-table.h:990
#11 solaris_file_end () at /vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:291
#12 0xfd469dcc in compile_file ()
    at /vol/gcc/src/hg/trunk/local/gcc/toplev.c:606
#13 0xfd46c4f3 in do_compile ()
    at /vol/gcc/src/hg/trunk/local/gcc/toplev.c:2081
#14 toplev::main(int, char**) ()
    at /vol/gcc/src/hg/trunk/local/gcc/toplev.c:2216
#15 0xfcedea7a in gcc::jit::playback::context::compile (this=0xfeffdad0)
    at /vol/gcc/src/hg/trunk/local/gcc/jit/jit-playback.c:1840
#16 0xfced2880 in gcc::jit::recording::context::compile_to_file (
    this=0x8069170, output_kind=GCC_JIT_OUTPUT_KIND_ASSEMBLER, 
    output_path=0x805180c "output-of-test-compile-to-assembler.c.s")
    at /vol/gcc/src/hg/trunk/local/gcc/jit/jit-recording.c:1384
#17 0xfcec6642 in gcc_jit_context_compile_to_file (ctxt=0x8069170, 
    output_kind=GCC_JIT_OUTPUT_KIND_ASSEMBLER, 
    output_path=0x805180c "output-of-test-compile-to-assembler.c.s")
    at /vol/gcc/src/hg/trunk/local/gcc/jit/libgccjit.c:2712
#18 0x080524c9 in test_jit (
    argv0=0xfeffdd3e "/var/gcc/regression/trunk/11.4-gcc/build.jit/gcc/testsuite/jit/test-compile-to-assembler.c.exe", user_data=0x0)
    at /vol/gcc/src/hg/trunk/local/gcc/testsuite/jit.dg/harness.h:364
#19 0x080525d9 in main (argc=1, argv=0xfeffdc0c)
    at /vol/gcc/src/hg/trunk/local/gcc/testsuite/jit.dg/harness.h:419

  Haven't yet started debugging how error_mark arrives there.

  When using gas/ld instead, the error isn't present.

* When using as and ld, there's one additional failure:

st-long-names.c.exe.reproducer.c
Input string too long, limit 10240
./test-long-names.c.exe: error: error invoking gcc driver
	FAILED: test-long-names.c.exe iteration 1 of 5: verify_code: result is NULL
FAIL:  test-long-names.c.exe iteration 1 of 5: verify_code: result is NULL
FAIL: test-long-names.c.exe killed: 7958 exp9 0 0 CHILDKILLED SIGABRT SIGABRT

  The "Input string too long, limit 10240" message is from as.  One could either
  xfail the test in this case or reduce NAME_LENGTH appropriately.

* In the 32-bit case, two tests FAIL like this:

	PASSED: test-vector-rvalues.cc.exe iteration 1 of 5: verify_vec_code: fn is non-null
	FAILED: test-vector-rvalues.cc.exe iteration 1 of 5: check_div: actual: c[i] != expected: a[i] / b[i]
incorrect value

        FAILED: test-vector-rvalues.cc.exe iteration 1 of 5: check_div: actual: c[i] != expected: a[i] / b[i]
incorrect value

#0  0xfc2cb64d in abort () from /lib/libc.so.1
#1  0x080544b2 in check_div<float __vector(4)>(float __vector(4) const&, float __vector(4) const&, float __vector(4) const&) (a=..., b=..., c=...)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/test-vector-rvalues.cc:165

165         CHECK_VALUE (c[i], a[i] / b[i]);
(gdb) p c[i]
$1 = 0.416666657
(gdb) p a[i]
$2 = 5
(gdb) p b[i]
$3 = 12

  probably needs to be CHECK_DOUBLE_VALUE instead

#2  0x08054297 in verify_vec_code<float __vector(4), float>(gcc_jit_context*, gcc_jit_result*, char const*, void (*)(float __vector(4) const&, float __vector(4) const&, float __vector(4) const&)) (ctxt=0x806f6b0, result=0x80c9870, 
    fnname=0x80524f5 "jit_v4f_div", 
    check_cb=0x805440b <check_div<float __vector(4)>(float __vector(4) const&, float __vector(4) const&, float __vector(4) const&)>)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/test-vector-rvalues.cc:191
#3  0x08053861 in verify_code (ctxt=0x806f6b0, result=0x80c9870)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/test-vector-rvalues.cc:210
#4  0x0805323a in test_jit (
    argv0=0xfeffdfc8 "/var/gcc/regression/trunk/11.4-gcc-gas/build/gcc/testsuite/jit/test-vector-rvalues.cc.exe", user_data=0x0)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/harness.h:373
#5  0x0805330f in main (argc=1, argv=0xfeffde94)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/harness.h:419

PASS:  test-vector-rvalues.cc.exe iteration 1 of 5: verify_vec_code: fn is non-null
FAIL:  test-vector-rvalues.cc.exe iteration 1 of 5: check_div: actual: c
FAIL: test-vector-rvalues.cc.exe killed: 23396 exp9 0 0 CHILDKILLED SIGABRT SIGABRT

        FAILED: test-vector-types.cc.exe iteration 1 of 5: check_div: actual: c[i] != expected: a[i] / b[i]
incorrect value

#0  0xfc2cb64d in abort () from /lib/libc.so.1
#1  0x0805427c in check_div<float __vector(4)>(float __vector(4) const&, float __vector(4) const&, float __vector(4) const&) (a=..., b=..., c=...)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/test-vector-types.cc:139
#2  0x08054061 in verify_vec_code<float __vector(4)>(gcc_jit_context*, gcc_jit_result*, char const*, void (*)(float __vector(4) const&, float __vector(4) const&, float __vector(4) const&)) (ctxt=0x806f470, result=0x80c5448, 
    fnname=0x8052432 "jit_v4f_div", 
    check_cb=0x80541d5 <check_div<float __vector(4)>(float __vector(4) const&, float __vector(4) const&, float __vector(4) const&)>)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/test-vector-types.cc:165
#3  0x08053673 in verify_code (ctxt=0x806f470, result=0x80c5448)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/test-vector-types.cc:184
#4  0x0805315a in test_jit (
    argv0=0xfeffdfd0 "/var/gcc/regression/trunk/11.4-gcc-gas/build/gcc/testsuite/jit/test-vector-types.cc.exe", user_data=0x0)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/harness.h:373
#5  0x0805322f in main (argc=1, argv=0xfeffde9c)
    at /vol/gcc/src/hg/trunk/solaris/gcc/testsuite/jit.dg/harness.h:419

  ISTM that check_div needs to use CHECK_DOUBLE_VALUE here.

* libgccjit.so is only built for the default multilib.  If running make check
  across all multilibs, all tests for the non-default multilibs (like the 64-bit
  ones when testing on i386-pc-solaris2.11) will FAIL.  Since one probably 
  doesn't want to build libgccjit.so for those multilibs, too, jit.exp needs
  to skip them to avoid tons of testsuite noise.

Overall, results aren't too bad for a first attempt.
Comment 1 David Malcolm 2018-02-13 21:39:15 UTC
Candidate patch for the linker issue:
  https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00776.html
Comment 2 ro@CeBiTec.Uni-Bielefeld.DE 2018-02-14 15:14:21 UTC
> * If DejaGnu is installed into a non-system directory, dejagnu.h isn't found
>   compiling the tests.  I've hacked around this by hardcoding a matching -I
>   option in jit.exp.

  I believe this should be handled like GMPINC: gcc/configure.ac gains an
  --with-dejagnu option which ultimately sets DEJAGNUINC, that's emitted
  to site.exp in gcc/Makefile.in so gcc/testsuite/jit.dg/jit.exp can
  use it.

> * When gcc is configured with Solaris as and ld, a couple of tests FAIL like
>   this:
>
>         NOTE: test-compile-to-assembler.c.exe iteration 2 of 5: writing
> reproducer to ./test-compile-to-assembler.c.exe.reproducer.c
> ./test-compile-to-assembler.c.exe: error: in get, at cgraph.h:404
> 0xfcfd4d3a symtab_node::get(tree_node const*)
>         /vol/gcc/src/hg/trunk/local/gcc/cgraph.h:401
> 0xfcfd4d3a decl_comdat_group(tree_node const*)
>         /vol/gcc/src/hg/trunk/local/gcc/tree.c:708
> 0xfd0ce378 solaris_define_comdat_signature(comdat_entry**, void*)
>         /vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:267
> 0xfd0ce6d6 void hash_table<comdat_entry_hasher,
> xcallocator>::traverse_noresize<void*,
> &(solaris_define_comdat_signature(comdat_entry**, void*))>(void*)
>         /vol/gcc/src/hg/trunk/local/gcc/hash-table.h:969
> 0xfd0ce6d6 void hash_table<comdat_entry_hasher, xcallocator>::traverse<void*,
> &(solaris_define_comdat_signature(comdat_entry**, void*))>(void*)
>         /vol/gcc/src/hg/trunk/local/gcc/hash-table.h:990
> 0xfd0ce6d6 solaris_file_end()
>         /vol/gcc/src/hg/trunk/local/gcc/config/sol2.c:291
> [...]
> FAIL: test-compile-to-assembler.c.exe: non-zero exit code: 7862 exp9 0 4
[...]
>   Haven't yet started debugging how error_mark arrives there.

  That those errors only happen during the second iteration seems to
  point at a GC issue.  In fact, there are problems here, cf. PR
  other/84379), but no solution so far.
Comment 3 Rainer Orth 2018-02-15 17:50:59 UTC
I've now developed a patch for PR target/84379 that cures the GC-related failures
described before.
Comment 4 Rainer Orth 2018-02-15 19:47:41 UTC
(In reply to Rainer Orth from comment #0)
[...]
> * In the 32-bit case, two tests FAIL like this:
> 
> 	PASSED: test-vector-rvalues.cc.exe iteration 1 of 5: verify_vec_code: fn is
> non-null
> 	FAILED: test-vector-rvalues.cc.exe iteration 1 of 5: check_div: actual:
> c[i] != expected: a[i] / b[i]
> incorrect value
[...]
>         FAILED: test-vector-types.cc.exe iteration 1 of 5: check_div:
> actual: c[i] != expected: a[i] / b[i]
> incorrect value
[...]
>   ISTM that check_div needs to use CHECK_DOUBLE_VALUE here.

I've just run an i686-pc-linux-gnu build and see exactly the same errors.  So this
seems to be a 32-bit (or 32-bit x86) issue.
Comment 5 David Malcolm 2018-03-09 15:25:17 UTC
Author: dmalcolm
Date: Fri Mar  9 15:24:44 2018
New Revision: 258388

URL: https://gcc.gnu.org/viewcvs?rev=258388&root=gcc&view=rev
Log:
jit: use 'configure' to replace hard-coded linker options (PR jit/64089 and PR jit/84288)

gcc/ChangeLog:
	PR jit/64089
	PR jit/84288
	* Makefile.in (LD_VERSION_SCRIPT_OPTION, LD_SONAME_OPTION): New.
	* configure: Regenerate.
	* configure.ac ("linker --version-script option"): New.
	("linker soname option"): New.

gcc/jit/ChangeLog:
	PR jit/64089
	PR jit/84288
	* Make-lang.in (COMMA): New.
	(LIBGCCJIT_VERSION_SCRIPT_OPTION): New.
	(LIBGCCJIT_SONAME_OPTION): New.
	(jit): Move --version-script and -soname linker options to the
	above.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/configure
    trunk/gcc/configure.ac
    trunk/gcc/jit/ChangeLog
    trunk/gcc/jit/Make-lang.in
Comment 6 David Malcolm 2018-03-09 15:31:30 UTC
I'm not sure if r258388 fixes the linker issue on Solaris, but it should make it much easier to fix; e.g. to apply your patch here:
  https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00835.html
(currently reported as untested)
Comment 7 ro@CeBiTec.Uni-Bielefeld.DE 2018-03-20 08:41:52 UTC
> --- Comment #6 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
> I'm not sure if r258388 fixes the linker issue on Solaris, but it should make
> it much easier to fix; e.g. to apply your patch here:
>   https://gcc.gnu.org/ml/gcc-patches/2018-02/msg00835.html
> (currently reported as untested)

It did indeed, as I've now found out:

	https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00925.html

There are a couple more issues to address, but we're getting there :-)

Thanks.
        Rainer
Comment 8 Rainer Orth 2018-03-21 17:39:48 UTC
Author: ro
Date: Wed Mar 21 17:39:16 2018
New Revision: 258727

URL: https://gcc.gnu.org/viewcvs?rev=258727&root=gcc&view=rev
Log:
Enable jit on Solaris: soname option and EXTRA_GCC_LIBS (PR jit/84288)

	gcc/jit:
	PR jit/84288
	* Make-lang.in ($(LIBGCCJIT_FILENAME)): Add $(EXTRA_GCC_LIBS).

	gcc:
	PR jit/84288
	* configure.ac (gcc_cv_ld_soname) <*-*-solaris2*>: Set.
	* configure: Regenerate.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/configure   (contents, props changed)
    trunk/gcc/configure.ac
    trunk/gcc/jit/ChangeLog
    trunk/gcc/jit/Make-lang.in
Comment 9 Martin Liška 2018-11-20 08:15:42 UTC
Rainer: Can the bug be marked as resolved?
Comment 10 ro@CeBiTec.Uni-Bielefeld.DE 2018-11-20 12:44:07 UTC
> --- Comment #9 from Martin Liška <marxin at gcc dot gnu.org> ---
> Rainer: Can the bug be marked as resolved?

No, there are quite a number of issues still open:

* the total_sz_out printing,

* hardcoded gld-specific options in jit.exp

* finding dejagnu.h in non-system directories

* dejagnu.h vs. C++

* does %p format include "0x" or not?

* skipping jit.dg for non-default multilib

and probably more.

It seems your check for PRs where patches have been committed is too
simplistic...