{"action":"created","issue":{"url":"https://api.github.com/repos/ldc-developers/ldc/issues/1310","repository_url":"https://api.github.com/repos/ldc-developers/ldc","labels_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1310/labels{/name}","comments_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1310/comments","events_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1310/events","html_url":"https://github.com/ldc-developers/ldc/issues/1310","id":135247365,"number":1310,"title":"Different function linkage type in object file for DMD vs. LDC","user":{"login":"JohanEngelen","id":10983051,"avatar_url":"https://avatars.githubusercontent.com/u/10983051?v=3","gravatar_id":"","url":"https://api.github.com/users/JohanEngelen","html_url":"https://github.com/JohanEngelen","followers_url":"https://api.github.com/users/JohanEngelen/followers","following_url":"https://api.github.com/users/JohanEngelen/following{/other_user}","gists_url":"https://api.github.com/users/JohanEngelen/gists{/gist_id}","starred_url":"https://api.github.com/users/JohanEngelen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohanEngelen/subscriptions","organizations_url":"https://api.github.com/users/JohanEngelen/orgs","repos_url":"https://api.github.com/users/JohanEngelen/repos","events_url":"https://api.github.com/users/JohanEngelen/events{/privacy}","received_events_url":"https://api.github.com/users/JohanEngelen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2016-02-21T19:28:59Z","updated_at":"2016-03-29T15:02:31Z","closed_at":"2016-03-28T10:39:16Z","body":"This concerns Windows, I did not check the other OS'es.\r\n\r\n```D\r\nextern (C++) class Expression : RootObject\r\n{\r\npublic:\r\n//...\r\n    final Expression optimize(int result, bool keepLvalue = false)\r\n    {\r\n        return Expression_optimize(this, result, keepLvalue);\r\n    }\r\n//...\r\n}\r\n```\r\nWhen compiled with DMD2.069.2, and running dumpbin, the `Expression::optimize` symbol is put in a section with `selection    2 (pick any)`:\r\n```\r\n1EE 00000000 SECTF8 notype       Static       | .text\r\n    Section length   13, #relocs    1, #linenums    0, checksum        0, selection    2 (pick any)\r\n```\r\n\r\nWhen compiled with LDC0.17, running dumpbin, the `Expression::optimize` symbol is put in a section with `selection 1 (pick no duplicates)`:\r\n```\r\n0AE 00000000 SECT3D notype       Static       | .text\r\n    Section length    6, #relocs    1, #linenums    0, checksum        0, selection    1 (pick no duplicates)\r\n```\r\n\r\nThe difference in linkage properties shows up in trying to build LDC (with DDMD front-end) using LDC as compiler. Because the C++ source contains a second implementation of `Expression::optimize` as inlined member function:\r\n```C++\r\nclass Expression : public RootObject\r\n{\r\npublic:\r\n//...\r\n    Expression *optimize(int result, bool keepLvalue = false)\r\n    {\r\n        return Expression_optimize(this, result, keepLvalue);\r\n    }\r\n```\r\nThis then results in a linker error (LNK2005) of multiple defined symbols.\r\n\r\nI don't know which compiler is correct: DMD or LDC.\r\n\r\nIf this needs fixing in LDC, LDC can be made to output all functions in `selection    2 (pick any)` sections by putting the functions in comdat sections: \r\n```diff\r\nLinkageWithCOMDAT DtoLinkage(Dsymbol *sym) {\r\n  if (DtoIsTemplateInstance(sym)) {\r\n    return LinkageWithCOMDAT(templateLinkage, supportsCOMDAT());\r\n  }\r\n-  return LinkageWithCOMDAT(llvm::GlobalValue::ExternalLinkage, false);\r\n+  return LinkageWithCOMDAT(llvm::GlobalValue::ExternalLinkage, true);\r\n}\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ldc-developers/ldc/issues/comments/202941931","html_url":"https://github.com/ldc-developers/ldc/issues/1310#issuecomment-202941931","issue_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1310","id":202941931,"user":{"login":"JohanEngelen","id":10983051,"avatar_url":"https://avatars.githubusercontent.com/u/10983051?v=3","gravatar_id":"","url":"https://api.github.com/users/JohanEngelen","html_url":"https://github.com/JohanEngelen","followers_url":"https://api.github.com/users/JohanEngelen/followers","following_url":"https://api.github.com/users/JohanEngelen/following{/other_user}","gists_url":"https://api.github.com/users/JohanEngelen/gists{/gist_id}","starred_url":"https://api.github.com/users/JohanEngelen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JohanEngelen/subscriptions","organizations_url":"https://api.github.com/users/JohanEngelen/orgs","repos_url":"https://api.github.com/users/JohanEngelen/repos","events_url":"https://api.github.com/users/JohanEngelen/events{/privacy}","received_events_url":"https://api.github.com/users/JohanEngelen/received_events","type":"User","site_admin":false},"created_at":"2016-03-29T15:02:31Z","updated_at":"2016-03-29T15:02:31Z","body":"The above code indeed links with DMD also on Mac, but not with LDC."}}