ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.19k stars 258 forks source link

Symbols with thunk appear in stack trace #3669

Open Geod24 opened 3 years ago

Geod24 commented 3 years ago

Just got this stack trace:

----------------
??:? nothrow void agora.test.Base.testAssertHandler(immutable(char)[], ulong, immutable(char)[]) [0x10ea8ad84]
??:? onAssertErrorMsg [0x10f844ac1]
??:? _d_assert_msg [0x10f844ed5]
??:? agora.consensus.data.Enrollment.Enrollment agora.test.Base.TestValidatorNode.createEnrollmentData() [0x10ea01c1b]
??:? _DThn760_5agora4test4Base17TestValidatorNode20createEnrollmentDataMFZSQCj9consensus4data10EnrollmentQm [0x10ea027da]
??:? void geod24.LocalRest.RemoteAPI!(agora.test.Base.TestAPI, agora.test.Base.Serializer).RemoteAPI.handleCommand(geod24.LocalRest.Command, agora.test.Base.TestAPI, geod24.LocalRest.FilterAPI, geod24.concurrency.Channel!(geod24.LocalRest.Response).Channel) [0x10ea94807]
[...]

Notice the _DThn760... that isn't demangled. The method in question is here.

JohanEngelen commented 3 years ago

I wonder if we should mark such thunks as DIFlagArtificial (such that LLVM treats them differently with debuginfo)...

kinke commented 3 years ago

I guess it'll always be there as long as the call isn't optimized to a tail call/jump. We only set the tail call attribute as long as the target function isn't variadic, which apparently only affects the optimizer. While glancing over our code, it didn't seem like we set the thunk function attribute, which might fix the musttail issue on AArch64 (IIRC).

kinke commented 3 years ago

We only set the tail call attribute as long as the target function isn't variadic, which apparently only affects the optimizer.

Cannot confirm - for a simple testcase and both Windows and Linux x64 targets, without -O, LLVM generates a jump, and the thunk isn't present in the backtraces:

interface I { void foo(); }

class C : I
{
    override void foo() { throw new Exception("Oops"); }
}

void bar(I i) { i.foo(); }

void main()
{
    bar(new C);
}

I've also tested adding the "thunk" function attribute, but it's apparently ignored (i.e., not in the final IR), at least as long as the thunk is prototyped.