lastpass / lastpass-cli

LastPass command line interface tool
GNU General Public License v2.0
2.85k stars 292 forks source link

GCC 10 compatibility issue #532

Open eclipseo opened 4 years ago

eclipseo commented 4 years ago

With the latest GCC 10 (in Fedora Rawhide), lastpass-cli fails to build:

[100%] Linking C executable lpass
/usr/bin/cmake -E cmake_link_script CMakeFiles/lpass.dir/link.txt --verbose=1
/usr/bin/cc -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection  -Wl,-z,relro -Wl,--as-needed  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -rdynamic CMakeFiles/lpass.dir/agent.c.o CMakeFiles/lpass.dir/blob.c.o CMakeFiles/lpass.dir/cipher.c.o CMakeFiles/lpass.dir/clipboard.c.o CMakeFiles/lpass.dir/cmd-add.c.o CMakeFiles/lpass.dir/cmd-duplicate.c.o CMakeFiles/lpass.dir/cmd-edit.c.o CMakeFiles/lpass.dir/cmd-export.c.o CMakeFiles/lpass.dir/cmd-generate.c.o CMakeFiles/lpass.dir/cmd-import.c.o CMakeFiles/lpass.dir/cmd-login.c.o CMakeFiles/lpass.dir/cmd-logout.c.o CMakeFiles/lpass.dir/cmd-ls.c.o CMakeFiles/lpass.dir/cmd-mv.c.o CMakeFiles/lpass.dir/cmd-passwd.c.o CMakeFiles/lpass.dir/cmd-rm.c.o CMakeFiles/lpass.dir/cmd-share.c.o CMakeFiles/lpass.dir/cmd-show.c.o CMakeFiles/lpass.dir/cmd-status.c.o CMakeFiles/lpass.dir/cmd-sync.c.o CMakeFiles/lpass.dir/cmd.c.o CMakeFiles/lpass.dir/config.c.o CMakeFiles/lpass.dir/edit.c.o CMakeFiles/lpass.dir/endpoints-login.c.o CMakeFiles/lpass.dir/endpoints-share.c.o CMakeFiles/lpass.dir/endpoints.c.o CMakeFiles/lpass.dir/format.c.o CMakeFiles/lpass.dir/http.c.o CMakeFiles/lpass.dir/json-format.c.o CMakeFiles/lpass.dir/kdf.c.o CMakeFiles/lpass.dir/log.c.o CMakeFiles/lpass.dir/lpass.c.o CMakeFiles/lpass.dir/notes.c.o CMakeFiles/lpass.dir/password.c.o CMakeFiles/lpass.dir/pbkdf2.c.o CMakeFiles/lpass.dir/process.c.o CMakeFiles/lpass.dir/session.c.o CMakeFiles/lpass.dir/terminal.c.o CMakeFiles/lpass.dir/upload-queue.c.o CMakeFiles/lpass.dir/util.c.o CMakeFiles/lpass.dir/xml.c.o  -o lpass  -lxml2 -lssl -lcrypto -lcurl 
make[2]: Leaving directory '/builddir/build/BUILD/lastpass-cli-1.3.3'
/usr/bin/ld: CMakeFiles/lpass.dir/cmd-login.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/cmd-login.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/cmd-share.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/cmd-share.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/cmd.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/cmd.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/lpass.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/lpass.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/process.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/process.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/upload-queue.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/upload-queue.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/util.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: multiple definition of `ARGV'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:8: first defined here
/usr/bin/ld: CMakeFiles/lpass.dir/util.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: multiple definition of `ARGC'; CMakeFiles/lpass.dir/agent.c.o:/builddir/build/BUILD/lastpass-cli-1.3.3/process.h:7: first defined here
collect2: error: ld returned 1 exit status

This is related to this change in GCC 10:

GCC now defaults to -fno-common. As a result, global variable accesses are more efficient on various targets. In C, global variables with multiple tentative definitions now result in linker errors. With -fcommon such definitions are silently merged during linking.

https://gcc.gnu.org/gcc-10/changes.html

Default to -fno-common

A common mistake in C is omitting extern when declaring a global variable in a header file. If the header is included by several files it results in multiple definitions of the same variable. In previous GCC versions this error is ignored. GCC 10 defaults to -fno-common, which means a linker error will now be reported. To fix this, use extern in header files when declaring global variables, and ensure each global is defined in exactly one C file. As a workaround, legacy C code can be compiled with -fcommon.

  int x;  // tentative definition - avoid in header files

  extern int y;  // correct declaration in a header file

https://gcc.gnu.org/gcc-10/porting_to.html

perlun commented 2 years ago

For the reference, this is still an issue. Seen on Debian bookworm, which uses GCC 11.3 by default (doesn't even provide anything older than GCC 10).

@GPaulovics or others, is there a plan for fixing this? :thinking: I note that the project doesn't seem to have anything merged for the last three years...

antoineco commented 1 year ago

Thanks for the pointer about the new default. This change allowed me to build with GCC 12:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e30d9fd..9493147 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_compile_options(-fcommon)
+
 IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.1)
   set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake > 2.8.4 is required
   cmake_minimum_required(VERSION 2.8)

edit: better use the patch from #535 actually.