View Issue Details

IDProjectCategoryView StatusLast Update
0002645OpenFOAMBugpublic2017-08-03 10:48
Reportertniemi Assigned Tohenry  
Status resolvedResolutionfixed 
Product Versiondev 
Summary0002645: fileHandler option missing due to wrong static initialization order
DescriptionI was trying to test the recent fileHandler-option, but I found out that it was missing from the list of valid options. It appears that our compiler (gcc 4.8.3) seems to first process the static/global code in fileOperation.C before it goes to argList.C. What happens is that the fileHandler-option which is added by the dummy "addArgsOptions intObj" will be cleared away when the HashTable validOptions is properly initialized in the beginning of argList.C.

I further investigated and googled about this and it was mentioned here ( that at around gcc 4.7 the processing order of files has changed. In older gccs the order is reversed, so that the static code in objects which are listed last in the linking phase will be processed first. In newer gccs it is the opposite. (strange that in our 4.8.3. the order is still reversed, in gcc 4.8.4 coming with ubuntu 14.04 the order is not reversed)

I was able to get the fileHandler-option working by moving it to initValidTables in argList.C. In that location it is guaranteed that validOptions is properly initialized as it is in the same file/translation unit. Now it may be that this issue is limited to only a small subset of compilers, but I guess it would be wise not to rely that argList.C will be always processed first? (I don't know what clang/intel does)

TagsNo tags attached.



2017-08-02 09:35

manager   ~0008494

It is not clear from your description what code you want changed to what and no patch or replacement files are provided. Also I cannot reproduce the problem and hence cannot test any potential fixes so will require a patch which has been tested.


2017-08-02 09:50


patch.diff (1,377 bytes)   
diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C
index 9d5ca42..d2507c3 100644
--- a/src/OpenFOAM/global/argList/argList.C
+++ b/src/OpenFOAM/global/argList/argList.C
@@ -72,6 +72,13 @@ Foam::argList::initValidTables::initValidTables()
         "do not execute functionObjects"
+    argList::addOption
+    (
+        "fileHandler",
+        "handler",
+        "override the fileHandler"
+     );
diff --git a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
index 5d65cf2..5949754 100644
--- a/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
+++ b/src/OpenFOAM/global/fileOperations/fileOperation/fileOperation.C
@@ -43,22 +43,6 @@ namespace Foam
     defineTypeNameAndDebug(fileOperation, 0);
     defineRunTimeSelectionTable(fileOperation, word);
-    class addArgsOptions
-    {
-        public:
-        addArgsOptions()
-        {
-            argList::addOption
-            (
-                "fileHandler",
-                "handler",
-                "override the fileHandler"
-            );
-        }
-    };
-    addArgsOptions intObj;
     word fileOperation::defaultFileHandler
patch.diff (1,377 bytes)   


2017-08-02 09:52

reporter   ~0008495

I have attached the patch as git diff. Basically remove addArgsOptions dummy from fileOperation.C and put its contents to argList.C initValidTables dummy. This should work on any valid compiler as it is guaranteed that static data will be initialized on the order they appear on a single file.


2017-08-03 10:48

manager   ~0008501

Thanks Timo, this change makse sense.

Resolved in OpenFOAM-dev by commit ec585137376bb88844fcb3e8fa0c227add4d3756

Resolved in OpenFOAM-5.x by commit ef412e1b83e19b86d7c377d903945c869691b10e

Issue History

Date Modified Username Field Change
2017-08-02 09:18 tniemi New Issue
2017-08-02 09:35 henry Note Added: 0008494
2017-08-02 09:50 tniemi File Added: patch.diff
2017-08-02 09:52 tniemi Note Added: 0008495
2017-08-03 10:48 henry Assigned To => henry
2017-08-03 10:48 henry Status new => resolved
2017-08-03 10:48 henry Resolution open => fixed
2017-08-03 10:48 henry Fixed in Version => 5.x
2017-08-03 10:48 henry Note Added: 0008501