bindings: cxx: drop the re-export guard of visible symbols
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 14 Feb 2023 10:10:56 +0000 (11:10 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 14 Feb 2023 14:56:13 +0000 (15:56 +0100)
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 <bartosz.golaszewski@linaro.org>
bindings/cxx/Makefile.am
bindings/cxx/gpiod.hpp

index f2fc884880a5210bc3a8b5c976f17db0083ed529..1eafaa2ce6376a8a08ac800c3ed7fdce72b6e288 100644 (file)
@@ -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)
index 8981db4102ee206e8b08c850f549d7c3016c8019..470148f9342c09f36621811879a96dc54505e866 100644 (file)
  * 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"