From d8d3a84b2ddfc29670430fc73ff8483a44b8f61e Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Tue, 14 Feb 2023 11:10:56 +0100 Subject: [PATCH] bindings: cxx: drop the re-export guard of visible symbols The ifdef guard that changes the definition of GPIOD_CXX_API between "default" and "hidden" is there to prevent libraries that would include gpiod.hpp from re-exporting libgpiodcxx symbols. Unfortunately the hidden linkage only works for translation units within the same ELF object. At static linking time we must always mark the throwable types as visible or we'll get the following errors: /usr/bin/ld: tests-chip.o:(.data+0x0): undefined reference to `typeinfo for gpiod::chip_closed' /usr/bin/ld: tests-line-request.o:(.data+0x0): undefined reference to `typeinfo for gpiod::request_released' /usr/bin/ld: .libs/gpiod-cxx-test: hidden symbol `_ZTIN5gpiod11chip_closedE' isn't defined /usr/bin/ld: final link failed: bad value On top of that we actually WANT to re-export typeinfo for throwable types as they can be propagated to external callers when an exception is thrown. The above error can only be triggered on clang. GCC seems to be incorrectly omitting the "hidden" attribute in this case. Signed-off-by: Bartosz Golaszewski --- bindings/cxx/Makefile.am | 1 - bindings/cxx/gpiod.hpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/bindings/cxx/Makefile.am b/bindings/cxx/Makefile.am index f2fc884..1eafaa2 100644 --- a/bindings/cxx/Makefile.am +++ b/bindings/cxx/Makefile.am @@ -23,7 +23,6 @@ libgpiodcxx_la_SOURCES = \ libgpiodcxx_la_CXXFLAGS = -Wall -Wextra -g -std=gnu++17 libgpiodcxx_la_CXXFLAGS += -fvisibility=hidden -I$(top_srcdir)/include/ libgpiodcxx_la_CXXFLAGS += $(PROFILING_CFLAGS) -libgpiodcxx_la_CXXFLAGS += -DGPIOD_CXX_BUILD libgpiodcxx_la_LDFLAGS = -version-info $(subst .,:,$(ABI_CXX_VERSION)) libgpiodcxx_la_LDFLAGS += -lgpiod -L$(top_builddir)/lib libgpiodcxx_la_LDFLAGS += $(PROFILING_LDFLAGS) diff --git a/bindings/cxx/gpiod.hpp b/bindings/cxx/gpiod.hpp index 8981db4..470148f 100644 --- a/bindings/cxx/gpiod.hpp +++ b/bindings/cxx/gpiod.hpp @@ -23,11 +23,7 @@ * the declarations in exception.hpp in order to expose the symbols of classes * inheriting from standard exceptions. */ -#ifdef GPIOD_CXX_BUILD #define GPIOD_CXX_API __attribute__((visibility("default"))) -#else -#define GPIOD_CXX_API __attribute__((visibility("hidden"))) -#endif #define __LIBGPIOD_GPIOD_CXX_INSIDE__ #include "gpiodcxx/chip.hpp" -- 2.30.2