Bug 401018

Summary: Visibility problems with Apple's Xcode/clang compilers
Product: [Frameworks and Libraries] extra-cmake-modules Reporter: RJVB <rjvbertin>
Component: generalAssignee: ecm-bugs-null <ecm-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: kdelibs-bugs
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Compiled Sources   
OS: macOS   
URL: https://phabricator.kde.org/D16894
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: libkcddb 18.08.3 build log with AppleClang 602
build log with clang 5.0.2 from MacPorts
AppleClang build commands for configpage.cpp, sites.cpp and the failed link command formatted for side-by-side comparison
clang build commands for configpage.cpp, sites.cpp and the failed link command formatted for side-by-side comparison
sites.cpp preprocessed by AppleClang
sites.cpp preprocessed by clang 5.0.2

Description RJVB 2018-11-13 22:52:01 UTC
There appears to be something different with Apple's clang compilers from Xcode (AppleClang) which can cause problems when building with hidden symbol visibility. Link failures will arise in certain projects because symbols (from libraries built by the same project) that should be visible but are not. Sometimes the issue occurs only on newer OS versions (I can build kde4-workspace with AppleClang on OS X 10.9 but the build fails with missing symbols on 10.13 and up).

An example where this started happening recently: libkcddb . This fails to link with AppleClang, not just on my ageing 10.9.5 system but also on an up-to-date 10.13 system. I'll be attaching full build logs, but here's the link error:

/usr/bin/clang++  -std=c++0x -fno-operator-names -fno-exceptions -DQT_NO_EXCEPTIONS -Wno-gnu-zero-variadic-macro-arguments -Wall -Wextra -Wcast-align -Wchar-subscripts -Wformat-security -Wno-long-long -Wpointer-arith -Wundef -Wnon-virtual-dtor -Woverloaded-virtual -Werror=return-type -Wvla -pedantic -Wzero-as-null-pointer-constant -bundle -Wl,-headerpad_max_install_names -multiply_defined suppress  -o kcm_cddb.so CMakeFiles/kcm_cddb.dir/cddbconfigwidget.cpp.o CMakeFiles/kcm_cddb.dir/kcmcddb.cpp.o CMakeFiles/kcm_cddb.dir/kcm_cddb_autogen/mocs_compilation.cpp.o /opt/local/lib/libKF5KIOWidgets.5.47.0.dylib ../libkcddb/libKF5Cddb.5.0.0.dylib /opt/local/lib/libKF5ConfigWidgets.5.47.0.dylib /opt/local/lib/libKF5JobWidgets.5.47.0.dylib /opt/local/lib/libKF5Completion.5.47.0.dylib /opt/local/lib/libKF5WidgetsAddons.5.47.0.dylib /opt/local/lib/libKF5KIOCore.5.47.0.dylib /opt/local/lib/libKF5Auth.5.47.0.dylib /opt/local/libexec/qt5/Library/Frameworks/QtWidgets.framework/QtWidgets /opt/local/lib/libKF5Service.5.47.0.dylib /opt/local/lib/libKF5I18n.5.47.0.dylib /opt/local/lib/libKF5CoreAddons.5.47.0.dylib /opt/local/libexec/qt5/Library/Frameworks/QtConcurrent.framework/QtConcurrent /opt/local/libexec/qt5/Library/Frameworks/QtDBus.framework/QtDBus /opt/local/lib/libKF5Codecs.5.47.0.dylib /opt/local/lib/libKF5ConfigGui.5.47.0.dylib /opt/local/libexec/qt5/Library/Frameworks/QtGui.framework/QtGui /opt/local/libexec/qt5/Library/Frameworks/QtXml.framework/QtXml /opt/local/lib/libKF5ConfigCore.5.47.0.dylib /opt/local/libexec/qt5/Library/Frameworks/QtNetwork.framework/QtNetwork /opt/local/libexec/qt5/Library/Frameworks/QtCore.framework/QtCore 
Undefined symbols for architecture x86_64:
  "ConfigBase::setFreedbSubmitTransport(int)", referenced from:
      CDDBModule::checkSettings() const in kcmcddb.cpp.o
  "ConfigBase::~ConfigBase()", referenced from:
      KCDDB::Config::~Config() in kcmcddb.cpp.o
  "KCDDB::Sites::siteList()", referenced from:
      CDDBConfigWidget::showMirrorList() in cddbconfigwidget.cpp.o
  "KCDDB::Sites::Sites()", referenced from:
      CDDBConfigWidget::showMirrorList() in cddbconfigwidget.cpp.o
  "KCDDB::Config::Config()", referenced from:
      CDDBModule::CDDBModule(QWidget*, QList<QVariant> const&) in kcmcddb.cpp.o
      CDDBModule::defaults() in kcmcddb.cpp.o
      CDDBModule::checkSettings() const in kcmcddb.cpp.o
      CDDBModule::load() in kcmcddb.cpp.o
  "ConfigBase::emailAddress() const", referenced from:
      CDDBModule::checkSettings() const in kcmcddb.cpp.o
  "ConfigBase::smtpHostname() const", referenced from:
      CDDBModule::checkSettings() const in kcmcddb.cpp.o
  "ConfigBase::smtpUsername() const", referenced from:
      CDDBModule::updateWidgetsFromConfig(KCDDB::Config const&) in kcmcddb.cpp.o
  "ConfigBase::freedbSubmitTransport() const", referenced from:
      CDDBModule::checkSettings() const in kcmcddb.cpp.o
  "ConfigBase::replyTo() const", referenced from:
      CDDBModule::checkSettings() const in kcmcddb.cpp.o
ld: symbol(s) not found for architecture x86_64

This error goes away when using a stock clang compiler, for instance clang-4.0 or clang-5.0 from MacPorts.

The symbols in question are defined in sites.cpp and in the autogenerated configbase.cpp (auto-generated files are identical for the different compilers I tested).

Looking at the build logs there are no differences in the compiler arguments between the various builds, other than in the build directory path. Yet the Sites::siteList() symbol is visible in the build by stock clang (5.0.2) and not in the one by AppleClang:

000000000001bdc0 T __ZN5KCDDB5Sites8siteListEv
vs.
000000000001bc80 t __ZN5KCDDB5Sites8siteListEv

I have only seen this with KDE code for now, never elsewhere.
Comment 1 RJVB 2018-11-13 22:54:38 UTC
Created attachment 116293 [details]
libkcddb 18.08.3 build log with AppleClang 602
Comment 2 RJVB 2018-11-13 22:55:50 UTC
Created attachment 116294 [details]
build log with clang 5.0.2 from MacPorts
Comment 3 RJVB 2018-11-13 22:57:36 UTC
Created attachment 116295 [details]
AppleClang build commands for configpage.cpp, sites.cpp and the failed link command formatted for side-by-side comparison
Comment 4 RJVB 2018-11-13 22:58:11 UTC
Created attachment 116296 [details]
clang build commands for configpage.cpp, sites.cpp and the failed link command formatted for side-by-side comparison
Comment 5 RJVB 2018-11-13 23:15:38 UTC
Created attachment 116297 [details]
sites.cpp preprocessed by AppleClang
Comment 6 RJVB 2018-11-13 23:16:50 UTC
Created attachment 116298 [details]
sites.cpp preprocessed by clang 5.0.2
Comment 7 RJVB 2018-11-14 19:06:34 UTC
Moving this to KConfig because it looks like kconfig_compiler_kf5 fails with AppleClang, generating empty export macros:

```
> diff -u libkcddb-18.08.3/build-*clang/libkcddb/kcddb_export.h
--- libkcddb-18.08.3/build-appleclang/libkcddb/kcddb_export.h   2018-11-14 00:04:58.000000000 +0100
+++ libkcddb-18.08.3/build-clang/libkcddb/kcddb_export.h        2018-11-13 23:18:12.000000000 +0100
@@ -9,15 +9,15 @@
 #  ifndef KCDDB_EXPORT
 #    ifdef KF5Cddb_EXPORTS
         /* We are building this library */
-#      define KCDDB_EXPORT 
+#      define KCDDB_EXPORT __attribute__((visibility("default")))
 #    else
         /* We are using this library */
-#      define KCDDB_EXPORT 
+#      define KCDDB_EXPORT __attribute__((visibility("default")))
 #    endif
 #  endif
 
 #  ifndef KCDDB_NO_EXPORT
-#    define KCDDB_NO_EXPORT 
+#    define KCDDB_NO_EXPORT __attribute__((visibility("hidden")))
 #  endif
 #endif
```

Why this happens only for certain projects is a mystery to me (as is the way this command can know what compiler syntax to generate).
Comment 8 RJVB 2018-11-15 12:08:22 UTC
Apologies, my initial hunch was right, this is an ECM issue.
See https://phabricator.kde.org/D16894
Comment 9 Justin Zobel 2022-12-03 09:01:32 UTC
Thank you for reporting this issue in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you!
Comment 10 Bug Janitor Service 2022-12-18 05:15:09 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 11 Bug Janitor Service 2023-01-02 05:29:13 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!