Bug 5332 – Undefined reference to zero length array

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-12-08T13:10:18Z
Last change time
2017-12-18T22:56:01Z
Keywords
link-failure, patch, pull, wrong-code
Assigned to
yebblies
Creator
Iain Buclaw
See also
https://issues.dlang.org/show_bug.cgi?id=7997

Comments

Comment #0 by ibuclaw — 2010-12-08T13:10:18Z
Testcase: int[0] arr; void main() { auto a = arr; } Yields: test.o: In function `_Dmain': test.d:(.text._Dmain+0x16): undefined reference to `_D4test3arrG0i' collect2: ld returned 1 exit status --- errorlevel 1 Most likely cause I guess is incorrect mangling. Regards
Comment #1 by ibuclaw — 2010-12-09T05:45:27Z
Actually, it's something else. DMD doesn't output var declarations that have no size. Patch to always write out globals: --- dmd~/toobj.c 2010-11-19 22:39:05.011906002 +0000 +++ dmd/toobj.c 2010-12-09 13:29:19.672718003 +0000 @@ -1287,7 +1287,7 @@ else s->Sseg = DATA; #endif - if (sz) + if (1 || sz) { outdata(s); if (isExport()) obj_export(s,0); Regards
Comment #2 by yebblies — 2012-02-03T00:04:41Z
Comment #3 by github-bugzilla — 2012-05-19T21:46:10Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/6a18e736d2296a7f041ba6d23ba73777a14ba5a7 Issue 5332 - Undefined reference to zero length array Always emit globals, even if they are zero-length static arrays. https://github.com/D-Programming-Language/dmd/commit/ab17ac3a249eb4485632c74e88dfe3c96d0b511c Merge pull request #689 from yebblies/issue5332 Issue 5332 - Undefined reference to zero length array
Comment #4 by bugzilla — 2012-05-19T23:35:02Z
The patch works for ELF objects, but not for others.
Comment #5 by github-bugzilla — 2012-05-20T00:53:09Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/c4ae9e312d7946e7041e065b26996abff92d4424 partial fix Issue 5332 - Undefined reference to zero length array
Comment #6 by github-bugzilla — 2012-05-20T00:53:28Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/d6ee976c5c956a03ba807d1ce411685903c2664b partial fix Issue 5332 - Undefined reference to zero length array
Comment #7 by bearophile_hugs — 2012-05-20T05:29:04Z
Maybe related to Issue 7997
Comment #8 by hsteoh — 2014-07-12T05:07:23Z
Seems to have been fixed in git HEAD. Tested on Linux 64-bit, dmd revision 2cd115bb6738e884c19b32b1640b23ed25efc0d6. Please reopen if this still happens.
Comment #9 by hsteoh — 2014-07-12T05:08:23Z
Gah, nevermind, missed the note about fix only working for ELF.
Comment #10 by bugzilla — 2017-10-25T07:44:12Z
Comment #11 by bugzilla — 2017-10-26T19:15:36Z
Comment #12 by github-bugzilla — 2017-10-26T23:57:47Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/239c35233e62f289e6e868b7d4eafdcd63c72ea4 fix Issue 5332 - Undefined reference to zero length array https://github.com/dlang/dmd/commit/ff4bdb660e6ed2ab1eb6c8725bd673417ef21a41 Merge pull request #7249 from WalterBright/fix5332 fix Issue 5332 - Undefined reference to zero length array
Comment #13 by github-bugzilla — 2017-12-18T22:56:01Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/239c35233e62f289e6e868b7d4eafdcd63c72ea4 fix Issue 5332 - Undefined reference to zero length array https://github.com/dlang/dmd/commit/ff4bdb660e6ed2ab1eb6c8725bd673417ef21a41 Merge pull request #7249 from WalterBright/fix5332