OTP / HiPE broken with GCC 6.2

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

OTP / HiPE broken with GCC 6.2

Johannes Weißl-2
Hi,

Last week GCC got updated from 6.1.1 to 6.2.0 on my Debian laptop. Since then
OTP releases built with this compiler have broken HiPE [1]. The error is
reproducible on different machines, even the official OTP 19.1.5 Debian binary
package is broken because it was built with the new compiler.

Has anybody else experienced the same with GCC 6.2? I have not done much
debugging, the error could be in GCC or OTP (maybe usage of undefined behavior).

Regards,
Johannes

[1] Stacktrace after `c(my_module, [native]).` for any module:

{'EXIT',{badarg,[{hipe_bifs,patch_call,
                            [1103888528,94502719669968,[]],
                            []},
                 {hipe_unified_loader,patch_call_insn,3,
                                      [{file,"hipe_unified_loader.erl"},{line,508}]},
                 {hipe_unified_loader,patch_bif_call_list,4,
                                      [{file,"hipe_unified_loader.erl"},{line,494}]},
                 {hipe_unified_loader,patch_call,5,
                                      [{file,"hipe_unified_loader.erl"},{line,485}]},
                 {hipe_unified_loader,patch,5,
                                      [{file,"hipe_unified_loader.erl"},{line,462}]},
                 {hipe_unified_loader,load_common,4,
                                      [{file,"hipe_unified_loader.erl"},{line,215}]},
                 {hipe_unified_loader,load_native_code,3,
                                      [{file,"hipe_unified_loader.erl"},{line,111}]},
                 {code_server,try_load_module_2,6,
                              [{file,"code_server.erl"},{line,1131}]}]}}

Dialyzer fails with:
Compiling some key modules to native code...{"init terminating in do_boot",{{badmatch,ok},[{dialyzer_cl,hc_cache,1,[{file,"dialyzer_cl.erl"},{line,572}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{dialyzer_cl,hipe_compile,2,[{file,"dialyzer_cl.erl"},{line,516}]},{dialyzer_cl,do_analysis,4,[{file,"dialyzer_cl.erl"},{line,382}]},{dialyzer,'-cl/1-fun-0-',1,[{file,"dialyzer.erl"},{line,153}]},{dialyzer,doit,1,[{file,"dialyzer.erl"},{line,243}]},{dialyzer,plain_cl,0,[{file,"dialyzer.erl"},{line,84}]},{init,start_em,1,[]}]}}

After the fix in https://github.com/erlang/otp/commit/cb987678ff56142029758e0e84fa97fa90003b4a:

Compiling some key modules to native code...{"init terminating in do_boot",{{badmatch,{error,{'EXIT',{badarg,[{hipe_bifs,patch_call,[1075697819,94447304565728,[]],[]},{hipe_unified_loader,patch_call_insn,3,[{file,"hipe_unified_loader.erl"},{line,508}]},{hipe_unified_loader,patch_bif_call_list,4,[{file,"hipe_unified_loader.erl"},{line,494}]},{hipe_unified_loader,patch_call,5,[{file,"hipe_unified_loader.erl"},{line,485}]},{hipe_unified_loader,patch,5,[{file,"hipe_unified_loader.erl"},{line,460}]},{hipe_unified_loader,load_common,4,[{file,"hipe_unified_loader.erl"},{line,215}]},{hipe_unified_loader,load_native_code,3,[{file,"hipe_unified_loader.erl"},{line,111}]},{code_server,try_load_module_2,6,[{file,"code_server.erl"},{line,1131}]}]}}}},[{dialyzer_cl,hc_cache,1,[{file,"dialyzer_cl.erl"},{line,572}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{dialyzer_cl,hipe_compile,2,[{file,"dialyzer_cl.erl"},{line,516}]},{dialyzer_cl,do_analysis,4,[{file,"dialyzer_cl.erl"},{line,38
 2}]},{dialyzer,'-cl/1-fun-0-',1,[{file,"dialyzer.erl"},{line,153}]},{dialyzer,doit,1,[{file,"dialyzer.erl"},{line,243}]},{dialyzer,plain_cl,0,[{file,"dialyzer.erl"},{line,84}]},{init,start_em,1,[]}]}}
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Sverker Eriksson-4
If this is x86_64 (amd64) then it looks like
the beam was built without gcc's default small code model
where "the program and its symbols must be linked
in the lower 2 GB of the address space."

The second argument to hipe_bifs:patch_call/2
should in this case be the address of a BIF,
but 94502719669968 is way past 2GB.

/Sverker, Erlang/OTP


On 11/02/2016 11:30 PM, Johannes Weißl wrote:

> Hi,
>
> Last week GCC got updated from 6.1.1 to 6.2.0 on my Debian laptop. Since then
> OTP releases built with this compiler have broken HiPE [1]. The error is
> reproducible on different machines, even the official OTP 19.1.5 Debian binary
> package is broken because it was built with the new compiler.
>
> Has anybody else experienced the same with GCC 6.2? I have not done much
> debugging, the error could be in GCC or OTP (maybe usage of undefined behavior).
>
> Regards,
> Johannes
>
> [1] Stacktrace after `c(my_module, [native]).` for any module:
>
> {'EXIT',{badarg,[{hipe_bifs,patch_call,
>                              [1103888528,94502719669968,[]],
>                              []},
>                   {hipe_unified_loader,patch_call_insn,3,
>                                        [{file,"hipe_unified_loader.erl"},{line,508}]},
>                   {hipe_unified_loader,patch_bif_call_list,4,
>                                        [{file,"hipe_unified_loader.erl"},{line,494}]},
>                   {hipe_unified_loader,patch_call,5,
>                                        [{file,"hipe_unified_loader.erl"},{line,485}]},
>                   {hipe_unified_loader,patch,5,
>                                        [{file,"hipe_unified_loader.erl"},{line,462}]},
>                   {hipe_unified_loader,load_common,4,
>                                        [{file,"hipe_unified_loader.erl"},{line,215}]},
>                   {hipe_unified_loader,load_native_code,3,
>                                        [{file,"hipe_unified_loader.erl"},{line,111}]},
>                   {code_server,try_load_module_2,6,
>                                [{file,"code_server.erl"},{line,1131}]}]}}
>
> Dialyzer fails with:
> Compiling some key modules to native code...{"init terminating in do_boot",{{badmatch,ok},[{dialyzer_cl,hc_cache,1,[{file,"dialyzer_cl.erl"},{line,572}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{dialyzer_cl,hipe_compile,2,[{file,"dialyzer_cl.erl"},{line,516}]},{dialyzer_cl,do_analysis,4,[{file,"dialyzer_cl.erl"},{line,382}]},{dialyzer,'-cl/1-fun-0-',1,[{file,"dialyzer.erl"},{line,153}]},{dialyzer,doit,1,[{file,"dialyzer.erl"},{line,243}]},{dialyzer,plain_cl,0,[{file,"dialyzer.erl"},{line,84}]},{init,start_em,1,[]}]}}
>
> After the fix in https://github.com/erlang/otp/commit/cb987678ff56142029758e0e84fa97fa90003b4a:
>
> Compiling some key modules to native code...{"init terminating in do_boot",{{badmatch,{error,{'EXIT',{badarg,[{hipe_bifs,patch_call,[1075697819,94447304565728,[]],[]},{hipe_unified_loader,patch_call_insn,3,[{file,"hipe_unified_loader.erl"},{line,508}]},{hipe_unified_loader,patch_bif_call_list,4,[{file,"hipe_unified_loader.erl"},{line,494}]},{hipe_unified_loader,patch_call,5,[{file,"hipe_unified_loader.erl"},{line,485}]},{hipe_unified_loader,patch,5,[{file,"hipe_unified_loader.erl"},{line,460}]},{hipe_unified_loader,load_common,4,[{file,"hipe_unified_loader.erl"},{line,215}]},{hipe_unified_loader,load_native_code,3,[{file,"hipe_unified_loader.erl"},{line,111}]},{code_server,try_load_module_2,6,[{file,"code_server.erl"},{line,1131}]}]}}}},[{dialyzer_cl,hc_cache,1,[{file,"dialyzer_cl.erl"},{line,572}]},{lists,foreach,2,[{file,"lists.erl"},{line,1338}]},{dialyzer_cl,hipe_compile,2,[{file,"dialyzer_cl.erl"},{line,516}]},{dialyzer_cl,do_analysis,4,[{file,"dialyzer_cl.erl"},{line,38
>   2}]},{dialyzer,'-cl/1-fun-0-',1,[{file,"dialyzer.erl"},{line,153}]},{dialyzer,doit,1,[{file,"dialyzer.erl"},{line,243}]},{dialyzer,plain_cl,0,[{file,"dialyzer.erl"},{line,84}]},{init,start_em,1,[]}]}}
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Mikael Pettersson-5
Sverker Eriksson writes:
 > If this is x86_64 (amd64) then it looks like
 > the beam was built without gcc's default small code model
 > where "the program and its symbols must be linked
 > in the lower 2 GB of the address space."
 >
 > The second argument to hipe_bifs:patch_call/2
 > should in this case be the address of a BIF,
 > but 94502719669968 is way past 2GB.
 >
 > /Sverker, Erlang/OTP
 >
 >
 > On 11/02/2016 11:30 PM, Johannes Weißl wrote:
 > > Hi,
 > >
 > > Last week GCC got updated from 6.1.1 to 6.2.0 on my Debian laptop. Since then
 > > OTP releases built with this compiler have broken HiPE [1]. The error is
 > > reproducible on different machines, even the official OTP 19.1.5 Debian binary
 > > package is broken because it was built with the new compiler.
 > >
 > > Has anybody else experienced the same with GCC 6.2? I have not done much
 > > debugging, the error could be in GCC or OTP (maybe usage of undefined behavior).
 > >
 > > Regards,
 > > Johannes
 > >
 > > [1] Stacktrace after `c(my_module, [native]).` for any module:
 > >
 > > {'EXIT',{badarg,[{hipe_bifs,patch_call,
 > >                              [1103888528,94502719669968,[]],
 > >                              []},
 > >                   {hipe_unified_loader,patch_call_insn,3,
 > >                                        [{file,"hipe_unified_loader.erl"},{line,508}]},
 > >                   {hipe_unified_loader,patch_bif_call_list,4,
 > >                                        [{file,"hipe_unified_loader.erl"},{line,494}]},
 > >                   {hipe_unified_loader,patch_call,5,
 > >                                        [{file,"hipe_unified_loader.erl"},{line,485}]},
 > >                   {hipe_unified_loader,patch,5,
 > >                                        [{file,"hipe_unified_loader.erl"},{line,462}]},
 > >                   {hipe_unified_loader,load_common,4,
 > >                                        [{file,"hipe_unified_loader.erl"},{line,215}]},
 > >                   {hipe_unified_loader,load_native_code,3,
 > >                                        [{file,"hipe_unified_loader.erl"},{line,111}]},
 > >                   {code_server,try_load_module_2,6,
 > >                                [{file,"code_server.erl"},{line,1131}]}]}}

I cannot reproduce this with the tip of the otp master branch, and gcc's built
from either the gcc-6.2.0 release tar ball or from a recent head of the gcc-6 branch.

Most likely the Erlang VM was compiled with non-standard options, for instance
as a PIE (position-independent executable) which would break all address space
layout assumptions.  This could be the result of otp build options or non-standard
behaviour in that Debian gcc.

If you want further help debugging this, show us
(1) the output of gcc -v
(2) any special options (whether via ./configure or environment variables) used when
    compiling otp
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Johannes Weißl-2
In reply to this post by Sverker Eriksson-4
Hi Sverker,

On Thu, Nov 03, 2016 at 03:47PM +0100, Sverker Eriksson wrote:
> If this is x86_64 (amd64) then it looks like
> the beam was built without gcc's default small code model
> where "the program and its symbols must be linked
> in the lower 2 GB of the address space."

Thanks for the reply! Yes, all tested platforms were x86_64 (amd64). I
tried again with an OTP build compiled explicitly with
CFLAGS="-mcmodel=small" [1] (if this is what you meant), but the error
stays the same.

I haven't mentioned it in my report, I tested with OTP 19.1.5 and the
current master branch (2ccd860 yesterday and 214aba4 today).

Regards,
Johannes

[1] https://gcc.gnu.org/onlinedocs/gcc-6.2.0/gcc/x86-Options.html#x86-Options
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Johannes Weißl-2
In reply to this post by Mikael Pettersson-5
Hi Mikael,

On Thu, Nov 03, 2016 at 08:12PM +0100, Mikael Pettersson wrote:
> I cannot reproduce this with the tip of the otp master branch, and gcc's built
> from either the gcc-6.2.0 release tar ball or from a recent head of the gcc-6 branch.

Can you try to configure gcc with "--enable-default-pie"? With this flag
(which is used for the Debian gcc package) I could reproduce the bug on
Debian and Fedora with the gcc-6.2.0 release tar ball and the current
gcc svn trunk (rev 241852). PIE also seems to have been used for the
official Fedora erlang19.1.4-1.fc25 package, as there HiPE is also
broken.

> Most likely the Erlang VM was compiled with non-standard options, for instance
> as a PIE (position-independent executable) which would break all address space
> layout assumptions.

This seems to be the case, thanks for the pointer! What would be your
preferred solution to solve this problem? One possibility would be to
add an option to the OTP build system to compile without PIE, so
that it does not break for compilers that have PIE enabled by default.
Similar has been suggested here for the Linux kernel:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841438

With CFLAGS and LDFLAGS set to "-no-pie -fno-pie" I can compile a
working version with the current Debian Testing gcc.

> If you want further help debugging this, show us
> (1) the output of gcc -v

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 6.2.0-10' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enabl
 e-objc-gc --enable-multiarch --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20161027 (Debian 6.2.0-10)

> (2) any special options (whether via ./configure or environment variables) used when
>     compiling otp

No special options.


Regards,
Johannes
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Kostis Sagonas-2
On 11/05/2016 12:49 AM, Johannes Weißl wrote:

> Hi Mikael,
>
> On Thu, Nov 03, 2016 at 08:12PM +0100, Mikael Pettersson wrote:
>> > I cannot reproduce this with the tip of the otp master branch, and gcc's built
>> > from either the gcc-6.2.0 release tar ball or from a recent head of the gcc-6 branch.
> Can you try to configure gcc with "--enable-default-pie"? With this flag
> (which is used for the Debian gcc package) I could reproduce the bug on
> Debian and Fedora with the gcc-6.2.0 release tar ball and the current
> gcc svn trunk (rev 241852). PIE also seems to have been used for the
> official Fedora erlang19.1.4-1.fc25 package, as there HiPE is also
> broken.
>
>> > Most likely the Erlang VM was compiled with non-standard options, for instance
>> > as a PIE (position-independent executable) which would break all address space
>> > layout assumptions.
> This seems to be the case, thanks for the pointer! What would be your
> preferred solution to solve this problem? One possibility would be to
> add an option to the OTP build system to compile without PIE, so
> that it does not break for compilers that have PIE enabled by default.
> Similar has been suggested here for the Linux kernel:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841438

Well, it's good to know that HiPE, when suffering from such problems, is
in good company (that of the Linux kernel).

> With CFLAGS and LDFLAGS set to "-no-pie -fno-pie" I can compile a
> working version with the current Debian Testing gcc.

 From a quick read of the thread you suggested for the kernel and of the
corresponding Ubuntu thread, it seems that forcing no-pie in the flags
is the way on this one.

But of course this does not solve the problem for OTP releases that are
already out there. (It should be pretty obvious that this affects all
Erlang/OTP releases that include HiPE: none can be compiled with PIE.)

Kostis
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Johannes Weißl-2
On Sat, Nov 05, 2016 at 11:22AM +0100, Kostis Sagonas wrote:
> On 11/05/2016 12:49 AM, Johannes Weißl wrote:
> > With CFLAGS and LDFLAGS set to "-no-pie -fno-pie" I can compile a
> > working version with the current Debian Testing gcc.
>
> From a quick read of the thread you suggested for the kernel and of the
> corresponding Ubuntu thread, it seems that forcing no-pie in the flags is
> the way on this one.

OK, thanks! I opened https://bugs.erlang.org/browse/ERL-294 for it.

Johannes
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Mikael Pettersson-5
In reply to this post by Johannes Weißl-2
Johannes Weißl writes:
 > Hi Mikael,
 >
 > On Thu, Nov 03, 2016 at 08:12PM +0100, Mikael Pettersson wrote:
 > > I cannot reproduce this with the tip of the otp master branch, and gcc's built
 > > from either the gcc-6.2.0 release tar ball or from a recent head of the gcc-6 branch.
 >
 > Can you try to configure gcc with "--enable-default-pie"? With this flag
 > (which is used for the Debian gcc package) I could reproduce the bug on
 > Debian and Fedora with the gcc-6.2.0 release tar ball and the current
 > gcc svn trunk (rev 241852). PIE also seems to have been used for the
 > official Fedora erlang19.1.4-1.fc25 package, as there HiPE is also
 > broken.

Using a gcc-6.2.0 configured with --enable-default-pie reproduces the bug for me
on FC23.

 > > Most likely the Erlang VM was compiled with non-standard options, for instance
 > > as a PIE (position-independent executable) which would break all address space
 > > layout assumptions.
 >
 > This seems to be the case, thanks for the pointer! What would be your
 > preferred solution to solve this problem? One possibility would be to
 > add an option to the OTP build system to compile without PIE, so
 > that it does not break for compilers that have PIE enabled by default.
 > Similar has been suggested here for the Linux kernel:
 > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=841438
 >
 > With CFLAGS and LDFLAGS set to "-no-pie -fno-pie" I can compile a
 > working version with the current Debian Testing gcc.

If this problem had been limited to Debian, I would have said that the
Erlang/OTP package maintainer for Debian should add the necessary options
to disable PIE.  However, reading some related Linux Kernel ML messages
today it seems that Gentoo and Fedora (so eventually also RHEL and CentOS)
also are affected, so we have no option but to work around it in OTP.

A change in erts/configure.in to add options to disable PIE if HiPE is
not disabled and the target arch is x86_64 should take care of the issue.
People building older versions will have to backport the patch or
override the compiler options, but that's nothing new.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Kenneth Lakin
On 11/06/2016 03:32 AM, Mikael Pettersson wrote:
> A change in erts/configure.in to add options to disable PIE if HiPE is
> not disabled and the target arch is x86_64 should take care of the issue.

Is i386 likely unaffected by this, or is x86_64 shorthand for "x86 32-
and 64-bit systems"? (Yes, I'm one of _those people_ with an ancient
laptop. ;) )



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: OTP / HiPE broken with GCC 6.2

Mikael Pettersson-5
Kenneth Lakin writes:
 > On 11/06/2016 03:32 AM, Mikael Pettersson wrote:
 > > A change in erts/configure.in to add options to disable PIE if HiPE is
 > > not disabled and the target arch is x86_64 should take care of the issue.
 >
 > Is i386 likely unaffected by this, or is x86_64 shorthand for "x86 32-
 > and 64-bit systems"? (Yes, I'm one of _those people_ with an ancient
 > laptop. ;) )

HiPE on 32-bit x86 is unaffected by the PIE issue.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions