# Crash in cling caused by header parsing in library load?

**URL:** <https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652>\
**Category:** ROOT\
**Tags:** cling\
**Created:** [April 1, 2020, 2:47pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652 "2020-04-01T14:47:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![valerio.formato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/valerio.formato/32/12474_2.png) [@valerio.formato](https://root-forum.cern.ch/u/valerio.formato)\
**Post date:** [April 1, 2020, 2:47pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/1 "2020-04-01T14:47:57Z")

</div>

Dear ROOTers,  
I’m facing a very strange issue: I was testing ROOT version 6.20/00 (I am interested in the performances of the new compression introduced there) and I came stumbling on a very strange crash.

Essentially my executable is linked against the experiment software library and creates an object of type `AMSChain` (inherited from `TChain`). As soon as this happens the executable crashes

```auto
In file included from rootdict_s dictionary payload:118:
/storage/gpfs_ams/ams/users/vformato/AMS/include/../include/EcalKRec.h:39:2: error: redefinition of enumerator 'kElectron'
        kElectron,
        ^
/storage/gpfs_ams/ams/users/vformato/devel/root-6.20.00.install/include/TPDGCode.h:25:31: note: previous definition is here
   kSu1Bar=-3203,kSearches0=7,kElectron=11,kPositron=-11,kNuE=12,
                              ^
In file included from rootdict_s dictionary payload:118:
/storage/gpfs_ams/ams/users/vformato/AMS/include/../include/EcalKRec.h:40:2: error: redefinition of enumerator 'kProton'
        kProton,
        ^
/storage/gpfs_ams/ams/users/vformato/devel/root-6.20.00.install/include/TPDGCode.h:31:21: note: previous definition is here
   kA2_1320Plus=215,kProton=2212,kProtonBar=-2212,
                    ^
Error in <TInterpreter::AutoParse>: Error parsing payload code for class AMSChain with content:

```

So it looks like the interpreter is lazy-loading the class dictionary on the spot, parsing all the headers and then (rightfully?) complaining about a redefinition of an existing enum.

I can reproduce the same exact crash just by firing up the interpreter, loading the experiment library via `gSystem->Load(...)` and creating a default-constructed `AMSChain` object

```auto
root [0] gSystem->Load("lib/linuxx8664gcc6.20/libntuple_slc6_PG_dynamic.so");
root [1] AMSChain ch
// same exact crash happens

```

My questions to you are

1. Why doesn’t this happen with ROOT 6.18/04? What changed in regard to dictionary header parsing?
2. Assuming that the ROOT 6.18/04 shows the correct/intended behavior, what’s a possible fix for this issue? (meaning: is it really necessary to parse and interpret everything in a fully fledged compiled executable / library? I really would like this to behave as in all previous ROOT versions)

Cheers,  
Valerio

* * *

_ROOT Version:_ 6.20/00  
_Platform:_ CentOS 7  
_Compiler:_ gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

* * *

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [April 1, 2020, 4:18pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/2 "2020-04-01T16:18:43Z")

</div>

Hi Valerio,

I hand this over to @Axel.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [April 1, 2020, 7:27pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/3 "2020-04-01T19:27:08Z")

</div>

> [@valerio.formato](#):
>
> root-6.20.00.install/include/TPDGCode.h:25:31: note: previous definition is here

It appears that the ROOT header TPDGCode.h is now also parsed during your dictionary generation and it unfortunately has a conflict with your code ☹ …  
One workaround to update `EcalKRec.h` to make the enum an ‘enum class’ (This will require change in the rest of your code ☹ ).

---

<div class="post-metadata">

**Author:** ![valerio.formato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/valerio.formato/32/12474_2.png) [@valerio.formato](https://root-forum.cern.ch/u/valerio.formato)\
**Post date:** [April 1, 2020, 9:43pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/4 "2020-04-01T21:43:15Z")

</div>

Unfortunately I’m not sure it’s a viable solution, that codebase is required to be backwards compatible to ROOT 5 and c++03 😕  
And by the looks of it the change you suggest requires to touch the code in a lot of places, handling ROOT6 vs ROOT5 code with `ifdef`s so on a first look it’s a no-go.

I’ll downgrade to 6.18/04 for the time being until I can understand better where the `TPDGCode` header is included (a small reproducer I’m attaching shows this crash when I try to load from the interpreter, but the executable runs just fine [root6.20\_crash\_reproducer.tar.gz](https://root-forum.cern.ch/uploads/short-url/eKpAq7zlkAkW2pxvDieHn2sh3GK.gz) (2.0 KB))

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 1, 2020, 10:00pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/5 "2020-04-01T22:00:53Z")

</div>

It seems to me that the offending line in ROOT 6.20 is in the “`${ROOTSYS}/include/module.modulemap`” file:

```cpp
module "EG" {
  // ...
  module "TPDGCode.h" { header "TPDGCode.h" export * }
  // ...
  link "libEG.so"
  export *
}

```

Maybe, you do not need to link against “libEG”.

ROOT 6.18 used PCH (instead of the new “C++ modules”) and there was the “`${ROOTSYS}/lib/libEG.rootmap`” file (instead of the new “`${ROOTSYS}/lib/EG.pcm`” file).

---

<div class="post-metadata">

**Author:** ![valerio.formato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/valerio.formato/32/12474_2.png) [@valerio.formato](https://root-forum.cern.ch/u/valerio.formato)\
**Post date:** [April 1, 2020, 10:23pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/6 "2020-04-01T22:23:45Z")

</div>

That’s a nice clue, is it possible it was different in 6.18/04?

And yes, unfortunately the experiment library links `libEG` so it carries it over. I’ll take a look at why `libEg` is used, though

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [April 1, 2020, 11:56pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/7 "2020-04-01T23:56:51Z")

</div>

> [@valerio.formato](#):
>
> Unfortunately I’m not sure it’s a viable solution, that codebase is required to be backwards compatible to ROOT 5 and c++03

Then the simplest adaptation is the following:

```auto
// File EcalKRec.h
enum Something {
    ..., kAMSElectron,
    ...
    kAMSProton,
};

```

or the slightly more risky

```auto
// File EcalKRec.h
enum Something {
    ..., 
#ifndef __CLING__
    kElectron,
#endif
    ...
#ifndef __CLING__
    kProton,
#endif
};

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 2, 2020, 7:11am UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/8 "2020-04-02T07:11:34Z")

</div>

@Axel Adding to @pcanal notes … the proper adaptation is the following:

```cpp
// File TPDGCode.h
#ifndef ROOT_TPDGCode
#define ROOT_TPDGCode
namespace ROOT {
  // ...
  typedef enum {/* ... */
    kElectron=11
    /* ... */}
  PDG_t;
  // ...
} // namespace ROOT
#endif //ROOT_TPDGCode

```

The only other file which would need to be “adapted” is: [montecarlo/pythia6/src/TPythia6Decayer.cxx](https://github.com/root-project/root/blob/master/montecarlo/pythia6/src/TPythia6Decayer.cxx)

---

<div class="post-metadata">

**Author:** ![valerio.formato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/valerio.formato/32/12474_2.png) [@valerio.formato](https://root-forum.cern.ch/u/valerio.formato)\
**Post date:** [April 2, 2020, 2:34pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/9 "2020-04-02T14:34:17Z")

</div>

Enclosing the ROOT enum in the main namespace would be an excellent solution but for now I’ll try to see if we can manage to fix this upstream in the experiment SW.

Thanks for the pointers!

Worst case scenario I just have to wait for 6.20/06 😃

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 16, 2020, 2:34pm UTC](https://root-forum.cern.ch/t/crash-in-cling-caused-by-header-parsing-in-library-load/38652/10 "2020-04-16T14:34:19Z")

</div>

Closed on April 16, 2020, 2:34pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
