linux.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* Definitions for systems using the Linux kernel, with or without
  2. MMU, using ELF at the compiler level but possibly FLT for final
  3. linked executables and shared libraries in some no-MMU cases, and
  4. possibly with a choice of libc implementations.
  5. Copyright (C) 1995-2015 Free Software Foundation, Inc.
  6. Contributed by Eric Youngdale.
  7. Modified for stabs-in-ELF by H.J. Lu (hjl@lucon.org).
  8. This file is part of GCC.
  9. GCC is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 3, or (at your option)
  12. any later version.
  13. GCC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. Under Section 7 of GPL version 3, you are granted additional
  18. permissions described in the GCC Runtime Library Exception, version
  19. 3.1, as published by the Free Software Foundation.
  20. You should have received a copy of the GNU General Public License and
  21. a copy of the GCC Runtime Library Exception along with this program;
  22. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  23. <http://www.gnu.org/licenses/>. */
  24. /* C libraries supported on Linux. */
  25. #ifdef SINGLE_LIBC
  26. #define OPTION_GLIBC (DEFAULT_LIBC == LIBC_GLIBC)
  27. #define OPTION_UCLIBC (DEFAULT_LIBC == LIBC_UCLIBC)
  28. #define OPTION_BIONIC (DEFAULT_LIBC == LIBC_BIONIC)
  29. #undef OPTION_MUSL
  30. #define OPTION_MUSL (DEFAULT_LIBC == LIBC_MUSL)
  31. #else
  32. #define OPTION_GLIBC (linux_libc == LIBC_GLIBC)
  33. #define OPTION_UCLIBC (linux_libc == LIBC_UCLIBC)
  34. #define OPTION_BIONIC (linux_libc == LIBC_BIONIC)
  35. #undef OPTION_MUSL
  36. #define OPTION_MUSL (linux_libc == LIBC_MUSL)
  37. #endif
  38. #define GNU_USER_TARGET_OS_CPP_BUILTINS() \
  39. do { \
  40. if (OPTION_GLIBC) \
  41. builtin_define ("__gnu_linux__"); \
  42. builtin_define_std ("linux"); \
  43. builtin_define_std ("unix"); \
  44. builtin_assert ("system=linux"); \
  45. builtin_assert ("system=unix"); \
  46. builtin_assert ("system=posix"); \
  47. } while (0)
  48. #ifndef LIBGCC_SPEC
  49. #define LIBGCC_SPEC "%{static|static-libgcc:-lgcc}%{!static:%{!static-libgcc:-lgcc_s}}"
  50. #endif
  51. /* Determine which dynamic linker to use depending on whether GLIBC or
  52. uClibc or Bionic or musl is the default C library and whether
  53. -muclibc or -mglibc or -mbionic or -mmusl has been passed to change
  54. the default. */
  55. #define CHOOSE_DYNAMIC_LINKER1(LIBC1, LIBC2, LIBC3, LIBC4, LD1, LD2, LD3, LD4) \
  56. "%{" LIBC2 ":" LD2 ";:%{" LIBC3 ":" LD3 ";:%{" LIBC4 ":" LD4 ";:" LD1 "}}}"
  57. #if DEFAULT_LIBC == LIBC_GLIBC
  58. #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  59. CHOOSE_DYNAMIC_LINKER1 ("mglibc", "muclibc", "mbionic", "mmusl", G, U, B, M)
  60. #elif DEFAULT_LIBC == LIBC_UCLIBC
  61. #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  62. CHOOSE_DYNAMIC_LINKER1 ("muclibc", "mglibc", "mbionic", "mmusl", U, G, B, M)
  63. #elif DEFAULT_LIBC == LIBC_BIONIC
  64. #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  65. CHOOSE_DYNAMIC_LINKER1 ("mbionic", "mglibc", "muclibc", "mmusl", B, G, U, M)
  66. #elif DEFAULT_LIBC == LIBC_MUSL
  67. #define CHOOSE_DYNAMIC_LINKER(G, U, B, M) \
  68. CHOOSE_DYNAMIC_LINKER1 ("mmusl", "mglibc", "muclibc", "mbionic", M, G, U, B)
  69. #else
  70. #error "Unsupported DEFAULT_LIBC"
  71. #endif /* DEFAULT_LIBC */
  72. /* For most targets the following definitions suffice;
  73. GLIBC_DYNAMIC_LINKER must be defined for each target using them, or
  74. GLIBC_DYNAMIC_LINKER32 and GLIBC_DYNAMIC_LINKER64 for targets
  75. supporting both 32-bit and 64-bit compilation. */
  76. #define UCLIBC_DYNAMIC_LINKER "/lib/ld-uClibc.so.0"
  77. #define UCLIBC_DYNAMIC_LINKER32 "/lib/ld-uClibc.so.0"
  78. #define UCLIBC_DYNAMIC_LINKER64 "/lib/ld64-uClibc.so.0"
  79. #define UCLIBC_DYNAMIC_LINKERX32 "/lib/ldx32-uClibc.so.0"
  80. #define BIONIC_DYNAMIC_LINKER "/system/bin/linker"
  81. #define BIONIC_DYNAMIC_LINKER32 "/system/bin/linker"
  82. #define BIONIC_DYNAMIC_LINKER64 "/system/bin/linker64"
  83. #define BIONIC_DYNAMIC_LINKERX32 "/system/bin/linkerx32"
  84. /* Should be redefined for each target that supports musl. */
  85. #define MUSL_DYNAMIC_LINKER "/dev/null"
  86. #define MUSL_DYNAMIC_LINKER32 "/dev/null"
  87. #define MUSL_DYNAMIC_LINKER64 "/dev/null"
  88. #define MUSL_DYNAMIC_LINKERX32 "/dev/null"
  89. #define GNU_USER_DYNAMIC_LINKER \
  90. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER, UCLIBC_DYNAMIC_LINKER, \
  91. BIONIC_DYNAMIC_LINKER, MUSL_DYNAMIC_LINKER)
  92. #define GNU_USER_DYNAMIC_LINKER32 \
  93. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER32, UCLIBC_DYNAMIC_LINKER32, \
  94. BIONIC_DYNAMIC_LINKER32, MUSL_DYNAMIC_LINKER32)
  95. #define GNU_USER_DYNAMIC_LINKER64 \
  96. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKER64, UCLIBC_DYNAMIC_LINKER64, \
  97. BIONIC_DYNAMIC_LINKER64, MUSL_DYNAMIC_LINKER64)
  98. #define GNU_USER_DYNAMIC_LINKERX32 \
  99. CHOOSE_DYNAMIC_LINKER (GLIBC_DYNAMIC_LINKERX32, UCLIBC_DYNAMIC_LINKERX32, \
  100. BIONIC_DYNAMIC_LINKERX32, MUSL_DYNAMIC_LINKERX32)
  101. /* Whether we have Bionic libc runtime */
  102. #undef TARGET_HAS_BIONIC
  103. #define TARGET_HAS_BIONIC (OPTION_BIONIC)
  104. /* musl avoids problematic includes by rearranging the include directories.
  105. * Unfortunately, this is mostly duplicated from cppdefault.c */
  106. #if DEFAULT_LIBC == LIBC_MUSL
  107. #define INCLUDE_DEFAULTS_MUSL_GPP \
  108. { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1, \
  109. GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 }, \
  110. { GPLUSPLUS_TOOL_INCLUDE_DIR, "G++", 1, 1, \
  111. GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 1 }, \
  112. { GPLUSPLUS_BACKWARD_INCLUDE_DIR, "G++", 1, 1, \
  113. GPLUSPLUS_INCLUDE_DIR_ADD_SYSROOT, 0 },
  114. #ifdef LOCAL_INCLUDE_DIR
  115. #define INCLUDE_DEFAULTS_MUSL_LOCAL \
  116. { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 2 }, \
  117. { LOCAL_INCLUDE_DIR, 0, 0, 1, 1, 0 },
  118. #else
  119. #define INCLUDE_DEFAULTS_MUSL_LOCAL
  120. #endif
  121. #ifdef PREFIX_INCLUDE_DIR
  122. #define INCLUDE_DEFAULTS_MUSL_PREFIX \
  123. { PREFIX_INCLUDE_DIR, 0, 0, 1, 0, 0},
  124. #else
  125. #define INCLUDE_DEFAULTS_MUSL_PREFIX
  126. #endif
  127. #ifdef CROSS_INCLUDE_DIR
  128. #define INCLUDE_DEFAULTS_MUSL_CROSS \
  129. { CROSS_INCLUDE_DIR, "GCC", 0, 0, 0, 0},
  130. #else
  131. #define INCLUDE_DEFAULTS_MUSL_CROSS
  132. #endif
  133. #ifdef TOOL_INCLUDE_DIR
  134. #define INCLUDE_DEFAULTS_MUSL_TOOL \
  135. { TOOL_INCLUDE_DIR, "BINUTILS", 0, 1, 0, 0},
  136. #else
  137. #define INCLUDE_DEFAULTS_MUSL_TOOL
  138. #endif
  139. #ifdef NATIVE_SYSTEM_HEADER_DIR
  140. #define INCLUDE_DEFAULTS_MUSL_NATIVE \
  141. { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 2 }, \
  142. { NATIVE_SYSTEM_HEADER_DIR, 0, 0, 0, 1, 0 },
  143. #else
  144. #define INCLUDE_DEFAULTS_MUSL_NATIVE
  145. #endif
  146. #if defined (CROSS_DIRECTORY_STRUCTURE) && !defined (TARGET_SYSTEM_ROOT)
  147. # undef INCLUDE_DEFAULTS_MUSL_LOCAL
  148. # define INCLUDE_DEFAULTS_MUSL_LOCAL
  149. # undef INCLUDE_DEFAULTS_MUSL_NATIVE
  150. # define INCLUDE_DEFAULTS_MUSL_NATIVE
  151. #else
  152. # undef INCLUDE_DEFAULTS_MUSL_CROSS
  153. # define INCLUDE_DEFAULTS_MUSL_CROSS
  154. #endif
  155. #undef INCLUDE_DEFAULTS
  156. #define INCLUDE_DEFAULTS \
  157. { \
  158. INCLUDE_DEFAULTS_MUSL_GPP \
  159. INCLUDE_DEFAULTS_MUSL_PREFIX \
  160. INCLUDE_DEFAULTS_MUSL_CROSS \
  161. INCLUDE_DEFAULTS_MUSL_TOOL \
  162. INCLUDE_DEFAULTS_MUSL_NATIVE \
  163. { GCC_INCLUDE_DIR, "GCC", 0, 1, 0, 0 }, \
  164. { 0, 0, 0, 0, 0, 0 } \
  165. }
  166. #endif
  167. #if (DEFAULT_LIBC == LIBC_UCLIBC) && defined (SINGLE_LIBC) /* uClinux */
  168. /* This is a *uclinux* target. We don't define below macros to normal linux
  169. versions, because doing so would require *uclinux* targets to include
  170. linux.c, linux-protos.h, linux.opt, etc. We could, alternatively, add
  171. these files to *uclinux* targets, but that would only pollute option list
  172. (add -mglibc, etc.) without adding any useful support. */
  173. /* Define TARGET_LIBC_HAS_FUNCTION for *uclinux* targets to
  174. no_c99_libc_has_function, because uclibc does not, normally, have
  175. c99 runtime. If, in special cases, uclibc does have c99 runtime,
  176. this should be defined to a new hook. Also please note that for targets
  177. like *-linux-uclibc that similar check will also need to be added to
  178. linux_libc_has_function. */
  179. # undef TARGET_LIBC_HAS_FUNCTION
  180. # define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function
  181. #else /* !uClinux, i.e., normal Linux */
  182. /* Determine what functions are present at the runtime;
  183. this includes full c99 runtime and sincos. */
  184. # undef TARGET_LIBC_HAS_FUNCTION
  185. # define TARGET_LIBC_HAS_FUNCTION linux_libc_has_function
  186. #endif