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 19949 - C++ Mangling: add support for abi-tags from the Itanium ABI #9995

Closed
wants to merge 3 commits into from

Conversation

SSoulaimane
Copy link
Member

@SSoulaimane SSoulaimane commented Jun 8, 2019

Implements "abi-tags" from the Itanium ABI specification.
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangle.abi-tag.

By introducing a special compile time attribute @__gnu_abi_tag().

This is crucial in order to interface std::string and std::list on linux.

See: issue 14956 (comment 13).

@SSoulaimane SSoulaimane force-pushed the cpp_abi_tag branch 7 times, most recently from a661c7d to ea0d336 Compare June 8, 2019 18:50
attribSemantic(uad);
if (uad.atts)
{
// detect the special attribute @__gnu_abi_tag(...)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a magic name. I would prefer to implement this as a true UDA which can use the fully qualified name to resolve any conflicts. This would avoid the need for the ugly double underscore prefix. You can have a look at how the @selector attribute is implemented.

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'll take a look.

Copy link
Member Author

@SSoulaimane SSoulaimane Jun 10, 2019

Choose a reason for hiding this comment

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

Yes, that is a better approach. I switched to it. I didn't make it part of druntime yet though.
I also ended up making an exception for namespaces from the UDA inheritance rules to stop members from inheriting this special UDA from namespaces, this is how it behaves in C++.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the core.attribute addition dlang/druntime#2639. Once it gets in I'll activate the module checks.

@@ -150,18 +150,21 @@ private final class CppMangleVisitor : Visitor
Objects components; // array of components available for substitution
OutBuffer* buf; // append the mangling to buf[]
Loc loc; // location for use in error messages
Strings* abiTags; // record of the processed abi-tags
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use D arrays?

Copy link
Member Author

Choose a reason for hiding this comment

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

DMD arrays mange their own memory.

Copy link
Contributor

@JinShil JinShil Jun 12, 2019

Choose a reason for hiding this comment

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

@SSoulaimane DMD is a mechanical translation from a C++ code base so it contains a lot of code that is not considered idiomatic D. Please prefer modern idiomatic D types and patterns (unless explicitly asked not to) for any new code so we can gradually transition DMD away from the cruft of the past.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please use Ddoc comments.

Copy link
Member Author

@SSoulaimane SSoulaimane Jun 12, 2019

Choose a reason for hiding this comment

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

The array is being filled by the visitor, I'm not sure that using D arrays is an improvement here because they rely on the GC. As I understand DMD is moving away from the GC.

Copy link
Contributor

@jacob-carlborg jacob-carlborg Jun 12, 2019

Choose a reason for hiding this comment

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

As I understand DMD is moving away from the GC.

No, not that I've heard of. Also, D arrays can be allocated using other means than the GC.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not that I've heard of.

I thought using mem.xmalloc and mem.xfree was supposed to make DMD more responsible about memory.

Also, D arrays can be allocated using other means than the GC.

How do you append to it.

The array fed to the visitor is stack allocated hence automatically freed.

src/dmd/dsymbolsem.d Outdated Show resolved Hide resolved
src/dmd/cppmangle.d Outdated Show resolved Hide resolved
@WalterBright
Copy link
Member

Why is this targeting stable rather than master?

@WalterBright
Copy link
Member

This is a very large PR. Please factor out isPosix into a separate one.

@SSoulaimane
Copy link
Member Author

Why is this targeting stable rather than master?

It just happened that way because it was based on #9946. I'll change that before it's merged.

@SSoulaimane
Copy link
Member Author

SSoulaimane commented Jun 8, 2019

This is a very large PR. Please factor out isPosix into a separate one.

Rebased

@WalterBright
Copy link
Member

@SSoulaimane SSoulaimane force-pushed the cpp_abi_tag branch 3 times, most recently from 2b44e5a to 70037d0 Compare June 10, 2019 16:16
}
if (e.op == TOK.type)
{
e.error("`@%s` at least one argument expected", Id.udaGNUAbiTag.toChars());
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this be handled automatically?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that is the case where the UDA is a type i.e. @type instead of @type().

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I would expect the compiler to complain if the UDA is a function expecting one argument. But that seems to not be the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's useful to have.

@SSoulaimane SSoulaimane force-pushed the cpp_abi_tag branch 2 times, most recently from 4e4d22f to a2af683 Compare June 11, 2019 19:11
@SSoulaimane
Copy link
Member Author

Because of the use of ancient C++ compilers in some the CIs, I will remove the runnable tests and stick to manual checks of the mangling with compilable tests instead. It has been demonstrated that it works at least.
Concrete support of the abi_tag only started in GCC 5 and Clang 3.9. Before that it was flimsy in GCC and unsupported in clang.

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 12, 2019

Thanks for your pull request and interest in making D better, @SSoulaimane! 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
19949 normal C++ Mangling: no support for abi-tags from the Itanium ABI

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 "master + dmd#9995"

*/
this(OutBuffer* buf, Loc loc)
this(OutBuffer* buf, Loc loc, Strings* abiTags = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I know Walter doesn’t like default values for parameters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's something with being less readable, but you'll have to ask him.

Copy link
Member Author

@SSoulaimane SSoulaimane Jun 12, 2019

Choose a reason for hiding this comment

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

Well, pick your poison. Either this or an overload. Everything has a purpose.

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer a default value, but it’s not my decision.

It’s also possible to explicitly pass in the default value.

src/dmd/semantic2.d Outdated Show resolved Hide resolved
@Geod24
Copy link
Member

Geod24 commented Jun 12, 2019

Any chance to get a runnable test with this ? compilable tests are great for development and changes, because you clearly see what went wrong, but runnable are better in terms of coverage.

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.

And also, extern(C++, "namespace") is preferred (and code path are quite different).
You can either tests both or test only the string version (I'll have a deprecation PR for the non-string version up soon).

test/compilable/cppmagle_abitag.d Outdated Show resolved Hide resolved
test/compilable/cppmagle_abitag.d Outdated Show resolved Hide resolved
test/compilable/cppmagle_abitag.d Outdated Show resolved Hide resolved
test/compilable/cppmagle_abitag.d Outdated Show resolved Hide resolved
@SSoulaimane
Copy link
Member Author

SSoulaimane commented Jun 12, 2019

Any chance to get a runnable test with this ? compilable tests are great for development and changes, because you clearly see what went wrong, but runnable are better in terms of coverage.

1e58f7c. I deleted them because semaphore and OSX on the auto-tester have ancient c++ compilers.

@Geod24
Copy link
Member

Geod24 commented Jun 13, 2019

1e58f7c. I deleted them because semaphore and OSX on the auto-tester have ancient c++ compilers.

Could easily disable it on OSX. Semaphore you'll need to read the environment variable I suppose.

@SSoulaimane
Copy link
Member Author

Semaphore you'll need to read the environment variable I suppose.

To do what?

@Geod24
Copy link
Member

Geod24 commented Jun 13, 2019

Disable it

@SSoulaimane SSoulaimane force-pushed the cpp_abi_tag branch 8 times, most recently from d9d43f7 to cca05a0 Compare June 16, 2019 17:13
@SSoulaimane SSoulaimane force-pushed the cpp_abi_tag branch 4 times, most recently from 39bb395 to f3703cb Compare June 29, 2019 21:26
@Geod24
Copy link
Member

Geod24 commented Mar 28, 2020

The replacement PR has been merged. Thanks for getting us started on this, your work was a great help.

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