Opened 4 years ago

Closed 4 years ago

#182 closed defect (fixed)

Static Const Global variable segfault in generated code

Reported by: Thierry Delisle Owned by: Michael Brooks <mlbrooks@…>
Priority: major Component: cfa-cc
Version: 1.0 Keywords: global
Cc:

Description

The following code segfaults when run:

static const char foo = -1;

int main() {}

Change History (2)

comment:1 Changed 4 years ago by mlbrooks

A tough experience reproducing has these lessons.

The "static" on the constant is required (regardless of gcc versions, as discussed below).

The problem seems to happen with gcc-8 and not with gcc-6.

Specifically these configurations on plg2 show the difference.

Gets the segfault:

$ make status
translator
        --with-target-hosts=host:debug
        CXXFLAGS=-Og
        -g
        CXX=g++-8
        CC=gcc-8

libcfa/x64-debug
        CXXFLAGS=-Og
        -g
        CXX=g++-8
        CC=gcc-8
        DRIVER_DIR=/u0/mlbrooks/cfa-prime/build-gcc8/driver/
        ARCHITECTURE=x64
        CONFIGURATION=debug
        CFA_VERSION=1:0:0

Does not get the segfault:

$ make status
translator
        --with-target-hosts=host:debug
        CXXFLAGS=-Og
        -g
        CXX=g++-8

libcfa/x64-debug
        CXXFLAGS=-Og
        -g
        CXX=g++-8
        DRIVER_DIR=/u0/mlbrooks/cfa-prime/build/driver/
        ARCHITECTURE=x64
        CONFIGURATION=debug
        CFA_VERSION=1:0:0
$ gcc --version
gcc (Ubuntu 6.5.0-2ubuntu1~16.04) 6.5.0 20181026
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

comment:2 Changed 4 years ago by Michael Brooks <mlbrooks@…>

Owner: set to Michael Brooks <mlbrooks@…>
Resolution: fixed
Status: newclosed

In 6fbe9a5:

Fixing code-gen of constants. Fixes #182? Removes workaround 58b6d1.

Forcing recent GCC versions to place CFA-initialized constants in writeable memory, so CFA initialization doesn't segfault when writing them. See the const-init test for specifics about recent GCC versions.

src/InitTweak/FixGlobalInit.cc: generating the attribute to control GCC's placement
libcfa/src/limits.* : removing workaround from 58b6d1, making these limits const again
tests//limits.* : commenting old test that uses the constants from licfa-limits, explaining what the test doesn't exercise
tests/
/const-init.* : new test of static constants, taken from #182, and comments explaining how to test this issue

Note: See TracTickets for help on using tickets.