Bug 64810 - jit not working on armv7hl ("ld: error: /tmp/libgccjit-ZGemdr/fake.so uses VFP register arguments, /tmp/ccJFCBsE.o does not")
Summary: jit not working on armv7hl ("ld: error: /tmp/libgccjit-ZGemdr/fake.so uses VF...
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: jit (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: David Malcolm
URL:
Keywords:
: 64873 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-01-27 01:20 UTC by David Malcolm
Modified: 2018-11-19 13:26 UTC (History)
2 users (show)

See Also:
Host: armv7hl-redhat-linux-gnueabi
Target: armv7hl-redhat-linux-gnueabi
Build: armv7hl-redhat-linux-gnueabi
Known to work:
Known to fail:
Last reconfirmed: 2015-01-27 00:00:00


Attachments
WIP patch to inject configure-time options into jit's toplev::main (no ChangeLog yet) (1.40 KB, patch)
2015-01-28 21:30 UTC, David Malcolm
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Malcolm 2015-01-27 01:20:05 UTC
Jakub did a test build of the jit on armv7hl-redhat-linux-gnueabi:
http://koji.fedoraproject.org/scratch/jakub/task_8710312/logs/armv7hl/build.log

All of the jit test logs show linker failures when creating the "fake.so", of the form:

	PASSED: test-hello-world.c.exe iteration 1 of 5: set_up_logging: logfile is non-null
PASS:  test-hello-world.c.exe iteration 1 of 5: set_up_logging: logfile is non-null
	NOTE: test-hello-world.c.exe iteration 1 of 5: writing reproducer to ./test-hello-world.c.exe.reproducer.c
ld: error: /tmp/libgccjit-ZGemdr/fake.so uses VFP register arguments, /tmp/ccJFCBsE.o does not
ld: failed to merge target specific data of file /tmp/ccJFCBsE.o
./test-hello-world.c.exe: error: error invoking gcc driver: exit_status: 256 err: 0
./test-hello-world.c.exe: error: whilst attempting to run a driver named: armv7hl-redhat-linux-gnueabi-gcc-5.0.0
./test-hello-world.c.exe: error: PATH was: /builddir/build/BUILD/gcc-5.0.0-20150123/obj-armv7hl-redhat-linux-gnueabi/gcc:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/builddir/.local/bin:/builddir/bin
	FAILED: test-hello-world.c.exe iteration 1 of 5: verify_code: result is NULL
FAIL:  test-hello-world.c.exe iteration 1 of 5: verify_code: result is NULL
FAIL: test-hello-world.c.exe killed: 526 exp7 0 0 CHILDKILLED SIGABRT SIGABRT
Comment 1 Ramana Radhakrishnan 2015-01-27 12:13:22 UTC
My first line of attack would be checking that while building up the jit, the jit configury and build system is not using the --with-float=hard and --with-fpu=vfpv3-d16 configure time option in some manner.
Comment 2 Jakub Jelinek 2015-01-27 12:27:02 UTC
Both the compiler and libgccjit were configured with:
--with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16 --with-abi=aapcs-linux
on the configure command line.  Perhaps some of these options are set for driver only (libgccjit presumably doesn't use any driver) and need to be passed explicitly to the compiler?
Comment 3 David Malcolm 2015-01-27 14:27:34 UTC
(In reply to Jakub Jelinek from comment #2)
> Both the compiler and libgccjit were configured with:
> --with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard
> --with-fpu=vfpv3-d16 --with-abi=aapcs-linux
> on the configure command line.  Perhaps some of these options are set for
> driver only (libgccjit presumably doesn't use any driver) and need to be
> passed explicitly to the compiler?

libgccjit *does* use the driver; the library runs toplev.c to generate a .s file, then invokes the driver to turn it into a .so file.  It looks like there's some kind of mismatch between these two things.

It looks like I'm going to need to get onto armvhl hw (or qemu) to investigate further.

Jakub: BTW, the jit testsuite does extra-verbose logging, beyond jit.log; in particular the arguments for both of the invocations above are logged to:
  gcc/testsuite/jit/*.log.txt
so if it's easy to hack up the specfile to stick these in the uuencoded logs, that might be beneficial.
Comment 4 ramana.radhakrishnan@arm.com 2015-01-27 15:46:53 UTC
On 27/01/15 12:27, jakub at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64810
>
> Jakub Jelinek <jakub at gcc dot gnu.org> changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                   CC|                            |jakub at gcc dot gnu.org
>
> --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> Both the compiler and libgccjit were configured with:
> --with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard
> --with-fpu=vfpv3-d16 --with-abi=aapcs-linux


The --with-abi=aapcs-linux in addition to the --with-float=hard argument 
is just wrong. In fact it allows for a case where if the order of 
command line arguments passed to the compiler if in some way is wrong, 
the code generated will force the compiler into passing floating point 
parameters through the integer registers rather than fp registers which 
is what the --with-float=hard configure time option is doing.

Really Fedora should remove this from the configure line as it only 
confuses people.

For the compiler built can you please post back the output is for a 
simple function that adds 2 float values and pushes it back up.

Ramana
Comment 5 David Malcolm 2015-01-27 18:47:57 UTC
FWIW I'm on an arm box now, and am able to reproduce this with:
 --enable-host-shared --enable-languages=jit,c++ --disable-bootstrap --enable-checking=release --with-float=hard

Am investigating.
Comment 6 David Malcolm 2015-01-27 19:40:49 UTC
I tried to configure the jit with just:
  --enable-host-shared --enable-languages=jit,c++ --disable-bootstrap --enable-checking=release

but I ran into this error compiling libgcc:
  /usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62099#c5
said:
     "You need to use -with-float=hard when configuring GCC."
hence I added --with-float=hard to the above when configuring.

Was this correct?

Doing so enabled the build to complete, and I was able to run "make check-jit", which showed the symptoms seen in comment #0.

Specifically, if I hack up gcc/testsuite/jit.dg/harness.h to add:
  gcc_jit_context_set_bool_option (
    ctxt,
    GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES,
    1);
and run e.g.
  make check-jit RUNTESTFLAGS="jit.exp=test-hello-world.c"
then gcc/testsuite/jit/test-hello-world.c.exe.log.txt shows that toplev is invoked thusly:
JIT:    entering: toplev::main
JIT:     argv[0]: ./test-hello-world.c.exe
JIT:     argv[1]: /tmp/libgccjit-KmhzbL/fake.c
JIT:     argv[2]: -fPIC
JIT:     argv[3]: -O3
JIT:     argv[4]: -g
JIT:     argv[5]: -quiet
JIT:     argv[6]: --param
JIT:     argv[7]: ggc-min-expand=0
JIT:     argv[8]: --param
JIT:     argv[9]: ggc-min-heapsize=0

and then the driver is invoked thus on the resulting .s file:
JIT:      entering: void gcc::jit::playback::context::invoke_driver(const char*, const char*, const char*, timevar_id_t, bool, bool)
JIT:       argv[0]: armv7l-unknown-linux-gnueabihf-gcc-5.0.0
JIT:       argv[1]: -shared
JIT:       argv[2]: /tmp/libgccjit-KmhzbL/fake.s
JIT:       argv[3]: -o
JIT:       argv[4]: /tmp/libgccjit-KmhzbL/fake.so
JIT:       argv[5]: -fno-use-linker-plugin
JIT:       argv[6]: (null)

(and the intermediates stay around due to the bool option above).

Invoking the driver by hand with those args replicates the issue:

$ LIBRARY_PATH=. ./armv7l-unknown-linux-gnueabihf-gcc-5.0.0 -shared /tmp/libgccjit-KmhzbL/fake.s -o /tmp/libgccjit-KmhzbL/fake.so -fno-use-linker-plugin
ld: error: /tmp/libgccjit-KmhzbL/fake.so uses VFP register arguments, /tmp/ccCFmkbn.o does not
ld: failed to merge target specific data of file /tmp/ccCFmkbn.o

Invoking the driver with "-v" shows the commands it's running:
  as -v -mfloat-abi=hard -meabi=5 -o /tmp/ccBPOxW0.o /tmp/libgccjit-KmhzbL/fake.s
GNU assembler version 2.24 (armv7hl-redhat-linux-gnueabi) using BFD version version 2.24

  ld --eh-frame-hdr -shared -dynamic-linker /lib/ld-linux-armhf.so.3 -X -m armelf_linux_eabi -o /tmp/libgccjit-KmhzbL/fake.so /lib/crti.o ./crtbeginS.o -L. /tmp/ccBPOxW0.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed ./crtendS.o /lib/crtn.o

/usr/bin/ld: error: /tmp/libgccjit-KmhzbL/fake.so uses VFP register arguments, /tmp/ccT3rLos.o does not
/usr/bin/ld: failed to merge target specific data of file /tmp/ccT3rLos.o

FWIW, eu-readelf on the .o file shows:

Object attributes section [16] '.ARM.attributes' of 47 bytes at offset 0x35b:
  Owner          Size
  aeabi            46
    File:          36
      CPU_name: ARM10TDMI
      CPU_arch: v5T
      ARM_ISA_use: Yes
      THUMB_ISA_use: Thumb-1
      ABI_FP_denormal: Needed
      ABI_FP_exceptions: Needed
      ABI_FP_number_model: IEEE 754
      ABI_align8_needed: Yes
      ABI_align8_preserved: Yes, except leaf SP
      ABI_enum_size: int
      ABI_optimization_goals: Aggressive Speed
Comment 7 David Malcolm 2015-01-27 20:00:41 UTC
(In reply to ramana.radhakrishnan@arm.com from comment #4)
> On 27/01/15 12:27, jakub at gcc dot gnu.org wrote:
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64810
> >
> > Jakub Jelinek <jakub at gcc dot gnu.org> changed:
> >
> >             What    |Removed                     |Added
> > ----------------------------------------------------------------------------
> >                   CC|                            |jakub at gcc dot gnu.org
> >
> > --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> > Both the compiler and libgccjit were configured with:
> > --with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard
> > --with-fpu=vfpv3-d16 --with-abi=aapcs-linux
> 
> 
> The --with-abi=aapcs-linux in addition to the --with-float=hard argument 
> is just wrong. In fact it allows for a case where if the order of 
> command line arguments passed to the compiler if in some way is wrong, 
> the code generated will force the compiler into passing floating point 
> parameters through the integer registers rather than fp registers which 
> is what the --with-float=hard configure time option is doing.
> 
> Really Fedora should remove this from the configure line as it only 
> confuses people.

Ramana: I'm sorry, I had trouble parsing your comment (e.g. which option were you referring to by "this" in the final sentence above).

What should I configure with when debugging this?
e.g. should I keep the --with-abi=aapcs-linux and lose the --with-float=hard?  should I be testing with the other options Jakub mentioned?  etc.

(Sorry about my ignorance here; I'm not particularly familiar with arm, and my test machine is slow which makes it difficult to exhaustively try every possibility).
Comment 8 ramana.radhakrishnan@arm.com 2015-01-28 09:36:21 UTC
On 27/01/15 20:00, dmalcolm at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64810
>
> --- Comment #7 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
> (In reply to ramana.radhakrishnan@arm.com from comment #4)
>> On 27/01/15 12:27, jakub at gcc dot gnu.org wrote:
>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64810
>>>
>>> Jakub Jelinek <jakub at gcc dot gnu.org> changed:
>>>
>>>              What    |Removed                     |Added
>>> ----------------------------------------------------------------------------
>>>                    CC|                            |jakub at gcc dot gnu.org
>>>
>>> --- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
>>> Both the compiler and libgccjit were configured with:
>>> --with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard
>>> --with-fpu=vfpv3-d16 --with-abi=aapcs-linux
>>
>>
>> The --with-abi=aapcs-linux in addition to the --with-float=hard argument
>> is just wrong. In fact it allows for a case where if the order of
>> command line arguments passed to the compiler if in some way is wrong,
>> the code generated will force the compiler into passing floating point
>> parameters through the integer registers rather than fp registers which
>> is what the --with-float=hard configure time option is doing.
>>
>> Really Fedora should remove this from the configure line as it only
>> confuses people.
>
> Ramana: I'm sorry, I had trouble parsing your comment (e.g. which option were
> you referring to by "this" in the final sentence above).


By "this" in the final sentence, I referred to the 
--with-abi=aapcs-linux option.


>
> What should I configure with when debugging this?
> e.g. should I keep the --with-abi=aapcs-linux and lose the --with-float=hard?
> should I be testing with the other options Jakub mentioned?  etc.

The architecture specific options that are commonly used for 
bootstrapping on ARM hard float are the following.

--with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16


>
> (Sorry about my ignorance here; I'm not particularly familiar with arm, and my
> test machine is slow which makes it difficult to exhaustively try every
> possibility).

No problem it's not an issue - there are quite a few options available 
so it's not easy to get the correct options sorted in the first instance.


Ramana
>
Comment 9 David Malcolm 2015-01-28 17:58:54 UTC
Thanks Ramana.

I attempted a build of the jit with the configuration you suggested,
specifically:

  $ ../src/configure \
      --enable-host-shared \
      --enable-languages=jit,c++ \
      --disable-bootstrap \
      --enable-checking=release \
      --prefix=/home/dmalcolm/gcc-git-jit/install-jit \
      --with-arch=armv7-a \
      --with-float=hard \
      --with-fpu=vfpv3-d16

Unfortunately, I see the same failures.

Hacking in a "-v" into the driver invocation in jit-playback.c...

diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
index d2549a0..5f570a7 100644
--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -2271,6 +2271,8 @@ invoke_driver (const char *ctxt_progname,
      time.  */
   ADD_ARG ("-fno-use-linker-plugin");

+  ADD_ARG ("-v");
+
   /* pex argv arrays are NULL-terminated.  */
   ADD_ARG (NULL);

...I see that libgccjit attempts to invoke the driver to convert the .s
to a .so, but it fails like so:

Target: armv7l-unknown-linux-gnueabihf
Configured with: ../src/configure --enable-host-shared --enable-languages=jit,c++ --disable-bootstrap --enable-checking=release --prefix=/home/dmalcolm/gcc-git-jit/install-jit --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16
Thread model: posix
gcc version 5.0.0 20150126 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-shared' '-o' '/tmp/libgccjit-VxeXM1/fake.so' '-fno-use-linker-plugin' '-v' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mtls-dialect=gnu'
 as -v -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o /tmp/ccCY7c5L.o /tmp/libgccjit-VxeXM1/fake.s
GNU assembler version 2.24 (armv7hl-redhat-linux-gnueabi) using BFD version version 2.24
COMPILER_PATH=
LIBRARY_PATH=/home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-shared' '-o' '/tmp/libgccjit-VxeXM1/fake.so' '-fno-use-linker-plugin' '-v' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mtls-dialect=gnu'
 ld --eh-frame-hdr -shared -dynamic-linker /lib/ld-linux-armhf.so.3 -X -m armelf_linux_eabi -o /tmp/libgccjit-VxeXM1/fake.so /lib/crti.o /home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc/crtbeginS.o -L/home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc /tmp/ccCY7c5L.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc/crtendS.o /lib/crtn.o
ld: error: /tmp/libgccjit-VxeXM1/fake.so uses VFP register arguments, /tmp/ccCY7c5L.o does not
ld: failed to merge target specific data of file /tmp/ccCY7c5L.o

That said, with the "test-empty.c" testcase, the generated
"fake.s" looks like this:

        .cpu arm10tdmi
        .fpu softvfp
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 2
        .eabi_attribute 34, 0
        .arm
        .syntax divided
        .file   "fake.c"
        .text
.Ltext0:
        .cfi_sections   .debug_frame
.Letext0:
        .section        .debug_line,"",%progbits
.Ldebug_line0:
        .section        .debug_str,"MS",%progbits,1
.LASF0:
        .ascii  "/tmp/libgccjit-La3Yzk/fake.c\000"
.LASF1:
        .ascii  "libgccjit 5.0.0 20150126 (experimental) -fPIC -O3 -"
        .ascii  "g --param ggc-min-expand=0 --param ggc-min-heapsize"
        .ascii  "=0\000"
        .ident  "GCC: (GNU) 5.0.0 20150126 (experimental)"
        .section        .note.GNU-stack,"",%progbits

In particular, I'm guessing that the line:
        .fpu softvfp
is at fault here.

This appears to come from arm.c:arm_file_start:
25689         if (TARGET_SOFT_FLOAT)
25690           {
25691             fpu_name = "softvfp";
25692           }
25693         else
and on debugging:
(gdb) p global_options.x_arm_float_abi
$1 = ARM_FLOAT_ABI_SOFT

Is this value bogus, given the configure-time options?

(if so, I'm guessing this is a jit-specific state-management issue)
Comment 10 David Malcolm 2015-01-28 18:20:51 UTC
Trying a hw watchpoint:
  (gdb) watch global_options.x_arm_float_abi
shows this is never touched within test-empty.c.exe

Invoking ./xgcc verbosely on an empty C file:

  $ ./xgcc -c -xc -v -B. -save-temps /dev/null

I note that ./cc1 and ./as are being invoked with various pertinent "-m" options:

./cc1 -fpreprocessed null.i -quiet -dumpbase null -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -mtls-dialect=gnu -auxbase null -version -o null.s


./as -v -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o null.o null.s


(e.g. -mfloat-abi=hard etc)

null.s looks like this:
        .arch armv7-a
        .eabi_attribute 28, 1
        .fpu vfpv3-d16
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 6
        .eabi_attribute 34, 1
        .eabi_attribute 18, 4
        .arm
        .syntax divided
        .file   "null"
        .ident  "GCC: (GNU) 5.0.0 20150126 (experimental)"
        .section        .note.GNU-stack,"",%progbits

Under non-jit operation the driver seems to invoking cc1 with -m options based on configure-time settings, whereas within the jit, jit-playback.c builds an argv for toplev::main analogous to invoking cc1, but doesn't attempt to inject these additional -m options, hence we get a bogus .fpu attribute, and indeed, the other settings are likely to be bogus also.
Comment 11 David Malcolm 2015-01-28 20:58:52 UTC
A breakpoint on "do_option_spec" in the driver shows that the options come from configure_default_options and option_default_specs.

configure_default_options comes from configargs.h, written out by gcc/configure(.ac) which seems to get configure_default_options from config.gcc (from ${t})

This would be easy to use, if only we could guarantee it was "-mKEY=VALUE", but it isn't; doing it naively the "obvious" way:

--- a/gcc/jit/jit-playback.c
+++ b/gcc/jit/jit-playback.c
@@ -63,6 +63,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "context.h"
 #include "fold-const.h"
 #include "debug.h"
+#include "configargs.h"

 #include "jit-common.h"
 #include "jit-logging.h"
@@ -2118,6 +2119,19 @@ make_fake_args (vec <char *> *argvec,
       }
   }

+  {
+    for (unsigned i = 0; i < ARRAY_SIZE (configure_default_options); i++)
+      {
+       char *arg = concat ("-m",
+                           configure_default_options[i].name,
+                           "=",
+                           configure_default_options[i].value,
+                           NULL);
+       ADD_ARG_TAKE_OWNERSHIP (arg);
+      }
+  }
+
 #undef ADD_ARG
 #undef ADD_ARG_TAKE_OWNERSHIP
 }

fails in toplev::main:
  test-empty.c.exe: error: unrecognized command line option '-mfloat=hard'
  test-empty.c.exe: error: unrecognized command line option '-mtls=gnu'

(these ought to be -mfloat-abi and -mtls-dialect respectively).

option_default_specs comes from OPTION_DEFAULT_SPECS.

OPTION_DEFAULT_SPECS can be defined by the config, and is for 20 targets, including arm (arm.h):
/* Support for a compile-time default CPU, et cetera.  The rules are:
   --with-arch is ignored if -march or -mcpu are specified.
   --with-cpu is ignored if -march or -mcpu are specified, and is overridden
    by --with-arch.
   --with-tune is ignored if -mtune or -mcpu are specified (but not affected
     by -march).
   --with-float is ignored if -mfloat-abi is specified.
   --with-fpu is ignored if -mfpu is specified.
   --with-abi is ignored if -mabi is specified.
   --with-tls is ignored if -mtls-dialect is specified. */
#define OPTION_DEFAULT_SPECS \
  {"arch", "%{!march=*:%{!mcpu=*:-march=%(VALUE)}}" }, \
  {"cpu", "%{!march=*:%{!mcpu=*:-mcpu=%(VALUE)}}" }, \
  {"tune", "%{!mcpu=*:%{!mtune=*:-mtune=%(VALUE)}}" }, \
  {"float", "%{!mfloat-abi=*:-mfloat-abi=%(VALUE)}" }, \
  {"fpu", "%{!mfpu=*:-mfpu=%(VALUE)}"}, \
  {"abi", "%{!mabi=*:-mabi=%(VALUE)}"}, \
  {"mode", "%{!marm:%{!mthumb:-m%(VALUE)}}"}, \
  {"tls", "%{!mtls-dialect=*:-mtls-dialect=%(VALUE)}"},

So it looks like the jit has to support whatever OPTION_DEFAULT_SPECS is set for the target.

I'm working on a patch that expands these spec values so that they can be injected by libgccjit into toplev::main (and maybe into its own invocation of the driver?).

Unfortunately, this requires running the driver at build time, which would require build==host.
Comment 12 David Malcolm 2015-01-28 21:30:13 UTC
Created attachment 34612 [details]
WIP patch to inject configure-time options into jit's toplev::main (no ChangeLog yet)
Comment 13 David Malcolm 2015-01-28 21:36:13 UTC
(In reply to David Malcolm from comment #12)
> Created attachment 34612 [details]
> WIP patch to inject configure-time options into jit's toplev::main (no
> ChangeLog yet)

With this patch, the 1st iteration of each test case works, with toplev::main containing e.g.:
JIT:    entering: toplev::main
JIT:     argv[0]: ./test-hello-world.c.exe
JIT:     argv[1]: /tmp/libgccjit-E39s8G/fake.c
JIT:     argv[2]: -fPIC
JIT:     argv[3]: -O3
JIT:     argv[4]: -g
JIT:     argv[5]: -quiet
JIT:     argv[6]: --param
JIT:     argv[7]: ggc-min-expand=0
JIT:     argv[8]: --param
JIT:     argv[9]: ggc-min-heapsize=0
JIT:     argv[10]: -fdump-tree-all
JIT:     argv[11]: -fdump-rtl-all
JIT:     argv[12]: -fdump-ipa-all
JIT:     argv[13]: -march=armv7-a
JIT:     argv[14]: -mfloat-abi=hard
JIT:     argv[15]: -mfpu=vfpv3-d16
JIT:     argv[16]: -mtls-dialect=gnu

(note the presence of e.g. "-mfloat-abi=hard")

However, it fails on the 2nd in-process iteration of each test case, with e.g.:
GNU assembler version 2.24 (armv7hl-redhat-linux-gnueabi) using BFD version version 2.24
/tmp/libgccjit-E39s8G/fake.s: Assembler messages:
/tmp/libgccjit-E39s8G/fake.s:1: Error: unknown cpu `armv7-a'
./test-hello-world.c.exe: error: error invoking gcc driver: exit_status: 256 err: 0

The 1st iteration's .s file begins:

        .arch armv7-a
        .eabi_attribute 28, 1
        .fpu vfpv3-d16
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 2
        .eabi_attribute 34, 1
        .arm
        .syntax divided
        .file   "fake.c"
        .text

2nd iteration's .s file begins:
        .cpu armv7-a
        .eabi_attribute 28, 1
        .fpu vfpv3-d16
        .eabi_attribute 20, 1
        .eabi_attribute 21, 1
        .eabi_attribute 23, 3
        .eabi_attribute 24, 1
        .eabi_attribute 25, 1
        .eabi_attribute 26, 2
        .eabi_attribute 30, 2
        .eabi_attribute 34, 1
        .arm
        .syntax divided
        .file   "fake.c"
        .text

Note the changing first line, from:
        .arch armv7-a
to:
        .cpu armv7-a

Am investigating.
Comment 14 Jakub Jelinek 2015-01-28 21:40:50 UTC
Wouldn't it be better to move the minimal spec parsing stuff from gcc.c to a separate source file that you could link into libgccjit.so?
Adding another native build only restriction is undesirable.
Comment 15 David Malcolm 2015-01-28 22:07:33 UTC
(In reply to David Malcolm from comment #13)
> Am investigating.

What appears to be happening is the 1st time through arm_option_override,
arm_selected_cpu is NULL, but is set to non-NULL at:
  arm_selected_cpu = arm_selected_arch;
The 2nd time through, arm_selected_cpu hasn't been reset, and so the condition:

  if (arm_selected_arch)
    {
      if (arm_selected_cpu)
	{
	  /* Check for conflict between mcpu and march.  */

fires, and this clause fires:

	    /* -mcpu wins.  */
	    arm_selected_arch = NULL;

so we have a NULL arm_selected_arch and a non-NULL arm_selected_cpu.

Fix appears to be to simply set each of these to NULL at the top of arm_option_override, to prevent state from previous in-process runs from affecting things:

--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -2627,6 +2627,10 @@ arm_gimplify_va_arg_expr (tree valist, tree type, gimple_seq *pre_p,
 static void
 arm_option_override (void)
 {
+  arm_selected_arch = NULL;
+  arm_selected_cpu = NULL;
+  arm_selected_tune = NULL;
+  
   if (global_options_set.x_arm_arch_option)
     arm_selected_arch = &all_architectures[arm_arch_option];

With this, and the previous patch, most of the jit testsuite passes.

I still see another failure in:
FAIL: test-expressions.c.exe killed: 12479 exp8 0 0 CHILDKILLED SIGSEGV {segmentation violation}
which appears to be (yet) another issue.
Comment 16 David Malcolm 2015-01-28 22:09:55 UTC
(In reply to Jakub Jelinek from comment #14)
> Wouldn't it be better to move the minimal spec parsing stuff from gcc.c to a
> separate source file that you could link into libgccjit.so?
> Adding another native build only restriction is undesirable.

Agreed; I'll see if I can come up with a way of doing this that isn't invasive.
Comment 17 David Malcolm 2015-01-29 02:56:25 UTC
(In reply to David Malcolm from comment #15)
[...snip..]
> I still see another failure in:
> FAIL: test-expressions.c.exe killed: 12479 exp8 0 0 CHILDKILLED SIGSEGV
> {segmentation violation}
> which appears to be (yet) another issue.

This turned out to be due to not handling DImode on arm in jit_langhook_type_for_mode, can be fixed with:

--- a/gcc/jit/dummy-frontend.c
+++ b/gcc/jit/dummy-frontend.c
@@ -167,6 +167,9 @@ jit_langhook_type_for_mode (enum machine_mode mode, int unsignedp)
   if (mode == TYPE_MODE (long_integer_type_node))
     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
 
+  if (mode == TYPE_MODE (long_long_integer_type_node))
+    return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node;
+
Comment 18 ramana.radhakrishnan@arm.com 2015-01-29 09:20:38 UTC
On 28/01/15 17:58, dmalcolm at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64810
>
> --- Comment #9 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
> Thanks Ramana.
>
> I attempted a build of the jit with the configuration you suggested,
> specifically:
>
>    $ ../src/configure \
>        --enable-host-shared \
>        --enable-languages=jit,c++ \
>        --disable-bootstrap \
>        --enable-checking=release \
>        --prefix=/home/dmalcolm/gcc-git-jit/install-jit \
>        --with-arch=armv7-a \
>        --with-float=hard \
>        --with-fpu=vfpv3-d16
>
> Unfortunately, I see the same failures.
>
> Hacking in a "-v" into the driver invocation in jit-playback.c...
>
> diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c
> index d2549a0..5f570a7 100644
> --- a/gcc/jit/jit-playback.c
> +++ b/gcc/jit/jit-playback.c
> @@ -2271,6 +2271,8 @@ invoke_driver (const char *ctxt_progname,
>        time.  */
>     ADD_ARG ("-fno-use-linker-plugin");
>
> +  ADD_ARG ("-v");
> +
>     /* pex argv arrays are NULL-terminated.  */
>     ADD_ARG (NULL);
>
> ...I see that libgccjit attempts to invoke the driver to convert the .s
> to a .so, but it fails like so:
>
> Target: armv7l-unknown-linux-gnueabihf
> Configured with: ../src/configure --enable-host-shared
> --enable-languages=jit,c++ --disable-bootstrap --enable-checking=release
> --prefix=/home/dmalcolm/gcc-git-jit/install-jit --with-arch=armv7-a
> --with-float=hard --with-fpu=vfpv3-d16
> Thread model: posix
> gcc version 5.0.0 20150126 (experimental) (GCC)
> COLLECT_GCC_OPTIONS='-shared' '-o' '/tmp/libgccjit-VxeXM1/fake.so'
> '-fno-use-linker-plugin' '-v' '-march=armv7-a' '-mfloat-abi=hard'
> '-mfpu=vfpv3-d16' '-mtls-dialect=gnu'
>   as -v -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o
> /tmp/ccCY7c5L.o /tmp/libgccjit-VxeXM1/fake.s
> GNU assembler version 2.24 (armv7hl-redhat-linux-gnueabi) using BFD version
> version 2.24
> COMPILER_PATH=
> LIBRARY_PATH=/home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc/:/lib/:/usr/lib/
> COLLECT_GCC_OPTIONS='-shared' '-o' '/tmp/libgccjit-VxeXM1/fake.so'
> '-fno-use-linker-plugin' '-v' '-march=armv7-a' '-mfloat-abi=hard'
> '-mfpu=vfpv3-d16' '-mtls-dialect=gnu'
>   ld --eh-frame-hdr -shared -dynamic-linker /lib/ld-linux-armhf.so.3 -X -m
> armelf_linux_eabi -o /tmp/libgccjit-VxeXM1/fake.so /lib/crti.o
> /home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc/crtbeginS.o
> -L/home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc /tmp/ccCY7c5L.o -lgcc
> --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
> /home/dmalcolm/gcc-git-jit/build-jit-comment8/gcc/crtendS.o /lib/crtn.o
> ld: error: /tmp/libgccjit-VxeXM1/fake.so uses VFP register arguments,
> /tmp/ccCY7c5L.o does not
> ld: failed to merge target specific data of file /tmp/ccCY7c5L.o
>
> That said, with the "test-empty.c" testcase, the generated
> "fake.s" looks like this:
>
>          .cpu arm10tdmi
>          .fpu softvfp
>          .eabi_attribute 20, 1
>          .eabi_attribute 21, 1
>          .eabi_attribute 23, 3
>          .eabi_attribute 24, 1
>          .eabi_attribute 25, 1
>          .eabi_attribute 26, 2
>          .eabi_attribute 30, 2
>          .eabi_attribute 34, 0
>          .arm
>          .syntax divided
>          .file   "fake.c"
>          .text
> .Ltext0:
>          .cfi_sections   .debug_frame
> .Letext0:
>          .section        .debug_line,"",%progbits
> .Ldebug_line0:
>          .section        .debug_str,"MS",%progbits,1
> .LASF0:
>          .ascii  "/tmp/libgccjit-La3Yzk/fake.c\000"
> .LASF1:
>          .ascii  "libgccjit 5.0.0 20150126 (experimental) -fPIC -O3 -"
>          .ascii  "g --param ggc-min-expand=0 --param ggc-min-heapsize"
>          .ascii  "=0\000"
>          .ident  "GCC: (GNU) 5.0.0 20150126 (experimental)"
>          .section        .note.GNU-stack,"",%progbits
>
> In particular, I'm guessing that the line:
>          .fpu softvfp


> is at fault here.
>
> This appears to come from arm.c:arm_file_start:
> 25689         if (TARGET_SOFT_FLOAT)
> 25690           {
> 25691             fpu_name = "softvfp";
> 25692           }
> 25693         else
> and on debugging:
> (gdb) p global_options.x_arm_float_abi
> $1 = ARM_FLOAT_ABI_SOFT
>
> Is this value bogus, given the configure-time options?

Sorry about the slow response, I was unable to check email last evening.

Yes this value is bogus as are the other .cpu values - the assembler 
output suggests to me that the configure time options aren't being 
passed at all from the driver down when used as a jit. Given the 
configure options I would expect

.arch armv7-a
.fpu vfpv3-d16

and an EABI attribute tag to indicate the PCS.

I think you've worked this out reading down-thread.

Ramana
>
> (if so, I'm guessing this is a jit-specific state-management issue)
>
Comment 19 David Malcolm 2015-01-29 15:55:48 UTC
(In reply to ramana.radhakrishnan@arm.com from comment #18)
[...snip...]
> Yes this value is bogus as are the other .cpu values - the assembler 
> output suggests to me that the configure time options aren't being 
> passed at all from the driver down when used as a jit. Given the 
> configure options I would expect
> 
> .arch armv7-a
> .fpu vfpv3-d16
> 
> and an EABI attribute tag to indicate the PCS.
> 
> I think you've worked this out reading down-thread.

Thanks for the confirmation.  I'm testing a patch for this now.
Comment 20 David Malcolm 2015-01-30 11:03:07 UTC
Patches posted for review as:
  https://gcc.gnu.org/ml/gcc-patches/2015-01/msg02704.html
Comment 21 David Malcolm 2015-01-30 18:23:08 UTC
*** Bug 64873 has been marked as a duplicate of this bug. ***
Comment 22 David Malcolm 2015-02-02 15:21:47 UTC
Author: dmalcolm
Date: Mon Feb  2 15:21:16 2015
New Revision: 220347

URL: https://gcc.gnu.org/viewcvs?rev=220347&root=gcc&view=rev
Log:
PR jit/64810: support DImode on arm

gcc/jit/ChangeLog:
	PR jit/64810
	* dummy-frontend.c (jit_langhook_type_for_mode): Support
	TYPE_MODE (long_long_integer_type_node).


Modified:
    trunk/gcc/jit/ChangeLog
    trunk/gcc/jit/dummy-frontend.c
Comment 23 David Malcolm 2015-02-02 16:11:47 UTC
Author: dmalcolm
Date: Mon Feb  2 16:11:15 2015
New Revision: 220351

URL: https://gcc.gnu.org/viewcvs?rev=220351&root=gcc&view=rev
Log:
PR jit/64810: fix for arm_option_override

gcc/ChangeLog:
	PR jit/64810
	* config/arm/arm.c (arm_option_override): Set
	arm_selected_arch/cpu/tune to NULL on entry.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm.c
Comment 24 David Malcolm 2015-02-03 17:20:30 UTC
Author: dmalcolm
Date: Tue Feb  3 17:19:58 2015
New Revision: 220373

URL: https://gcc.gnu.org/viewcvs?rev=220373&root=gcc&view=rev
Log:
PR jit/64810: driver, arm, jit: configure-time default options

gcc/ChangeLog:
	PR jit/64810
	* Makefile.in (GCC_OBJS): Add gcc-main.o.
	* gcc-main.c: New file, containing "main" taken from gcc.c.
	* gcc.c (do_self_spec): Free decoded_options.
	(class driver): Move declaration to gcc.h.
	(main): Move declaration and implementation to new file
	gcc-main.c.
	(driver_get_configure_time_options): New function.
	* gcc.h (class driver): Move this declaration here, from
	gcc.c.
	(driver_get_configure_time_options): New declaration.

gcc/jit/ChangeLog:
	PR jit/64810
	* Make-lang.in (jit_OBJS): Add jit/jit-spec.o and gcc.o.
	(LIBGCCJIT_FILENAME): Add EXTRA_GCC_OBJS.
	* jit-playback.c: Include gcc.h.
	(gcc::jit::playback::context::compile): Move mutex acquisition
	to before the call to make_fake_args.
	(append_arg_from_driver): New function.
	(gcc::jit::playback::context::make_fake_args): On the first call,
	call into driver_get_configure_time_options to get configure-time
	default options and cache them.  Add them to the args for
	toplev::main.
	* jit-spec.c: New source file.
	* docs/internals/test-hello-world.exe.log.txt: Update to reflect
	above changes.


Added:
    trunk/gcc/gcc-main.c
    trunk/gcc/jit/jit-spec.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/Makefile.in
    trunk/gcc/gcc.c
    trunk/gcc/gcc.h
    trunk/gcc/jit/ChangeLog
    trunk/gcc/jit/Make-lang.in
    trunk/gcc/jit/docs/_build/texinfo/libgccjit.texi
    trunk/gcc/jit/docs/internals/test-hello-world.exe.log.txt
    trunk/gcc/jit/jit-playback.c
Comment 25 Ramana Radhakrishnan 2015-03-13 09:09:16 UTC
Fixed presumably ?
Comment 26 David Malcolm 2015-03-13 14:17:23 UTC
(In reply to Ramana Radhakrishnan from comment #25)
> Fixed presumably ?

Mostly.  The remaining issue with configure-time options reaching the jit is when gcc is configured with:
  --with-arch=native
I attempted to fix that, but it appeared to be non-trivial, so I think I'll open that as a separate (non-arm) bug (sorry, have been on vacation in the meantime, and need to page it all back in to my brain...)
Comment 27 Richard Earnshaw 2016-06-28 12:29:33 UTC
(In reply to David Malcolm from comment #26)
> (In reply to Ramana Radhakrishnan from comment #25)
> > Fixed presumably ?
> 
> Mostly.  The remaining issue with configure-time options reaching the jit is
> when gcc is configured with:
>   --with-arch=native
> I attempted to fix that, but it appeared to be non-trivial, so I think I'll
> open that as a separate (non-arm) bug (sorry, have been on vacation in the
> meantime, and need to page it all back in to my brain...)

Is there anything further to be done on this?
Comment 28 Martin Liška 2018-11-19 13:26:42 UTC
Can the bug be marked as resolved?