Bug 17740 – ghost "internal" symbols show up sometimes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-08-10T17:17:40Z
Last change time
2024-12-13T18:53:58Z
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#19299 →

Comments

Comment #0 by schveiguy — 2017-08-10T17:17:40Z
In unknown circumstances, CTFE initializations can cause a symbol "internal" to be emitted to the object file. I'm pretty sure this isn't supposed to happen. When it does happen, you get linker errors that "internal" isn't defined. A current example where it is blocking a PR: https://github.com/dlang/phobos/pull/5683 Note the error from the builds: generated/freebsd/release/32/libphobos2.a(file_5f5_798.o)(.text._D3std4file28__T17statTimeToStdTimeVai97Z17statTimeToStdTimeFNaNbNfKS4core3sys5posix3sys4stat6stat_tZS3std8datetime7systime7SysTime+0x61): In function `_D3std4file28__T17statTimeToStdTimeVai97Z17statTimeToStdTimeFNaNbNfKS4core3sys5posix3sys4stat6stat_tZS3std8datetime7systime7SysTime': : undefined reference to `internal' generated/freebsd/release/32/libphobos2.a(file_5f6_7a4.o)(.text._D3std4file29__T17statTimeToStdTimeVai109Z17statTimeToStdTimeFNaNbNfKS4core3sys5posix3sys4stat6stat_tZS3std8datetime7systime7SysTime+0x61): In function `_D3std4file29__T17statTimeToStdTimeVai109Z17statTimeToStdTimeFNaNbNfKS4core3sys5posix3sys4stat6stat_tZS3std8datetime7systime7SysTime': : undefined reference to `internal' generated/freebsd/release/32/libphobos2.a(systime_31a9_2ce.o)(.data+0x0): undefined reference to `internal' generated/freebsd/release/32/libphobos2.a(systime_31a9_2ce.o)(.rodata+0x8): undefined reference to `internal' generated/freebsd/release/32/libphobos2.a(systime_31a9_2ce.o)(.text._D3std8datetime7systime7SysTime11toLocalTimeMxFNaNbNfZS3std8datetime7systime7SysTime+0x18): In function `_D3std8datetime7systime7SysTime11toLocalTimeMxFNaNbNfZS3std8datetime7systime7SysTime': : undefined reference to `internal' generated/freebsd/release/32/libphobos2.a(systime_31a9_2ce.o)(.text._D3std8datetime7systime7SysTime5toUTCMxFNaNbNfZS3std8datetime7systime7SysTime+0x18): more undefined references to `internal' follow Another example: https://github.com/dlang/dmd/blob/master/src/ddmd/tocsym.d#L681 I found in the compiler these lines: https://github.com/dlang/dmd/blob/master/src/ddmd/tocsym.d#L662 https://github.com/dlang/dmd/blob/master/src/ddmd/tocsym.d#L681 Which explain how the symbol name is generated. Those are in a section titled "CTFE stuff". Just recording this bug here so it's not forgotten. I have no idea how to reduce it.
Comment #1 by schveiguy — 2017-08-10T18:38:11Z
(In reply to Steven Schveighoffer from comment #0) > Another example: Wrong link, here it is: https://forum.dlang.org/post/[email protected]
Comment #2 by issues.dlang — 2017-08-10T18:39:14Z
Well, it looks like it relates to directly assigning a non-null value to the _timezone member at compile time. The new TimeZone class declaration is not required. All you have to do to trigger it is to change line # 8996 at the bottom of std.datetime.systime from Rebindable!(immutable TimeZone) _timezone; to Rebindable!(immutable TimeZone) _timezone = UTC(); Unfortunately, declaring a struct like struct S { Rebindable!(immutable TimeZone) _timezone = UTC(); } does not exhibit the problem. So, I don't know how to create a small test case that doesn't require the std.datetime code. But assigning UTC() like this before used to work. A backend bug on Windows prevened me from getting a similar PR merged where it added a new TimeZone class, and assigning UTC() in that case had exactly the same problem as I recall (certainly, assigning the new time zone class did, because that's what blocked the PR). But it worked perfectly fine on other OSes, and I'm fairly certain that I tried those changes again at some point, and the backend bug was gone - I just wanted to rework the changes, so they weren't committed. Regardless, it worked perfectly fine on non-Windows OSes previously. So, something about this broke in the last several releases. I'd have to do some research to figure out when it broke though.
Comment #3 by issues.dlang — 2017-08-12T08:37:20Z
Okay. If it's a regression, it's an old one. I suspect that I just didn't hit it before, because I didn't run make checkwhitespace, and running the full unittest build doesn't hit it (at least, not on my machine). I tried back as far as 2.069.0, and directly assigning UTC() to _timezone still triggered the problem with running make whitespace.
Comment #4 by schveiguy — 2017-10-10T15:50:51Z
Comment #5 by mrsmith33 — 2017-10-10T16:38:22Z
Here is even smaller test case: // main.d import texteditor; void main() {} // texteditor.d module texteditor; class EditorTextModel { void fun() { editor.fun2(); } TextEditor editor; } struct TextEditor { Piece* sentinel = new Piece; void fun2() {} import std.datetime : MonoTime; } struct Piece {} // dmd -m64 -lib -of="lib.lib" -debug -g -w -I="./" texteditor.d // dmd -m64 -of="app.exe" -debug -g -w -I="./" lib.lib main.d
Comment #6 by mrsmith33 — 2017-10-10T17:29:40Z
Looks like the problem is with Piece* sentinel = new Piece; If I do that at runtime it works.
Comment #7 by schveiguy — 2017-10-10T17:41:28Z
Hm... I didn't see this before, but you have an import for MonoTime. On the original PR I saw this, it was an update to MonoTime. Can you confirm that your code works or not without MonoTime import (which seems to be doing nothing in your latest version)?
Comment #8 by schveiguy — 2017-10-10T17:42:10Z
Correction: PR was not about MonoTime but SysTime. But still, datetime seems to be involved.
Comment #9 by mrsmith33 — 2017-10-10T17:52:05Z
Error doesn't happen when `import std.datetime : MonoTime;` is removed
Comment #10 by robert.schadek — 2024-12-13T18:53:58Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19299 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB