Bug 441849 - libkdexoauth2 fails to build because of newly enabled C99 standard: "duplicate symbol: atof" & similar
Summary: libkdexoauth2 fails to build because of newly enabled C99 standard: "duplicat...
Status: RESOLVED FIXED
Alias: None
Product: libkgapi
Classification: Frameworks and Libraries
Component: General (other bugs)
Version First Reported In: GIT
Platform: Ubuntu Linux
: NOR major
Target Milestone: ---
Assignee: Daniel Vrátil
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-01 07:57 UTC by Kevin Funk
Modified: 2021-09-09 21:18 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Funk 2021-09-01 07:57:26 UTC
SUMMARY


STEPS TO REPRODUCE
1. Build libkgapi as usual


OBSERVED RESULT

Receiving linker errors like this (and more):

```
ld: error: duplicate symbol: atof
>>> defined at stdlib-float.h:27 (/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:27)
>>>            src/saslplugin/CMakeFiles/kdexoauth2.dir/xoauth2plugin.c.o:(atof)
>>> defined at stdlib-float.h:27 (/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:27)
>>>            src/saslplugin/CMakeFiles/kdexoauth2.dir/xoauth2plugin_init.c.o:(.text+0xB0)

ld: error: duplicate symbol: atoi
>>> defined at stdlib.h:363 (/usr/include/stdlib.h:363)
>>>            src/saslplugin/CMakeFiles/kdexoauth2.dir/xoauth2plugin.c.o:(atoi)
>>> defined at stdlib.h:363 (/usr/include/stdlib.h:363)
>>>            src/saslplugin/CMakeFiles/kdexoauth2.dir/xoauth2plugin_init.c.o:(.text+0x0)
```


EXPECTED RESULT

Builds fine


SOFTWARE/OS VERSIONS

Linux/KDE Plasma: Ubuntu 21.04, Ubuntu clang version 12.0.0-3ubuntu1~21.04.1
KDE Frameworks Version: Git master (395837d750077d96ea48f4bb59fdf0b015301298)
Qt Version: Qt 5.15


ADDITIONAL INFORMATION

Culprit is the following commit:

```
commit d38505e653965b709f941b12a0271f93c98cc584 (HEAD)
Author: Laurent Montel <montel@kde.org>
Date:   Sat Aug 14 13:49:16 2021 +0200

    GIT_SILENT: time to increase version
```

This sets the CMake variable KDE_COMPILERSETTINGS_LEVEL to 5.85.0 and with this uses newer compiler flags. Specifically, it now uses -std=c99 instead of -std=gnu90.

C99 changes the meaning of `extern inline` (https://stackoverflow.com/questions/216510/what-does-extern-inline-do). In our case that has the effect that some headers from glibc are treated differently, i.e. functions like `atof` are actually defined and exported in the object files including the header defining `atof` and friends. More information about this issue https://gcc.gnu.org/legacy-ml/gcc/2006-11/msg00011.html).

Normally this should not be the case; I think the underlying issue is that libkgapi is using a generated config.h (./src/saslplugin/config.h) which is incompatible under C99.


Possible work-arounds right now:

* Revert d38505e653965b709f941b12a0271f93c98cc584 OR
* Apply the following patch:

```
this fixes it as well for me: ```diff --git a/src/saslplugin/config.h b/src/saslplugin/config.h
index 73550fb..005a955 100644
--- a/src/saslplugin/config.h
+++ b/src/saslplugin/config.h
@@ -482,7 +482,6 @@ struct iovec {
 
 #ifndef HAVE___ATTRIBUTE__
 /* Can't use attributes... */
-#define __attribute__(foo)
 #endif
 
 #define SASL_PATH_ENV_VAR "SASL_PATH"```
```


The proper solution would be to generate the config.h at build time (committing generated headers from configure checks is usually a bad idea to begin with).
Comment 1 Kevin Funk 2021-09-01 07:57:55 UTC
Further note: Looks like we're missing a 'saslplugin' component on Bugzilla.
Comment 2 Bug Janitor Service 2021-09-08 07:26:46 UTC
A possibly relevant merge request was started @ https://invent.kde.org/pim/libkgapi/-/merge_requests/18
Comment 3 Kevin Funk 2021-09-09 21:18:30 UTC
Git commit ad7e81221fb8203bdb1b0a9d75bf5001d755f0ca by Kevin Funk.
Committed on 08/09/2021 at 07:32.
Pushed by lbeltrame into branch 'master'.

saslplugin: Fix build under C99 on all platforms

C99 changes the meaning of `extern inline` (https://stackoverflow.com/questions/216510/what-does-extern-inline-do).
In our case that has the effect that some headers from glibc are treated
differently, i.e. functions like `atof` are actually defined and exported
in the object files including the header defining `atof` and friends.

More information about this issue:
  https://gcc.gnu.org/legacy-ml/gcc/2006-11/msg00011.html

Normally this should not be the case; the underlying issue is that libkgapi
is using a generated config.h (./src/saslplugin/config.h) which is causing
issues under C99.

Fix this by generating the config.h file using CMake.

This patch also updates the 3rdparty plugin_common.* to a more recent
version (cyrus-sasl-2.1.27 to be exact), providing also support for
"Windows 10 or greater".

M  +10   -3    src/saslplugin/CMakeLists.txt
D  +0    -573  src/saslplugin/config.h
A  +18   -0    src/saslplugin/config.h.in
M  +480  -532  src/saslplugin/plugin_common.c
M  +128  -93   src/saslplugin/plugin_common.h

https://invent.kde.org/pim/libkgapi/commit/ad7e81221fb8203bdb1b0a9d75bf5001d755f0ca