Changeset e7d6968 for src/InitTweak


Ignore:
Timestamp:
Oct 23, 2020, 9:08:09 PM (4 years ago)
Author:
Fangren Yu <f37yu@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c532847
Parents:
37b7d95 (diff), 3aec25f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc into master

Location:
src/InitTweak
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r37b7d95 re7d6968  
    153153                        } // if
    154154                        if ( Statement * ctor = ctorInit->ctor ) {
     155                                addDataSectonAttribute( objDecl );
    155156                                initStatements.push_back( ctor );
    156157                                objDecl->init = nullptr;
  • src/InitTweak/FixInit.cc

    r37b7d95 re7d6968  
    802802                                if ( Statement * ctor = ctorInit->get_ctor() ) {
    803803                                        if ( objDecl->get_storageClasses().is_static ) {
     804
     805                                                // The ojbect needs to go in the data section, regardless of dtor complexity below.
     806                                                // The attribute works, and is meant to apply, both for leaving the static local alone,
     807                                                // and for hoisting it out as a static global.
     808                                                addDataSectonAttribute( objDecl );
     809
    804810                                                // originally wanted to take advantage of gcc nested functions, but
    805811                                                // we get memory errors with this approach. To remedy this, the static
  • src/InitTweak/InitTweak.cc

    r37b7d95 re7d6968  
    11031103                return isCopyFunction( decl, "?{}" );
    11041104        }
     1105
     1106        void addDataSectonAttribute( ObjectDecl * objDecl ) {
     1107                Type *strLitT = new PointerType( Type::Qualifiers( ),
     1108                        new BasicType( Type::Qualifiers( ), BasicType::Char ) );
     1109                std::list< Expression * > attr_params;
     1110                attr_params.push_back(
     1111                        new ConstantExpr( Constant( strLitT, "\".data#\"", std::nullopt ) ) );
     1112                objDecl->attributes.push_back(new Attribute("section", attr_params));
     1113        }
     1114
    11051115}
  • src/InitTweak/InitTweak.h

    r37b7d95 re7d6968  
    108108        bool isConstExpr( Initializer * init );
    109109
     110        /// Modifies objDecl to have:
     111        ///    __attribute__((section (".data#")))
     112        /// which makes gcc put the declared variable in the data section,
     113        /// which is helpful for global constants on newer gcc versions,
     114        /// so that CFA's generated initialization won't segfault when writing it via a const cast.
     115        /// The trailing # is an injected assembly comment, to suppress the "a" in
     116        ///    .section .data,"a"
     117        ///    .section .data#,"a"
     118        /// to avoid assembler warning "ignoring changed section attributes for .data"
     119        void addDataSectonAttribute( ObjectDecl * objDecl );
     120
    110121        class InitExpander_old {
    111122        public:
Note: See TracChangeset for help on using the changeset viewer.