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

Jiangli Zhou jiangli at openjdk.org
Mon Jul 10 23:28:12 UTC 2023


On Mon, 10 Jul 2023 22:49:02 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> I'm not suggesting that the application code should be changed. I'm suggesting that a broader solution should be found that avoids this issue in the future, rather than having to patch hotspot again for the next application that comes along and defines a symbol that conflicts. That's what I mean by "principled". I.e. we should be able to explain how to avoid symbol conflicts when statically linking applications against hotspot. 

Thanks for the clarification, @JornVernee.

> I don't think that telling users that, if they have a symbol conflict: "just file a bug report and we will patch hotspot to use a different symbol" is good enough.

Agreed. 

> 
> For instance, we could put all of hotspot into a `HotSpot` namespace, and then document this name space name and require that applications that want to statically link against hotspot don't use the `HotSpot` name space. That would also avoid having to fix up uses of these symbols inside hotspot itself, since things in the same namespace can refer to each other already, without needing a qualifier.

I think using a hotspot special namespace can be a good general solution for resolving and avoiding any potential duplication symbol issue like this. The good news is that with our prototype and testing on JDK 11, we didn't find many duplicate symbol issues with hotspot code specifically. So far we only observed issues with:

- `StringTable::StringTable`
- `Thread`
- `ProfileData`

> Thanks for the pointers. So it sounds like limiting the symbols 'exported' by a static library is not really possible.

Right. We've looked into following solutions for linkage failures due to symbol conflicts and each solution may be used in different cases when applicable:

- Changing to static function/variable, so the symbol has internal linkage (as suggested by @AlanBateman in earlier code review for symbol issues in JDK library code)
- Use namespace
- Symbol (function, variable) renaming

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

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


More information about the hotspot-dev mailing list