0002-Fix-getopt-linking-error-with-musl-libc.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. From db7fab775d03438b4cfce6b49fab2d3176ecb1d3 Mon Sep 17 00:00:00 2001
  2. From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
  3. Date: Sat, 11 May 2024 19:38:01 +0200
  4. Subject: [PATCH] Fix getopt linking error with musl-libc
  5. The buildroot project, to which the sscep application was added, has
  6. configurations that raise the following linking error:
  7. buildroot/output/host/opt/ext-toolchain/bin/../lib/gcc/i586-buildroot-linux-musl/9.3.0/../../../../i586-buildroot-linux-musl/bin/ld: buildroot/output/host/i586-buildroot-linux-musl/sysroot/lib/libc.a(getopt.o): in function `getopt':
  8. getopt.c:(.text.getopt+0x0): multiple definition of `getopt'; src/getopt.o:getopt.c:(.text+0x0): first defined here
  9. buildroot/output/host/opt/ext-toolchain/bin/../lib/gcc/i586-buildroot-linux-musl/9.3.0/../../../../i586-buildroot-linux-musl/bin/ld: buildroot/output/host/i586-buildroot-linux-musl/sysroot/lib/libc.a(getopt.o):(.data.optind+0x0): multiple definition of `optind'; src/getopt.o:(.data+0x0): first defined here
  10. collect2: error: ld returned 1 exit status
  11. The commit 65561b53344b8 ("Fix getopt linking error") actually fixed the
  12. linking error only for uclibc, but not for musl-libc. The patch fixes
  13. the error for both uclibc and musl-libc.
  14. Link: http://autobuild.buildroot.net/results/d5b1b4e5e9d9c8eca5e75c345db4d1f3f0cd84ed/build-end.log
  15. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
  16. Upstream: https://github.com/certnanny/sscep/pull/181
  17. ---
  18. configure.ac | 2 +-
  19. src/getopt.c | 12 ++----------
  20. 2 files changed, 3 insertions(+), 11 deletions(-)
  21. diff --git a/configure.ac b/configure.ac
  22. index 9f3ee15686a2..7a968d97dcaa 100644
  23. --- a/configure.ac
  24. +++ b/configure.ac
  25. @@ -34,7 +34,7 @@ AC_TYPE_SIZE_T
  26. # Checks for library functions.
  27. AC_FUNC_MALLOC
  28. AC_FUNC_REALLOC
  29. -AC_CHECK_FUNCS([alarm gethostbyname memset socket strchr strdup strstr])
  30. +AC_CHECK_FUNCS([alarm gethostbyname getopt memset socket strchr strdup strstr])
  31. AC_CONFIG_FILES([Makefile])
  32. AC_SUBST([LIBTOOL_DEPS])
  33. diff --git a/src/getopt.c b/src/getopt.c
  34. index 0109406ba4ac..8793052845ed 100644
  35. --- a/src/getopt.c
  36. +++ b/src/getopt.c
  37. @@ -31,15 +31,7 @@
  38. #include <stddef.h>
  39. #include <string.h>
  40. -#define GETOPT_INTERFACE_VERSION 2
  41. -#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
  42. -# include <gnu-versions.h>
  43. -# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
  44. -# define ELIDE_CODE
  45. -# endif
  46. -#endif
  47. -
  48. -#ifndef ELIDE_CODE
  49. +#ifndef HAVE_GETOPT
  50. char* optarg;
  51. int optopt;
  52. @@ -237,4 +229,4 @@ int getopt_long(int argc, char* const argv[], const char* optstring,
  53. return retval;
  54. }
  55. -#endif /* Not ELIDE_CODE. */
  56. +#endif /* HAVE_GETOPT */
  57. --
  58. 2.43.0