RFR: 8311661: Resolve duplicate symbol of StringTable::StringTable with JDK static linking [v2]

Ioi Lam iklam at openjdk.org
Tue Jul 11 16:23:22 UTC 2023


On Tue, 11 Jul 2023 15:44:30 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> Hi,
> 
> to prevent clashes like this, libraries that support static linking tend to define a global namespace or a common prefix, usually switchable via defines. IIRC sqlite does this, zlib, jemalloc... If we could pull such a thing off with a minimum of invasiveness, it would be a much more robust solution.

Do the libraries that you mention just enclose every .cpp and .hpp files with `namespace xxx {` and `}`. Something like


// thread.hpp
#include <....>
#include <....>
#include <....>

namespace hotspot {   // <<< add
class Thread {....}
} // <<< add


That doesn't look too bad to me, as we just need to do this once, and it can (probably) be done with a script.

> 
> If we introduce such a namespace, the name could be very short and non-descriptive, and then be defined (or completely switched off by default) via compile option. That way one could even link two hotspots if one wanted (only one usuable at a time for other reasons).
> 
> If combined with "using" somewhere, maybe in precompiled.hpp, this solution may not be that invasive.

Are you suggesting something like this?


// precompiled.hpp
namespace hotspot {}
using Bar = hotspot::Bar;    

// bar.h, the "Bar" class is automatically put inside "hotspot" namespace.
class Bar {
  static int a() { return 0; }
};


I tried it but couldn't get it to work. The `using` must be put after the type of `hotspot::Bar` has already been declared.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/14808#issuecomment-1631120256


More information about the graal-dev mailing list