Ignore:
Timestamp:
Jul 30, 2018, 4:43:47 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
f072892
Parents:
c198b69
git-author:
Rob Schluntz <rschlunt@…> (07/26/18 13:54:40)
git-committer:
Rob Schluntz <rschlunt@…> (07/30/18 16:43:47)
Message:

Remove filename from global init/destroy functions, use fixed constructor/destructor priority of 200 for CFA library globals

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    rc198b69 r1be845b  
    3737        class GlobalFixer : public WithShortCircuiting {
    3838          public:
    39                 GlobalFixer( const std::string & name, bool inLibrary );
     39                GlobalFixer( bool inLibrary );
    4040
    4141                void previsit( ObjectDecl *objDecl );
     
    5252        };
    5353
    54         void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) {
    55                 PassVisitor<GlobalFixer> visitor( name, inLibrary );
     54        void fixGlobalInit( std::list< Declaration * > & translationUnit, bool inLibrary ) {
     55                PassVisitor<GlobalFixer> visitor( inLibrary );
    5656                acceptAll( translationUnit, visitor );
    5757                GlobalFixer & fixer = visitor.pass;
     
    7070        }
    7171
    72   std::string globalFunctionName( const std::string & name ) {
    73         // get basename
    74         std::string ret = name.substr( 0, name.find( '.' ) );
    75         // replace invalid characters with _
    76                 static std::string invalid = "/-@";
    77         replace_if( ret.begin(), ret.end(), []( char c ) { return invalid.find(c) != std::string::npos; }, '_' );
    78         return ret;
    79   }
    80 
    81         GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) {
    82                 std::string fixedName = globalFunctionName( name );
     72        GlobalFixer::GlobalFixer( bool inLibrary ) : tempNamer( "_global_init" ) {
    8373                std::list< Expression * > ctorParameters;
    8474                std::list< Expression * > dtorParameters;
     
    9080                        // for library code are run before constructors and destructors for user code,
    9181                        // specify a priority when building the library. Priorities 0-100 are reserved by gcc.
    92                         ctorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
    93                         dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
     82                        // Priorities 101-200 are reserved by cfa, so use priority 200 for CFA library globals,
     83                        // allowing room for overriding with a higher priority.
     84                        ctorParameters.push_back( new ConstantExpr( Constant::from_int( 200 ) ) );
     85                        dtorParameters.push_back( new ConstantExpr( Constant::from_int( 200 ) ) );
    9486                }
    95                 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     87                initFunction = new FunctionDecl( "__global_init__", Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
    9688                initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) );
    97                 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     89                destroyFunction = new FunctionDecl( "__global_destroy__", Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
    9890                destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) );
    9991        }
Note: See TracChangeset for help on using the changeset viewer.