LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 38659 - Compile issue on clang 6.0.0
Summary: Compile issue on clang 6.0.0
Status: NEW
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: unspecified
Hardware: Other All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-21 06:13 PDT by Nathan Owens
Modified: 2018-08-27 14:29 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
10.4 Files (836.00 KB, application/x-tar)
2018-08-21 15:13 PDT, Nathan Owens
Details
11.2 build log; Clang 6 (18.78 KB, text/plain)
2018-08-21 15:14 PDT, Nathan Owens
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Owens 2018-08-21 06:13:43 PDT
On i386 when building angelscript I get:
If building for amd64 I don’t. The workaround for i386 is to build using gcc


gmake[1]: Entering directory '/wrkdirs/usr/ports/lang/angelscript/work/sdk/angelscript/projects/gnuc'
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_atomic.o -c ../../source/as_atomic.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_builder.o -c ../../source/as_builder.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_bytecode.o -c ../../source/as_bytecode.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc.o -c ../../source/as_callfunc.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_arm.o -c ../../source/as_callfunc_arm.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_mips.o -c ../../source/as_callfunc_mips.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_ppc.o -c ../../source/as_callfunc_ppc.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_ppc_64.o -c ../../source/as_callfunc_ppc_64.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_sh4.o -c ../../source/as_callfunc_sh4.cpp
c++ -O2 -pipe -fstack-protector -fno-strict-aliasing  -Wall -fPIC -fno-strict-aliasing -o obj/as_callfunc_x86.o -c ../../source/as_callfunc_x86.cpp
fatal error: error in backend: No open frame
c++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: i386-unknown-freebsd10.4
Thread model: posix
c++: note: diagnostic msg: PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
c++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
c++: note: diagnostic msg: /tmp/as_callfunc_x86-315a7c.cpp
c++: note: diagnostic msg: /tmp/as_callfunc_x86-315a7c.sh
c++: note: diagnostic msg:

********************
gmake[1]: *** [Makefile:157: obj/as_callfunc_x86.o] Error 70
gmake[1]: *** Waiting for unfinished jobs....
gmake[1]: Leaving directory '/wrkdirs/usr/ports/lang/angelscript/work/sdk/angelscript/projects/gnuc'
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make: stopped in /usr/ports/lang/angelscript
build of lang/angelscript | angelscript-2.32.0 ended at Thu Aug 16 10:19:44 CST 2018
build time: 00:00:15
!!! build failure encountered !!!
[00:01:51] Error: Build failed in phase: build
[00:01:51] Cleaning up
[00:01:52] Unmounting file systems
Comment 1 Reid Kleckner 2018-08-21 10:21:43 PDT
Please compress and attach the files mentioned here so we can easily reproduce the crash:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
c++: note: diagnostic msg: /tmp/as_callfunc_x86-315a7c.cpp
c++: note: diagnostic msg: /tmp/as_callfunc_x86-315a7c.sh
Comment 2 Dimitry Andric 2018-08-21 14:18:21 PDT
(In reply to Nathan Owens from comment #0)
...
> fatal error: error in backend: No open frame
> c++: error: clang frontend command failed with exit code 70 (use -v to see
> invocation)
> FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512

The bug report title says "clang 6.0.0", but the crash message says clang 3.4.1 (which is the default compiler in FreeBSD 10.x).  It's not very likely that bugs in this old version will be fixed, but you should always save and attach the generated .cpp and .sh files.
Comment 3 Nathan Owens 2018-08-21 14:26:40 PDT
(In reply to Dimitry Andric from comment #2)
> (In reply to Nathan Owens from comment #0)
> ...
> > fatal error: error in backend: No open frame
> > c++: error: clang frontend command failed with exit code 70 (use -v to see
> > invocation)
> > FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
> 
> The bug report title says "clang 6.0.0", but the crash message says clang
> 3.4.1 (which is the default compiler in FreeBSD 10.x).  It's not very likely
> that bugs in this old version will be fixed, but you should always save and
> attach the generated .cpp and .sh files.

Yeah sorry, I forgot I got that error from freebsd 10.4, also having issues with 11.2 clang-6; Will attach both, except 11.2 doesn't generate those error reports like 10.4 did
Comment 4 Nathan Owens 2018-08-21 15:13:16 PDT
Created attachment 20753 [details]
10.4 Files
Comment 5 Nathan Owens 2018-08-21 15:14:48 PDT
Created attachment 20754 [details]
11.2 build log; Clang 6
Comment 6 Dimitry Andric 2018-08-25 06:19:34 PDT
This particular crash is an older issue, which has been "solved" in the mean time, by making it a non-fatal error.  After https://reviews.llvm.org/rL315264 ("[MC] Properly diagnose badly scoped .cfi_ directives"), it now prints:

error: this directive must appear between .cfi_startproc and .cfi_endproc directives

The problem is that angelscript is attempting some sort of workaround for optimizations messing up its assumptions about stack layout, e.g. it has this:

        asm __volatile__(
#ifdef __OPTIMIZE__
                // When compiled with optimizations the stack unwind doesn't work properly,
                // causing exceptions to crash the application. By adding this prologue
                // and the epilogue below, the stack unwind works as it should.
                // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below
                "pushl %%ebp               \n"
                ".cfi_adjust_cfa_offset 4  \n"
                ".cfi_rel_offset ebp, 0    \n"
                "movl %%esp, %%ebp         \n"
                ".cfi_def_cfa_register ebp \n"
#endif
                _S(CLEAR_FPU_STACK)    "\n"
                "pushl %%ebx            \n"
                "movl  %%edx, %%ebx     \n"

Before r315264, MCStreamer crashed with a "no open frame" error, if it encountered such 'naked' .cfi directives.  After r315264, it prints a regular error instead.

The easiest way to work around these errors is to change all the #ifdef __OPTIMIZE__ lines to:

#if defined(__OPTIMIZE__) && !defined(__clang__)
Comment 7 Dimitry Andric 2018-08-25 06:23:46 PDT
Btw, this is a very minimal test case:

$ cat pr38649.cpp
// clang -cc1 -triple i386-- -emit-obj pr38649.cpp
void a() { asm(".cfi_restore %ebp\n"); }

$ clang -cc1 -triple i386-- -emit-obj pr38649.cpp
error: this directive must appear between .cfi_startproc and .cfi_endproc directives
1 error generated.

If you attempt to compile this for x86_64, clang blows up in a different way:

$ clang -cc1 -triple x86_64-- -emit-obj -munwind-tables pr38649.cpp
Assertion failed: ((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) && "Invalid size"), function EmitIntValue, file /usr/src/contrib/llvm/lib/MC/MCStreamer.cpp, line 115.
Abort trap
Comment 8 Reid Kleckner 2018-08-27 14:29:32 PDT
(In reply to Dimitry Andric from comment #7)
> Btw, this is a very minimal test case:
> 
> $ cat pr38649.cpp
> // clang -cc1 -triple i386-- -emit-obj pr38649.cpp
> void a() { asm(".cfi_restore %ebp\n"); }
> 
> $ clang -cc1 -triple i386-- -emit-obj pr38649.cpp
> error: this directive must appear between .cfi_startproc and .cfi_endproc
> directives
> 1 error generated.

This seems like everything is working as intended. If you want to do your own CFI, maybe use a standalone .s file or a naked function, or force -funwind-tables.

> If you attempt to compile this for x86_64, clang blows up in a different way:
> 
> $ clang -cc1 -triple x86_64-- -emit-obj -munwind-tables pr38649.cpp
> Assertion failed: ((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
> "Invalid size"), function EmitIntValue, file
> /usr/src/contrib/llvm/lib/MC/MCStreamer.cpp, line 115.
> Abort trap

That's lame. :( If you don't make an object, we generate this asm:

_Z1av:
        .cfi_startproc
        #APP
        .cfi_restore -2
        #NO_APP
        retq
        .cfi_endproc

The -2 comes from this line in X86RegisterInfo.td:
def EDI : X86Reg<"edi", 7, [DI, HDI]>, DwarfRegNum<[-2, 7, 7]>;
def EBP : X86Reg<"ebp", 5, [BP, HBP]>, DwarfRegNum<[-2, 4, 5]>;
def ESP : X86Reg<"esp", 4, [SP, HSP]>, DwarfRegNum<[-2, 5, 4]>;

The first entry is the register number used for 32-bit x86, and the second and third I don't know, maybe x64 and x32. I guess we need to diagnose it.