Skip to content

Preserve hidden symbol visibility for static builds with GCC-compatible compilers - #1088

Open
realwangzhichao wants to merge 1 commit into
leethomason:masterfrom
realwangzhichao:dev
Open

Preserve hidden symbol visibility for static builds with GCC-compatible compilers#1088
realwangzhichao wants to merge 1 commit into
leethomason:masterfrom
realwangzhichao:dev

Conversation

@realwangzhichao

Copy link
Copy Markdown

Problem

In the __GNUC__ >= 4 branch, TINYXML2_LIB is unconditionally defined as
__attribute__((visibility("default"))).

This overrides the hidden-by-default visibility configured by CMake, even when
tinyxml2 is built as a static library. When the static archive is linked as a
private dependency into a shared library, tinyxml2 symbols can consequently
appear in that shared library's dynamic symbol table.

This may cause symbol interposition when multiple versions of tinyxml2 are
loaded into the same process.

Change

Mirror the existing MSVC export/import logic in the __GNUC__ branch:

  • Use visibility("default") when TINYXML2_EXPORT is defined.
  • Use visibility("default") when TINYXML2_IMPORT is defined.
  • Otherwise, leave TINYXML2_LIB undecorated so static builds preserve the
    configured hidden visibility.

Shared-library exports and imports remain unchanged.

Testing

Tested with GCC 13.3:

  • Static Release build and ctest: passed.
  • Shared Release build and ctest: passed.
  • Linked the PIC static archive into a test shared object with --whole-archive
    and verified with nm -D that no tinyxml2:: symbols were exported.
  • Verified with nm -D that the shared tinyxml2 library still exports its
    public symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant