0002-musl-libs.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. From 2e1f8ca0b67c1d1991c14d509938c347e09bae94 Mon Sep 17 00:00:00 2001
  2. From: Hongxu Jia <hongxu.jia@windriver.com>
  3. Date: Fri, 23 Aug 2019 10:18:47 +0800
  4. Subject: [PATCH] musl-libs
  5. Collection of fixes needed to compile libelf and other libraries
  6. provided by elfutils for musl targets
  7. error is glibc specific API, so this patch will mostly not accepted
  8. upstream given that elfutils has been closely tied to glibc
  9. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  10. Upstream-Status: Inappropriate [workaround for musl]
  11. Rebase to 0.177
  12. Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
  13. ---
  14. lib/error.h | 27 +++++++++++++++++++++++++++
  15. lib/fixedsizehash.h | 1 -
  16. lib/libeu.h | 1 +
  17. libdwfl/dwfl_error.c | 9 +++++++++
  18. libdwfl/linux-kernel-modules.c | 1 +
  19. libelf/elf.h | 9 ++++++---
  20. 6 files changed, 44 insertions(+), 4 deletions(-)
  21. create mode 100644 lib/error.h
  22. diff --git a/lib/error.h b/lib/error.h
  23. new file mode 100644
  24. index 0000000..ef06827
  25. --- /dev/null
  26. +++ b/lib/error.h
  27. @@ -0,0 +1,27 @@
  28. +#ifndef _ERROR_H_
  29. +#define _ERROR_H_
  30. +
  31. +#include <stdarg.h>
  32. +#include <stdio.h>
  33. +#include <stdlib.h>
  34. +#include <string.h>
  35. +#include <errno.h>
  36. +
  37. +static unsigned int error_message_count = 0;
  38. +
  39. +static inline void error(int status, int errnum, const char* format, ...)
  40. +{
  41. + va_list ap;
  42. + fprintf(stderr, "%s: ", program_invocation_name);
  43. + va_start(ap, format);
  44. + vfprintf(stderr, format, ap);
  45. + va_end(ap);
  46. + if (errnum)
  47. + fprintf(stderr, ": %s", strerror(errnum));
  48. + fprintf(stderr, "\n");
  49. + error_message_count++;
  50. + if (status)
  51. + exit(status);
  52. +}
  53. +
  54. +#endif /* _ERROR_H_ */
  55. diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
  56. index dac2a5f..43016fc 100644
  57. --- a/lib/fixedsizehash.h
  58. +++ b/lib/fixedsizehash.h
  59. @@ -30,7 +30,6 @@
  60. #include <errno.h>
  61. #include <stdlib.h>
  62. #include <string.h>
  63. -#include <sys/cdefs.h>
  64. #include <system.h>
  65. diff --git a/lib/libeu.h b/lib/libeu.h
  66. index ecb4d01..edc85e3 100644
  67. --- a/lib/libeu.h
  68. +++ b/lib/libeu.h
  69. @@ -29,6 +29,7 @@
  70. #ifndef LIBEU_H
  71. #define LIBEU_H
  72. +#include "system.h"
  73. #include <stddef.h>
  74. #include <stdint.h>
  75. diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
  76. index 7bcf61c..11dcc8b 100644
  77. --- a/libdwfl/dwfl_error.c
  78. +++ b/libdwfl/dwfl_error.c
  79. @@ -154,7 +154,16 @@ dwfl_errmsg (int error)
  80. switch (error &~ 0xffff)
  81. {
  82. case OTHER_ERROR (ERRNO):
  83. +#if defined(__GLIBC__)
  84. return strerror_r (error & 0xffff, "bad", 0);
  85. +#else
  86. + {
  87. + static __thread char buf[128] = "";
  88. + if (strerror_r (error & 0xffff, buf, sizeof(buf)) == 0)
  89. + return buf;
  90. + }
  91. + return "strerror_r() failed";
  92. +#endif
  93. case OTHER_ERROR (LIBELF):
  94. return elf_errmsg (error & 0xffff);
  95. case OTHER_ERROR (LIBDW):
  96. diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
  97. index 0434f1e..5afaee8 100644
  98. --- a/libdwfl/linux-kernel-modules.c
  99. +++ b/libdwfl/linux-kernel-modules.c
  100. @@ -50,6 +50,7 @@
  101. #include <sys/utsname.h>
  102. #include <fcntl.h>
  103. #include <unistd.h>
  104. +#include "system.h"
  105. /* If fts.h is included before config.h, its indirect inclusions may not
  106. give us the right LFS aliases of these functions, so map them manually. */
  107. diff --git a/libelf/elf.h b/libelf/elf.h
  108. index 197b557..8e5b94c 100644
  109. --- a/libelf/elf.h
  110. +++ b/libelf/elf.h
  111. @@ -21,7 +21,9 @@
  112. #include <features.h>
  113. -__BEGIN_DECLS
  114. +#ifdef __cplusplus
  115. +extern "C" {
  116. +#endif
  117. /* Standard ELF types. */
  118. @@ -4103,6 +4105,7 @@ enum
  119. #define R_ARC_TLS_LE_S9 0x4a
  120. #define R_ARC_TLS_LE_32 0x4b
  121. -__END_DECLS
  122. -
  123. +#ifdef __cplusplus
  124. +}
  125. +#endif
  126. #endif /* elf.h */