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

DCD crashes on startup in std.experimental.logger #1358

Closed
Hackerpilot opened this issue Mar 18, 2016 · 20 comments
Closed

DCD crashes on startup in std.experimental.logger #1358

Hackerpilot opened this issue Mar 18, 2016 · 20 comments

Comments

@Hackerpilot
Copy link

Using LDC built from commit 6e0bada

Stack trace:

#0  0x0000000000598058 in rt.monitor_.ensureMonitor(Object) ()
#1  0x0000000000598126 in _d_monitorenter ()
#2  0x00000000004665e3 in std.experimental.logger.core.Logger.memLogFunctions!(64).logImpl!(160, "src/server/server.d", "server.server.main", "int server.server.main(string[] args)", "server.server", immutable(char)[], immutable(char)[]).logImpl(lazy immutable(char)[], lazy immutable(char)[]) (this=0x7ffff7fc38e8, _param_0={string delegate() (void)} 0x7fffffffd400, _param_1={string delegate() (void)} 0x7fffffffd3f0) at /usr/local/include/d/std/experimental/logger/core.d:948
#3  0x0000000000459178 in std.experimental.logger.core.defaultLogFunction!(64).defaultLogFunction!(160, "src/server/server.d", "server.server.main", "int server.server.main(string[] args)", "server.server", immutable(char)[], immutable(char)[]).defaultLogFunction(lazy immutable(char)[], lazy immutable(char)[]) (_param_0={string delegate() (void)} 0x7fffffffd468, _param_1={string delegate() (void)} 0x7fffffffd458) at /usr/local/include/d/std/experimental/logger/core.d:487
#4  0x000000000045723d in D main (args=...) at server.d:160
@Hackerpilot
Copy link
Author

This may related to #1377.

@JohanEngelen
Copy link
Member

@Hackerpilot Is it fixed by this?

--- a/gen/typinf.cpp
+++ b/gen/typinf.cpp
@@ -726,8 +726,11 @@ void TypeInfoDeclaration_codegen(TypeInfoDeclaration *decl, IRState *p) {
     } else {
       irg->type = LLStructType::create(gIR->context(), decl->toPrettyChars());
     }
-    LLGlobalVariable *g = new LLGlobalVariable(gIR->module, irg->type, true,
-                                               lwc.first, nullptr, mangled);
+    // Create the symbol. We need to keep it mutable as the type is not declared
+    // as immutable on the D side, plus synchronized() can be used on the
+    // implicit monitor.
+    auto g = new LLGlobalVariable(gIR->module, irg->type, false, lwc.first,
+                                  nullptr, mangled);
     setLinkage(lwc, g);
     irg->value = g;
   }

Thanks for testing!

@Hackerpilot
Copy link
Author

It is. With that patch DCD passes its test suite.

@JohanEngelen
Copy link
Member

@Hackerpilot Thanks for the fix confirmation.
Closing, as this is a duplicate of #1377.

@Hackerpilot
Copy link
Author

I made a fresh clone of LDC master (fa8fe51), and tried this again and it's failing in the same place. I checked that CPP file and see that the fix is there, but the crash is back. Any ideas?

@JohanEngelen
Copy link
Member

@Hackerpilot What happens when you apply the patch of this PR? #1384

@JohanEngelen JohanEngelen reopened this Apr 5, 2016
@Hackerpilot
Copy link
Author

That patch is against the ltsmaster branch, so I'll have to translate it to D first.

@JohanEngelen
Copy link
Member

@Hackerpilot Sorry didn't notice, working on new PR here: #1385

@Hackerpilot
Copy link
Author

For some reason that didn't break the build.

The line of ASM causing the segfault is

mov    rax,QWORD PTR [rax]

gdb tells me that the rax register's value at this point is 0.

Stack trace:

#0  0x00000000005a2a28 in rt.monitor_.ensureMonitor(Object) ()
#1  0x00000000005a2af6 in _d_monitorenter ()
#2  0x000000000046a793 in std.experimental.logger.core.Logger.memLogFunctions!(64).logImpl!(160, "src/server/server.d", "server.server.main", "int server.server.main(string[] args)", "server.server", immutable(char)[], immutable(char)[]).logImpl(lazy immutable(char)[], lazy immutable(char)[]) (this=0x7ffff7fc38e0, _param_0={string delegate() (void)} 0x7fffffffd410, _param_1={string delegate() (void)} 0x7fffffffd400) at /usr/local/include/d/std/experimental/logger/core.d:948
#3  0x000000000045d258 in std.experimental.logger.core.defaultLogFunction!(64).defaultLogFunction!(160, "src/server/server.d", "server.server.main", "int server.server.main(string[] args)", "server.server", immutable(char)[], immutable(char)[]).defaultLogFunction(lazy immutable(char)[], lazy immutable(char)[]) (_param_0={string delegate() (void)} 0x7fffffffd478, _param_1={string delegate() (void)} 0x7fffffffd468) at /usr/local/include/d/std/experimental/logger/core.d:487
#4  0x000000000045b33d in D main (args=...) at server.d:160

@JohanEngelen
Copy link
Member

Could you dustmite it?
(the crash is exactly what I would expect from an optimization bug with synchronize on an immutable object)

@Hackerpilot
Copy link
Author

I'm working on figuring out how to write the test script to catch that specific segfault.

Edit: https://github.com/CyberShadow/DustMite/wiki/Detecting-a-specific-segfault

@Hackerpilot
Copy link
Author

I'm no longer able to reproduce this issue with LDC at version 98c899b

@dnadlinger
Copy link
Member

Yep, we should be emitting TypeInfo as mutable for now.

@yotamr
Copy link

yotamr commented Sep 16, 2017

Seems to happen again on LDC 1.3.0:

#0 0x00007fbcfb0caa99 in rt.monitor_.ensureMonitor(Object) () from ./libagent.so #1 0x00007fbcfb0cab66 in _d_monitorenter () from ./libagent.so #2 0x00007fbcfae048ce in std.experimental.logger.core.Logger.log!(immutable(char)[]).log(const(std.experimental.logger.core.LogLevel), lazy immutable(char)[], int, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[]) (this=0x7fbcd4004258, ll=const(LogLevel).all, args=..., line=179, file=..., funcName=..., prettyFuncName=..., moduleName=...) at /opt/ldc2/bin/../import/std/experimental/logger/core.d:1259 #3 0x00007fbcfae031d9 in std.experimental.logger.core.log!(immutable(char)[]).log(lazy immutable(char)[], int, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[]) (arg=..., line=179, file=..., funcName=..., prettyFuncName=..., moduleName=...) at /opt/ldc2/bin/../import/std/experimental/logger/core.d:353 #4 0x00007fbcfae31613 in service.restapi.getRules() () at restapi.d:179

@JohanEngelen
Copy link
Member

@yotamr How about LDC 1.4.0 ?

@yotamr
Copy link

yotamr commented Sep 17, 2017 via email

@yotamr
Copy link

yotamr commented Sep 17, 2017

My code is a shared library loaded by an already-existing process. There are three threads running D code: one belonging to the process that loaded the .so, and two other threads handling HTTP communication. I tried reproducing it in two ways, both did not reproduce the crash:

  1. single-threaded app that writes as many logs as possible in a loop
  2. The same as Removed Phobos 1 from LDC tree. #1, only with three threads writing in a loop instead of one. All threads share the same logger object.

@dnadlinger
Copy link
Member

Could you please open a new issue for the crash you are seeing, including more detailed system information (OS/compiler/linker versions, processor, etc.) and a way to reproduce it?

What you are describing is a different problem than reported here, which was caused by TypeInfos being emitted as constant data.

@yotamr
Copy link

yotamr commented Sep 17, 2017 via email

@dnadlinger
Copy link
Member

Thanks!

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

No branches or pull requests

4 participants