Ignore:
Timestamp:
Oct 7, 2020, 9:33:22 PM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8e4bc30
Parents:
69c5c00
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r69c5c00 r6fbe9a5  
    112112                        } // if
    113113                        if ( Statement * ctor = ctorInit->ctor ) {
     114                                // Translation 1: Add this attribute on the global declaration:
     115                                //    __attribute__((section (".data#")))
     116                                // which makes gcc put the global in the data section,
     117                                // so that the global is writeable (via a const cast) in the init function.
     118                                // The trailing # is an injected assembly comment, to suppress the "a" in
     119                                //    .section .data,"a"
     120                                //    .section .data#,"a"
     121                                // to avoid assembler warning "ignoring changed section attributes for .data"
     122                                Type *strLitT = new PointerType( Type::Qualifiers( ),
     123                                        new BasicType( Type::Qualifiers( ), BasicType::Char ) );
     124                                std::list< Expression * > attr_params;
     125                                attr_params.push_back(
     126                                        new ConstantExpr( Constant( strLitT, "\".data#\"", std::nullopt ) ) );
     127                                objDecl->attributes.push_back(new Attribute("section", attr_params));
     128                                // Translation 2: Move the initizliation off the global declaration,
     129                                // into the startup function.
    114130                                initStatements.push_back( ctor );
    115131                                objDecl->init = nullptr;
Note: See TracChangeset for help on using the changeset viewer.