Skip to content

Merging issue with global variables between compiled and interpreted code #15938

Open
@hahnjo

Description

@hahnjo

Check duplicate issues.

  • Checked for duplicates

Description

As reported on the forum, ROOT seems to have merging issues with global variables between compiled and interpreted code since v6.28 coinciding with the upgrade to LLVM 13.

Reproducer

// calo.h
#ifndef __CALO__
#define __CALO__

namespace calo {
    int nUnits = 0;
    void setnUnits (int n) {
	nUnits = n;
    }
}

#endif

// insert.h
#ifndef _cali_
#define _cali_

void insert();
#endif

// insert.C
#include <iostream>
#include "calo.h"
#include "insert.h"

using namespace std;

void insert() {
    cout << "DEBUG\t" << calo::nUnits << endl;
}
 $ g++ -std=c++11  -fPIC --shared -o libinsert.so insert.C

On the prompt:

gSystem->Load("libinsert.so")
#include "calo.h"
#include "insert.h"
insert()
calo::setnUnits(3)
insert()

The last call should print 3, but shows 0.

ROOT version

master, reproduced with 6.28/00

Installation method

from source

Operating system

Linux (but likely general problem)

Additional context

From Wile in the forum:

I assume that if a “global variable” is defined in a “named namespace” then its value should be “shared”. But, if it is defined in an “unnamed namespace”, then it should be “local” (“static”) to every unit that includes the file with its definition. Maybe one should check what the current C++ standard says about it.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions