Skip to content

Conversation

@stephanlachnit
Copy link
Contributor

What is the purpose of the change

In GCC and clang the symbol visibility behavior of MSVC can be mirror using -fvisibility=hidden. This allows to more easily test that symbol visbility annotations work correctly and can potentially lead to smaller binaries. The default behavior on non-Windows platforms is not changed with this commit.

See also https://gcc.gnu.org/wiki/Visibility

Also fixes a tiny mistake where the _WIN32 macro was used to silence a MSVC warning where the _MSC_VER macro should have been used instead.

This also needs to be backported to 1.12.1, see mesonbuild/wrapdb#2270

Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

This change added tests and can be verified as follows:

  • run unit tests

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable

@github-actions github-actions bot added the C++ Pull Requests for C++ binding label Dec 17, 2025
@stephanlachnit
Copy link
Contributor Author

The only thing I still need to verify that the tests actually work when compiling under Windows with MSYS2, in these logs you can see that avro::json::typeToString as a symbol is missing. I'm unsure why since the symbol is not in any headers, but I also don't see the issue of just exporting it.

@stephanlachnit stephanlachnit force-pushed the p-fix-symbol-visibility branch from 0d9e09c to 52938d0 Compare December 17, 2025 15:16
@stephanlachnit
Copy link
Contributor Author

Ok so after some testing, exporting avro::json::typeToString is required. Now this should be good to go.

/cc @martin-g @wgtmac @WillAyd how does it work with backporting? Should I open a PR again branch-1.12?

@stephanlachnit stephanlachnit marked this pull request as ready for review December 17, 2025 15:19
@martin-g
Copy link
Member

/cc @martin-g @wgtmac @WillAyd how does it work with backporting? Should I open a PR again branch-1.12?

Someone will have to cherry-pick it. The best would be you - to make sure that it works as desired.

@stephanlachnit
Copy link
Contributor Author

Someone will have to cherry-pick it. The best would be you - to make sure that it works as desired.

Sure, I'll do it then.

Copy link
Member

@martin-g martin-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stephanlachnit stephanlachnit marked this pull request as draft December 17, 2025 21:53
@stephanlachnit
Copy link
Contributor Author

stephanlachnit commented Dec 17, 2025

Seems like there are still some issues, e.g.:

ld.lld: error: undefined symbol: __declspec(dllimport) vtable for avro::istream

avro::istream is header-only, so it should not have the AVRO_DECL attribute.

For inlines, there are warning of similar nature:

'avro::GenericDatum::type' redeclared inline; 'dllimport' attribute ignored

I'm not quite sure what the solution is here. Probably just dropping the inline attribute as it doesn't do anything anyway.

wgtmac added a commit to wgtmac/iceberg-cpp that referenced this pull request Dec 18, 2025
@wgtmac
Copy link
Member

wgtmac commented Dec 18, 2025

Created apache/iceberg-cpp#421 to verify this PR.

@HuaHuaY
Copy link

HuaHuaY commented Dec 19, 2025

It seems like I'm running into another visibility related issue.

The GenericDatum class uses std::any value_; to store some types, such as GenericRecord, and also provides a template method value, which internally calls std::any_cast to perform type conversion. My dynamic library calls value<::avro::GenericRecord>, and my dynamic library also provides an interface to receive a GenericDatum.

I write set_target_properties(xxx PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN 1) to hidden visibility information in my dynamic library. Then my dynamic library internally stores a GenericRecord's typeinfo.

However, when a program using my dynamic library constructs a GenericRecord and passes it to me, std::any_cast will fail to convert the type due to inconsistency in typeinfo, even though both my library and avro are dynamic libraries.

I have no ideas on how to solve this problem, unless I remove the hidden visibility configuration.

@stephanlachnit
Copy link
Contributor Author

It seems like I'm running into another visibility related issue.

Hm, I don't think I can help with this one.

@stephanlachnit stephanlachnit force-pushed the p-fix-symbol-visibility branch from 52938d0 to 059b3c0 Compare December 22, 2025 14:02
…latforms

In GCC and clang the symbol visibility behavior of MSVC can be mirror using `-fvisibility=hidden`.
This allows to more easily test that symbol visbility annotations work correctly and can potentially lead to smaller binaries.
The default behavior on non-Windows platforms is not changed with this commit.

See also https://gcc.gnu.org/wiki/Visibility

Also fixes a tiny mistake where the _WIN32 macro was used to silence a MSVC warning where the _MSC_VER macro should have been used instead.
@stephanlachnit stephanlachnit force-pushed the p-fix-symbol-visibility branch from 059b3c0 to 5f93cdd Compare December 22, 2025 14:08
@stephanlachnit stephanlachnit marked this pull request as ready for review December 22, 2025 14:15
@stephanlachnit
Copy link
Contributor Author

I updated this with the latest test from mesonbuild/wrapdb#2270, with this one it links on all platforms and tests run also fine.

* - AVRO_DLL_HIDDEN annotation for hiding symbols
* - AVRO_DYN_LINK needs to be defined when compiling / linking avro as dynamic library
* - AVRO_SOURCE needs to be defined when compiling avro as library
* - AVRO_DECL contains the correct symbol visibility annotation depending on the two macros above
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - AVRO_DECL contains the correct symbol visibility annotation depending on the two macros above
* - AVRO_DECL contains the correct symbol visibility annotation depending on AVRO_DYN_LINK and AVRO_SOURCE

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

Labels

C++ Pull Requests for C++ binding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants