Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler segfault in showcase.d #32

Closed
John-Colvin opened this issue Oct 26, 2015 · 6 comments
Closed

compiler segfault in showcase.d #32

John-Colvin opened this issue Oct 26, 2015 · 6 comments

Comments

@John-Colvin
Copy link

OS X 10.11.1, LLVM 3.6.2

% ../../build/bin/ldmd2 showcase.d 
In file included from calypso_cache.h:1:
./showcase.hpp:40:32: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
        int echo(int a, int b) override;
                               ^
./showcase.hpp:41:38: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
        virtual float echo2(float f) override;
                                     ^
./showcase.hpp:63:47: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
        virtual const char *hello(bool pluto) override;
                                              ^
3 warnings generated.
void* __tmp1800 = void;
 , __tmp1800 = cast(void*)this , __tmp1800 += -16L;
return (cast(DCXXclass)__tmp1800).hello(ceres);
0  ldc2                     0x00000001103f9859 llvm::sys::PrintStackTrace(__sFILE*) + 57
1  ldc2                     0x00000001103f9db6 SignalHandler(int) + 218
2  libsystem_platform.dylib 0x00007fff9712552a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fbdac1b7030 _sigtramp + 352918304
4  ldc2                     0x000000010e4c1304 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) + 292
5  ldc2                     0x000000010de6992b cpp::LangPlugin::toDefineFunction(FuncDeclaration*) + 171
6  ldc2                     0x000000010de699ef non-virtual thunk to cpp::LangPlugin::toDefineFunction(FuncDeclaration*) + 47
7  ldc2                     0x000000010dedb130 DtoDefineFunction(FuncDeclaration*) + 1888
8  ldc2                     0x000000010dec7d45 CodegenVisitor::visit(FuncDeclaration*) + 53
9  ldc2                     0x000000010db54de1 FuncDeclaration::accept(Visitor*) + 33
10 ldc2                     0x000000010dec63f4 CodegenVisitor::visit(TemplateInstance*) + 356
11 ldc2                     0x000000010dc4dc61 TemplateInstance::accept(Visitor*) + 33
12 ldc2                     0x000000010dec5a24 Declaration_codegen(Dsymbol*) + 68
13 ldc2                     0x000000010df01534 codegenModule(IRState*, Module*, bool) + 820
14 ldc2                     0x000000010da3d47f ldc::CodeGenerator::emit(Module*) + 431
15 ldc2                     0x000000010da6d766 main + 8966
16 libdyld.dylib            0x00007fff82b0f5ad start + 1
17 libdyld.dylib            0x0000000000000003 start + 2102331991
Error: Error executing /Users/john/Git/Calypso/build/bin/ldc2: Segmentation fault: 11 (core dumped)
@Syniurge
Copy link
Owner

No idea here, sorry. You're probably the first person to try it on OS X.

A class and its methods were previously correctly emitted, since the following is a dump of a thunk generated by Calypso:

    void* __tmp1800 = void;
    , __tmp1800 = cast(void*)this , __tmp1800 += -16L;
    return (cast(DCXXclass)__tmp1800).hello(ceres);

so not everything is broken, but I've no idea what goes wrong with the function template instance. The segfaulting line would be helpful to figure out what's happening, could you rebuild Calypso with -DCMAKE_BUILD_TYPE=RelWithDebInfo?

@John-Colvin
Copy link
Author

with -DCMAKE_BUILD_TYPE=RelWithDebInfo I get

[ 21%] Generating src/core/atomic.o
ldc2(31541,0x7fff722e8000) malloc: *** mach_vm_map(size=140621419954176) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Error: out of memory
make[2]: *** [runtime/src/core/atomic.o] Error 1
make[1]: *** [runtime/CMakeFiles/druntime-ldc.dir/all] Error 2
make: *** [all] Error 2

while compiling Calypso.

@Syniurge
Copy link
Owner

There's some weird stuff going on OS X..

You may be able to gather more info by debugging the ldc2 command, first by retrieving the command line for the generation of atomic.o with make VERBOSE=1

And then if your debugger is gdb (unlikely but I'm not familiar with LLDB):

gdb build/bin/ldc2 -- [ldc2 args during the compilation of atomic.o]

In gdb:

break malloc_error_break
run
bt

It would be very interesting to know where that malloc call comes from. If LDC 0.15.2 works on OS X then it's probably due to a Calypso modification, but again I'm clueless.

@wilsonk
Copy link

wilsonk commented Oct 27, 2015

Hello @Syniurge and @John-Colvin,

It looks like your error might be because the build line you used is missing a couple things. Here is my 'build.sh' file:

rm -f calypso_cache* *.o
clang++ -std=c++11 -c showcase.cpp -o showcase.cpp.o
ar rcs libshowcase.a showcase.cpp.o
ldc2 -v -cpp-args -std=c++11 -Llibshowcase.a -L-lstdc++ showcase.d

So really you should just need the '-cpp-args -std=c++11' option to build the showcase demo (and -L-lstdc++ I guess :) ). It builds and works here with Calypso from git today and OS X 10.10.3 with clang/llvm 3.6.2.

@Syniurge
Copy link
Owner

Hi Kelly, neat that Calypso is working at least partially for you on OS X!

-std=c++11 hasn't been needed for a while for showcase.d, it just prevents the warnings, so I'm not sure what goes wrong on John's setup, why ldc2 built with -DCMAKE_BUILD_TYPE=RelWithDebInfo blows a fuse. I don't have access to an OS X machine unfortunately..

@Syniurge Syniurge added the os x label May 30, 2016
@timotheecour
Copy link
Collaborator

timotheecour commented Jan 16, 2018

out of memory

IIRC

*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Error: out of memory

could be caused by building ldc using too much memory, depending on options (eg: release builds use more memory, make -j8 uses more memory, having a VM running on the side (eg parallels with dedicated resources) also reduces available memory. IIRC I was able to fix this with make -j{smaller number}

require -std=c++11

Also, yes, the original error was clearly due to requiring -std=c++11;

-lstdc++ vs -lc++

see #82

break malloc_error_break

IIRC this doesn't work on OSX, instead use break malloc_printf worked for me

showcase.cpp doesn't exist in git master; I believe this was moved to Calypso/tests/calypso/basics.d

this works (modulo applying other fixes I mentioned for OSX)

ldc2 -run Calypso/tests/calypso/basics.d
NOTE: adding -cpp-verbosediags (or if the command fails for other reasons), the warnings will be shown: warning: 'override' keyword is a C++11 extension
adding -cpp-args -std=c++11 will suppress these warnings

will close once docs are updated in corresponding files

EDIT: docs were updated in c1cbe1b, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants