Bug 10057 – [2.063 beta] Module info overwritten in shared phobos.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2013-05-10T05:52:00Z
Last change time
2013-05-19T05:12:13Z
Assigned to
nobody
Creator
mike

Comments

Comment #0 by mike — 2013-05-10T05:52:49Z
When running the phobos unittests against the shared phobos libraries, some of them fail because they are run twice. This because the Module info from the phobos lib is overwritten by the on from the binary. --- module std.c.linux.socket; import std.stdio; void main(){} unittest { writeln("Test"); } --- When linking with the static phobos: dmd test.d -unittest -defaultlib=:libphobos2.a it only prints "Test" once. While when linking with the shared phobos: dmd test.d -unittest -defaultlib=:libphobos2so.so "Test" is printed twice.
Comment #1 by bugzilla — 2013-05-10T22:28:27Z
I'm not sure this can be considered a bug in dmd. What's happening is that you've created two instances of std.c.linux.socket - one in the shared phobos library, and one in your executable which you are linking with the shared library. Which instance 'wins'? It really should be an error, but I don't know how it could be detected. I know what you're trying to do - run the unittests against the shared library. This will never work. It works when linking against a static library because the unittest module will override everything in the static library. It won't work with a shared library. I'm going to mark this as wontfix, as I can't think of a reasonable way to deal with this, other than "don't do that".
Comment #2 by code — 2013-05-10T22:45:19Z
Yes, wrong way of doing it and a known issuue. It's the reason why druntime uses https://github.com/D-Programming-Language/druntime/blob/master/src/test_runner.d. I didn't yet got around of updating phobos unittests to use the same mechanism. > It really should be an error, but I don't know how it could be detected. It can be detected, because the ModuleInfo* in the shared library points into the executable due to interposing. If we agree that we want to disallow interposing we can make it a runtime error.
Comment #3 by bugzilla — 2013-05-10T23:56:19Z
(In reply to comment #2) > It can be detected, because the ModuleInfo* in the shared library points into > the executable due to interposing. If we agree that we want to disallow > interposing we can make it a runtime error. Sounds good to me. Let's do it.
Comment #4 by github-bugzilla — 2013-05-19T05:11:51Z
Commits pushed to master at https://github.com/D-Programming-Language/druntime https://github.com/D-Programming-Language/druntime/commit/5aedb6e292693af18e75215164e9277c879777ce fix Issue 10057 - Module info overwritten in shared phobos - detect module collisions by checking that all ModuleInfo* of a DSO point into the same segment - abort the program in that case - added core.sys.linux.errno to find the name of the executable https://github.com/D-Programming-Language/druntime/commit/12b2214e39dd06a631b0941e9e596cf8cf6c3561 Merge pull request #487 from dawgfoto/fix10057 fix Issue 10057 - Module info overwritten in shared phobos