Skip to content

Conversation

@rainers
Copy link
Member

@rainers rainers commented Dec 24, 2018

ensure s.csym initialized

@dlang-bot
Copy link
Contributor

dlang-bot commented Dec 24, 2018

Thanks for your pull request, @rainers!

Bugzilla references

Auto-close Bugzilla Severity Description
18456 blocker crt_constructor/crt_destructor segfaults if -lib

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "stable + dmd#9132"

@rainers rainers changed the base branch from master to stable December 24, 2018 11:49
@rainers
Copy link
Member Author

rainers commented Dec 24, 2018

I just noticed that even if no longer crashing, it still doesn't work as expected: the initializing reference is placed into a different object file inside the library, so never linked and the function is actually not called.

I'll remove auto-merge and see if a fix can be added. AFAICT auto-merge doesn't work on stable anyway ATM?

@wilzbach
Copy link
Contributor

Yeah auto-merge requires all CI to pass, but I don't know why Appveyor is unable to build this PR. Looks like it didn't even try.

@rainers rainers force-pushed the issue18456 branch 4 times, most recently from 3b6f58a to 69fa274 Compare December 24, 2018 16:27
delay objmod.setModuleCtorDtor until the function is actually generated
don't make them extra object files in a library, they will never be linked
@rainers
Copy link
Member Author

rainers commented Dec 25, 2018

Works now, but implementation and tests are very different. Some refactorings might be desirable:

  • use flags enum for isCrtCtorDtor
  • move evaluation into semantic analysis so its usage is not limited to the glue layer

I'd rather make these changes on master, though.

else if (auto f = s.isFuncDeclaration())
{
objmod.setModuleCtorDtor(s.csym, isCtor);
f.isCrtCtorDtor |= isCtor ? 1 : 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the |= ? Is there ever a case where 1 and 2 can both be set? Or any other bits?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit surprised, too, but the existing implementation allows both: https://github.com/dlang/dmd/blob/master/test/runnable/test17868b.d#L7

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pragma just places a function pointer in the init/fini segment, so as a low-level tool it can be used as people want.

Copy link
Member

@WalterBright WalterBright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the |= then it's good to go.

@thewilsonator thewilsonator dismissed WalterBright’s stale review December 26, 2018 05:53

Apparently a function can be both a constructor and a destructor.

@thewilsonator
Copy link
Contributor

Adding 72h -> merge

@thewilsonator thewilsonator added Merge:72h no objection -> merge The PR will be merged if there are no objections raised. Merge:auto-merge labels Dec 29, 2018
@dlang-bot dlang-bot merged commit 2842e8b into dlang:stable Jan 1, 2019
pd.error("can only apply to a single declaration");
}

visit(cast(AttribDeclaration)pd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move the call to the base class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flag has to be set before visiting the function generation, because the pointers in init/fini are now written when visiting the function, which might be delayed with multiobj.
The problem was that they ended up in a different object file.

@MartinNowak
Copy link
Member

MartinNowak commented Jan 1, 2019

This PR had quite a bad timing during the beta for a low-level compiler change.

@rainers
Copy link
Member Author

rainers commented Jan 2, 2019

This PR had quite a bad timing during the beta for a low-level compiler change.

It's been lingering here quite some time, but I doubt a lot of people have used the feature as it is still undocumented.

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

Labels

Merge:auto-merge Merge:72h no objection -> merge The PR will be merged if there are no objections raised. Severity:Bug Fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants