Bug 13666 – Undefined Symbols for __gshared data symbols in templates

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2014-10-30T08:27:00Z
Last change time
2015-02-18T03:38:57Z
Keywords
link-failure, pull
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2014-10-30T08:27:20Z
Compile this module to a library: module test; template drt_envvars_enabled() { extern(C) __gshared bool drt_envvars_enabled = false; } bool foo() { return drt_envvars_enabled!(); } /////////// > dmd -lib test.d Then link it with main.d: import test; int main() { return foo(); } ////////////// > dmd main.d test.lib OPTLINK (R) for Win32 Release 8.00.15 Copyright (C) Digital Mars 1989-2013 All rights reserved. http://www.digitalmars.com/ctg/optlink.html test.lib(test) Error 42: Symbol Undefined __D4test25__T19drt_envvars_enabledZ19drt_envvars_enabledb --- errorlevel 1 According to https://github.com/D-Programming-Language/druntime/pull/986, this fails for Win32 and OS/X, but works for other platform. It also works if the variable is not "__gshared" or it is initialized to a non-zero value. It is probably caused by some bad BSS optimization.
Comment #1 by r.sagitario — 2014-10-31T10:05:26Z
Comment #2 by schveiguy — 2014-10-31T12:15:38Z
Very similar issue encountered: https://github.com/D-Programming-Language/druntime/pull/990 Fails on only OSX and Windows. Error is a undefined symbol, just like this. In my case, the same code, compiled without -inline, succeeds to build. Seems different for your case.
Comment #3 by github-bugzilla — 2014-10-31T17:43:35Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/fbec2df168658b64ea699c3cbbad5d73df5e310e Merge pull request #4099 from rainers/issue_13666 Fix issue 13666: Undefined Symbols for __gshared data symbols in templates
Comment #4 by github-bugzilla — 2015-02-18T03:38:57Z