www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - how to disable inlining of ldc2 when 'dub build --build=release'?

reply lixiaozi <jackspring qq.com> writes:
Hi,guys!
I recently use ldc2 to compile my project.
When using 'dub build --build=release --compiler=ldc2 ',it 
crashed in a try catch block.
After a few tries, I noticed it's the inline optimization in ldc2 
that caused the crash. So i manually changed the call of ldc2 to 
'ldc2 -release -disable-inlining -Hkeep-all-bodies -O3 -w -oq 
...' and it worked and doesn't crash any more.

Now, I try to disable inlining in "dub.json" like
==
"dflags":[
                 "-disable-inlining"
         ],
==
  but it doesn't work, because then dub calls ldc2 like this:
'ldc2   -disable-inlining  -release  -enable-inlining 
-Hkeep-all-bodies -O3 -w -oq' and inlining in ldc2 will still be 
enabled.

so, what should i do to disable inlining of ldc2 in release build?

Thanks in advance.
May 20 2017
next sibling parent reply Johan Engelen <j j.nl> writes:
On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 [...]
 I noticed it's the inline optimization in ldc2 that caused the 
 crash.
If you are certain that your code is 100% correct, please file a bug report. Inlining is done by LLVM and it is rare to find an LLVM bug like that (what architecture are you on, x86?).
 so, what should i do to disable inlining of ldc2 in release 
 build?
You can try disabling inlining of a specific function (pragma(inline, false)), or disabling optimization inside a function ( optStrategy("none")). -Johan
May 20 2017
next sibling parent reply Stefan Koch <uplink.coder googlemail.com> writes:
On Saturday, 20 May 2017 at 08:08:38 UTC, Johan Engelen wrote:
 On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 [...]
 I noticed it's the inline optimization in ldc2 that caused the 
 crash.
If you are certain that your code is 100% correct, please file a bug report. Inlining is done by LLVM and it is rare to find an LLVM bug like that (what architecture are you on, x86?).
While LLVM in general has quite a few bugs, inlining should be rather solid. Any chance we can get a test-case ?
May 20 2017
parent lixiaozi <jackspring qq.com> writes:
On Saturday, 20 May 2017 at 08:22:43 UTC, Stefan Koch wrote:
 On Saturday, 20 May 2017 at 08:08:38 UTC, Johan Engelen wrote:
 On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 [...]
 I noticed it's the inline optimization in ldc2 that caused 
 the crash.
If you are certain that your code is 100% correct, please file a bug report. Inlining is done by LLVM and it is rare to find an LLVM bug like that (what architecture are you on, x86?).
While LLVM in general has quite a few bugs, inlining should be rather solid. Any chance we can get a test-case ?
Thanks. I've tried to get a test-case, but they couldn't core dump.
May 22 2017
prev sibling parent lixiaozi <jackspring qq.com> writes:
On Saturday, 20 May 2017 at 08:08:38 UTC, Johan Engelen wrote:
 On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 [...]
 I noticed it's the inline optimization in ldc2 that caused the 
 crash.
If you are certain that your code is 100% correct, please file a bug report. Inlining is done by LLVM and it is rare to find an LLVM bug like that (what architecture are you on, x86?).
 so, what should i do to disable inlining of ldc2 in release 
 build?
You can try disabling inlining of a specific function (pragma(inline, false)), or disabling optimization inside a function ( optStrategy("none")). -Johan
Thanks.
 On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 [...]
 I noticed it's the inline optimization in ldc2 that caused the 
 crash.
If you are certain that your code is 100% correct, please file a bug report. Inlining is done by LLVM and it is rare to find an LLVM bug like that (what architecture are you on, x86?).
I'm not so sure about the 100% correct. It's just the "disable-inlining" flag that make thought it's a inline problem.
 so, what should i do to disable inlining of ldc2 in release 
 build?
You can try disabling inlining of a specific function (pragma(inline, false)), or disabling optimization inside a function ( optStrategy("none")). -Johan
I've just tried these. (pragma(inline, false)) didn't work and ( optStrategy("none")) produced a error of "Error: undefined identifier 'optStrategy'. Here's some info. == <uname -a> 15:04:24 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux == == <ldc2 --version> LDC - the LLVM D compiler (1.2.0): based on DMD v2.072.2 and LLVM 4.0.0 built with LDC - the LLVM D compiler (1.2.0) Default target: x86_64-unknown-linux-gnu Host CPU: haswell http://dlang.org - http://wiki.dlang.org/LDC Registered Targets: x86 - 32-bit X86: Pentium-Pro and above x86-64 - 64-bit X86: EM64T and AMD64 == == <dub --version> DUB version 1.2.1, built on Feb 17 2017 == == <file uploadTest> uploadTest: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ef04c21ce824390619013256378b3dda8e6caf67, not stripped == == <gdb uploadTest core.6722> GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/senter/uploadserverTest/uploadTest...done. [New LWP 6726] [New LWP 6728] [New LWP 6730] [New LWP 6724] [New LWP 6722] [New LWP 6727] [New LWP 6725] [New LWP 6729] [New LWP 6723] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Core was generated by `uploadTest'. Program terminated with signal 6, Aborted. at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 56 return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig); (gdb) bt at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 at ../../../libgcc/unwind.inc:234 (this=<optimized out>) at core.d:1216 (gdb) == uploadTest is the executable build by dub in release-debug mode. == <and the code that corrupted the app> try { writeln("post begin--------------------"); writeln("picanalyseurl", picanalyseurl); auto httpanalyse = HTTP(picanalyseurl.idup); httpanalyse.handle.set(CurlOption.timeout,10); scope char[] content = post(picanalyseurl.idup,picanalysemsg.idup,httpanalyse); writeln(cast(string)content); writeln("post end ------------------"); } catch(Throwable ee) { writeln(ee.msg); } == for now the variable 'picanalyseurl' is invalid, so there'll always a exception. == <the corrupted screenshot> picanalyseurl:http://127.0.0.1:8721/picanalyse picanalysemsg:meid=8C1F780876BB489A&picname=8C1F780876BB489A_201702210000000001.jpg uploaddt=2017-05-19 11:12:32&analyseMode=0&analysePicname=&picanalyseregion= post begin-------------------- picanalyseurlhttp://127.0.0.1:8721/picanalyse Aborted(core dump) == Thanks.
May 22 2017
prev sibling next sibling parent reply Johan Engelen <j j.nl> writes:
On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 
 Now, I try to disable inlining in "dub.json" like
 ==
 "dflags":[
                 "-disable-inlining"
         ],
 ==
  but it doesn't work, because then dub calls ldc2 like this:
 'ldc2   -disable-inlining  -release  -enable-inlining 
 -Hkeep-all-bodies -O3 -w -oq' and inlining in ldc2 will still 
 be enabled.
You could file a bug/feature request with Dub: I think it should add user flags at the end of the cmdline. (flags can override earlier flags, so then the user can override any flag Dub is already passing to LDC). -Johan
May 20 2017
parent lixiaozi <jackspring qq.com> writes:
On Saturday, 20 May 2017 at 08:11:06 UTC, Johan Engelen wrote:
 On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:
 
 Now, I try to disable inlining in "dub.json" like
 ==
 "dflags":[
                 "-disable-inlining"
         ],
 ==
  but it doesn't work, because then dub calls ldc2 like this:
 'ldc2   -disable-inlining  -release  -enable-inlining 
 -Hkeep-all-bodies -O3 -w -oq' and inlining in ldc2 will still 
 be enabled.
You could file a bug/feature request with Dub: I think it should add user flags at the end of the cmdline. (flags can override earlier flags, so then the user can override any flag Dub is already passing to LDC). -Johan
Thanks. I've file a issue here:https://github.com/dlang/dub/issues/1135
May 22 2017
prev sibling parent reply Stanislav Blinov <stanislav.blinov gmail.com> writes:
On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:

 so, what should i do to disable inlining of ldc2 in release 
 build?
As Stefan mentioned, a test case would be nice. But have you tried annotating the offending function with pragma(inline, false)? http://dlang.org/spec/pragma.html#inline
May 20 2017
parent lixiaozi <jackspring qq.com> writes:
On Saturday, 20 May 2017 at 10:22:14 UTC, Stanislav Blinov wrote:
 On Saturday, 20 May 2017 at 08:02:26 UTC, lixiaozi wrote:

 so, what should i do to disable inlining of ldc2 in release 
 build?
As Stefan mentioned, a test case would be nice. But have you tried annotating the offending function with pragma(inline, false)? http://dlang.org/spec/pragma.html#inline
Thanks. I've tried pragma(inline,false), it didn't help. Maybe I'l should try more way to locate the problem. Thanks.
May 22 2017