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

Fix Issue 23814 - [Codegen] Calling member function of extern(C++) cl… #15063

Closed
wants to merge 8 commits into from

Conversation

naydef
Copy link

@naydef naydef commented Mar 31, 2023

…ass with multiple inheritance doesn't preserve the EBX register in some cases

Remade.
Also not much idea of what I'm doing.
Not sure how to test this.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @naydef! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Auto-close Bugzilla Severity Description
23814 normal [Codegen] Calling member function of extern(C++) class with multiple inheritance doesn't preserve the EBX register in some cases

Testing this PR locally

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

dub run digger -- build "master + dmd#15063"

@RazvanN7
Copy link
Contributor

RazvanN7 commented Apr 3, 2023

As stated in the issue, I cannot reproduce this for neither 32 or 64 bit.

32 bit output:

00000000 <_ZN9MainClass5func4Ev>:
   0:   55                      push   ebp
   1:   8b ec                   mov    ebp,esp
   3:   83 ec 08                sub    esp,0x8
   6:   e8 00 00 00 00          call   b <_ZN9MainClass5func4Ev+0xb>
   b:   58                      pop    eax
   c:   05 02 00 00 00          add    eax,0x2
  11:   89 45 fc                mov    DWORD PTR [ebp-0x4],eax
  14:   8b 4d fc                mov    ecx,DWORD PTR [ebp-0x4]
  17:   8d 81 40 00 00 00       lea    eax,[ecx+0x40]
  1d:   c9                      leave  
  1e:   c3                      ret   

Does not use ebx.

64 bit output:

0000000000000000 <_ZN9MainClass5func4Ev>:
   0:   48 8d 05 00 00 00 00    lea    rax,[rip+0x0]        # 7 <_ZN9MainClass5func4Ev+0x7>
   7:   c3                      ret

Does not use rbx.

I don't think this issue is valid.

@naydef
Copy link
Author

naydef commented Apr 3, 2023

I also replied in the issue report:

I'm using DMD64 D Compiler v2.102.2 on Linux. Compiling with: "dmd app.d -m32"

I see you check func4 (judging by name of the disassembly _ZN9MainClass5func4Ev), while my example code calls func1.
Use the second example code. You can use a debugger and break where func1 is called in _Dmain, step into the function and you'll see the usage of EBX register in a function called _THUNK0, which at the end jumps to _ZN9MainClass5func1Ev.

This issue has actually caused me trouble when interoperating with C++ code on Linux, it doesn't seem to exist on Windows.

Geod24
Geod24 previously requested changes Apr 3, 2023
Copy link
Member

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

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

  1. This needs a test (which can then be used to repro the issue @RazvanN7 )
  2. If the code is wrong, remove it, don't make the if always false.

@naydef
Copy link
Author

naydef commented Apr 3, 2023

I'm not sure how to test this I think I have a test for this, will add soon (code in issue report). It affected the C++ code which stored loop counter in this register in one place and some other used data in another case, causing crashing when the D proved object was used. DMD tends to keep stuff on the stack.

@naydef naydef requested a review from Geod24 April 4, 2023 16:27
@naydef
Copy link
Author

naydef commented Apr 15, 2023

ping (Requested changes are applied)

@RazvanN7
Copy link
Contributor

cc @WalterBright

@naydef
Copy link
Author

naydef commented Jun 11, 2023

@RazvanN7
Can this pull request be reviewed? It's blocking my project on Linux. I'll prefer It if the pull request get outright dismissed than rotting here for ages. If there's something I have to do, please tell me.

@dkorpel dkorpel dismissed Geod24’s stale review June 11, 2023 21:47

Requested changes are applied

@dkorpel
Copy link
Contributor

dkorpel commented Jun 11, 2023

Thanks for the ping, I've force pushed to restart the test suite and emailed Walter to request his review, since he wrote the backend.

@naydef
Copy link
Author

naydef commented Jun 12, 2023

@dkorpel
Can test suite be restarted (failure seems unrelated)?

@dkorpel
Copy link
Contributor

dkorpel commented Jun 13, 2023

I can rebase again, but @RazvanN7 has access to buildkite directly

@dkorpel
Copy link
Contributor

dkorpel commented Jun 13, 2023

Or merge despite the failure

@RazvanN7
Copy link
Contributor

I restarted the buildkite testing pipeline. Adding the 72h no objection -> merge label.

@RazvanN7 RazvanN7 added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Jun 14, 2023
assignaddrc(c1);
cdb.append(c1);
}
}
Copy link
Member

@WalterBright WalterBright Jun 15, 2023

Choose a reason for hiding this comment

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

"multiple inheritance doesn't preserve the EBX register in some cases"

Just removing all this code will break what it does. EBX register clobbering means it has to be saved/restored.

Copy link
Author

@naydef naydef Jun 15, 2023

Choose a reason for hiding this comment

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

I don't have much clue how to do that (not familiar with compiler backends).
Edit: I don't see what useful thing this code does, loading GOT in EBX and then it goes unused. So yea, clueless here.

Copy link
Member

Choose a reason for hiding this comment

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

I wrote a more explanatory comment in the bu

Copy link
Member

Choose a reason for hiding this comment

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

... in the bug report

@RazvanN7 RazvanN7 removed the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Aug 3, 2023
@adamdruppe
Copy link
Contributor

Merged in OpenD.

@RazvanN7
Copy link
Contributor

Since @WalterBright opposes the current implementation I see no point in keeping this PR open. If anyone wants to try and fix the issue there is a link from the bug report to the this PR.

@RazvanN7 RazvanN7 closed this Jan 10, 2024
@RazvanN7
Copy link
Contributor

@naydef Thanks for your work and the time you put into this. I'm sorry that this is not the outcome you desired, however, maybe this will prompt @WalterBright to fix this issue.

@naydef
Copy link
Author

naydef commented Jan 10, 2024

Closing it was long overdue...

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

Successfully merging this pull request may close these issues.

7 participants