Bug 22592 – importC: Segmentation fault indexing global array at run-time
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-12-12T21:06:09Z
Last change time
2021-12-13T16:35:35Z
Keywords
ImportC, pull, wrong-code
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2021-12-12T21:06:09Z
Compile with -betterC and run the resultant executable.
---
/* Comment out the next line to make the segfault go away. */
int testfn (void);
typedef struct config_s {
short field;
} config;
static const config table[10] = {
{0}, {4}, {5}, {6}, {4}, {16}, {16}, {32}, {128}, {258}
};
int testfn ()
{
return table[6].field;
}
int main()
{
testfn();
}
---
As far as I understand it, the issue is that SCstatic is not set until the variable is known to be going to object file.
However it is referenced *before* this, so all code generated until SCstatic gets set assumes that the global will be SCglobal. This is why the segfault occurs.
Setting SCstatic at Symbol generation time of course fixes this, but I'm not in a position to say that is the correct thing to do here.
Comment #3 by bugzilla — 2021-12-13T04:06:33Z
I clearly took the wrong approach in solving that problem.
Comment #4 by bugzilla — 2021-12-13T04:18:42Z
(In reply to Iain Buclaw from comment #0)
> Compile with -betterC and run the resultant executable.
I think you meant compile as a C file.
Comment #5 by dlang-bot — 2021-12-13T09:14:35Z
@WalterBright created dlang/dmd pull request #13422 "fix Issue 22592 - importC: Segmentation fault indexing global array a…" fixing this issue:
- fix Issue 22592 - importC: Segmentation fault indexing global array at run-time
https://github.com/dlang/dmd/pull/13422
Comment #6 by dlang-bot — 2021-12-13T12:00:41Z
dlang/dmd pull request #13422 "fix Issue 22592 - importC: Segmentation fault indexing global array a…" was merged into stable:
- a9247881dcbcbfbd871d75ebb95bd13ef5527752 by Walter Bright:
fix Issue 22592 - importC: Segmentation fault indexing global array at run-time
https://github.com/dlang/dmd/pull/13422
Comment #7 by ibuclaw — 2021-12-13T16:35:35Z
*** Issue 22590 has been marked as a duplicate of this issue. ***