3 * (C) COPYRIGHT ARM Limited. All rights reserved.
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
20 #ifndef _ARM_CSTD_COMPILERS_H_
21 #define _ARM_CSTD_COMPILERS_H_
23 /* ============================================================================
24 Document default definitions - assuming nothing set at this point.
25 ============================================================================ */
27 * @addtogroup arm_cstd_coding_standard
33 * Defined with value of 1 if toolchain is Microsoft Visual Studio, 0
36 #define CSTD_TOOLCHAIN_MSVC 0
40 * Defined with value of 1 if toolchain is the GNU Compiler Collection, 0
43 #define CSTD_TOOLCHAIN_GCC 0
47 * Defined with value of 1 if toolchain is ARM RealView Compiler Tools, 0
48 * otherwise. Note - if running RVCT in GCC mode this define will be set to 0;
49 * @c CSTD_TOOLCHAIN_GCC and @c CSTD_TOOLCHAIN_RVCT_GCC_MODE will both be
52 #define CSTD_TOOLCHAIN_RVCT 0
56 * Defined with value of 1 if toolchain is ARM RealView Compiler Tools running
57 * in GCC mode, 0 otherwise.
59 #define CSTD_TOOLCHAIN_RVCT_GCC_MODE 0
63 * Defined with value of 1 if processor is an x86 32-bit machine, 0 otherwise.
65 #define CSTD_CPU_X86_32 0
69 * Defined with value of 1 if processor is an x86-64 (AMD64) machine, 0
72 #define CSTD_CPU_X86_64 0
76 * Defined with value of 1 if processor is an ARM machine, 0 otherwise.
78 #define CSTD_CPU_ARM 0
82 * Defined with value of 1 if processor is an AARCH64 machine, 0 otherwise.
84 #define CSTD_CPU_AARCH64 0
89 * Defined with value of 1 if processor is a MIPS machine, 0 otherwise.
91 #define CSTD_CPU_MIPS 0
95 * Defined with value of 1 if CPU is 32-bit, 0 otherwise.
97 #define CSTD_CPU_32BIT 0
101 * Defined with value of 1 if CPU is 64-bit, 0 otherwise.
103 #define CSTD_CPU_64BIT 0
107 * Defined with value of 1 if processor configured as big-endian, 0 if it
110 #define CSTD_CPU_BIG_ENDIAN 0
114 * Defined with value of 1 if operating system is a version of Windows, 0 if
117 #define CSTD_OS_WINDOWS 0
121 * Defined with value of 1 if operating system is a 32-bit version of Windows,
124 #define CSTD_OS_WIN32 0
128 * Defined with value of 1 if operating system is a 64-bit version of Windows,
131 #define CSTD_OS_WIN64 0
135 * Defined with value of 1 if operating system is Linux, 0 if it is not.
137 #define CSTD_OS_LINUX 0
141 * Defined with value of 1 if we are compiling Linux kernel code, 0 otherwise.
143 #define CSTD_OS_LINUX_KERNEL 0
147 * Defined with value of 1 if operating system is a 32-bit version of Linux,
150 #define CSTD_OS_LINUX32 0
154 * Defined with value of 1 if operating system is a 64-bit version of Linux,
157 #define CSTD_OS_LINUX64 0
161 * Defined with value of 1 if operating system is Android, 0 if it is not.
163 #define CSTD_OS_ANDROID 0
167 * Defined with value of 1 if we are compiling Android kernel code, 0 otherwise.
169 #define CSTD_OS_ANDROID_KERNEL 0
173 * Defined with value of 1 if operating system is a 32-bit version of Android,
176 #define CSTD_OS_ANDROID32 0
180 * Defined with value of 1 if operating system is a 64-bit version of Android,
183 #define CSTD_OS_ANDROID64 0
187 * Defined with value of 1 if operating system is a version of Apple OS,
190 #define CSTD_OS_APPLEOS 0
194 * Defined with value of 1 if operating system is a 32-bit version of Apple OS,
197 #define CSTD_OS_APPLEOS32 0
201 * Defined with value of 1 if operating system is a 64-bit version of Apple OS,
204 #define CSTD_OS_APPLEOS64 0
207 * @def CSTD_OS_SYMBIAN
209 * Defined with value of 1 if operating system is Symbian, 0 if it is not.
211 #define CSTD_OS_SYMBIAN 0
216 * Defined with value of 1 if there is no operating system (bare metal), 0
219 #define CSTD_OS_NONE 0
221 /* ============================================================================
222 Determine the compiler in use
223 ============================================================================ */
225 /* Default empty definitions of compiler-specific option enable/disable. This will be overridden
226 * if applicable by preprocessor defines below. */
227 #define CSTD_PUSH_WARNING_GCC_WADDRESS
228 #define CSTD_POP_WARNING_GCC_WADDRESS
230 #if defined(_MSC_VER)
231 #undef CSTD_TOOLCHAIN_MSVC
232 #define CSTD_TOOLCHAIN_MSVC 1
234 #elif defined(__GNUC__)
235 #undef CSTD_TOOLCHAIN_GCC
236 #define CSTD_TOOLCHAIN_GCC 1
238 /* Detect RVCT pretending to be GCC. */
239 #if defined(__ARMCC_VERSION)
240 #undef CSTD_TOOLCHAIN_RVCT_GCC_MODE
241 #define CSTD_TOOLCHAIN_RVCT_GCC_MODE 1
244 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6 && MALI_GCC_WORKAROUND_MIDCOM_4598 == 0)
245 /* As a workaround to MIDCOM-4598 (GCC internal defect), these pragmas are not compiled if the GCC version
246 * is within a certain range, or if a #define is enabled by the build system. For more, see a comment
247 * in the build system also referring to the MIDCOM issue mentioned, where the environment is updated
248 * for the GNU toolchain. */
249 #undef CSTD_PUSH_WARNING_GCC_WADDRESS
250 #define CSTD_PUSH_WARNING_GCC_WADDRESS \
253 _Pragma("GCC diagnostic push")\
254 _Pragma("GCC diagnostic ignored \"-Waddress\"")\
257 #undef CSTD_POP_WARNING_GCC_WADDRESS
258 #define CSTD_POP_WARNING_GCC_WADDRESS \
261 _Pragma("GCC diagnostic pop")\
265 #elif defined(__ARMCC_VERSION)
266 #undef CSTD_TOOLCHAIN_RVCT
267 #define CSTD_TOOLCHAIN_RVCT 1
270 #warning "Unsupported or unknown toolchain"
274 /* ============================================================================
275 Determine the processor
276 ============================================================================ */
277 #if 1 == CSTD_TOOLCHAIN_MSVC
279 #undef CSTD_CPU_X86_32
280 #define CSTD_CPU_X86_32 1
282 #elif defined(_M_X64) || defined(_M_AMD64)
283 #undef CSTD_CPU_X86_64
284 #define CSTD_CPU_X86_64 1
286 #elif defined(_M_ARM)
288 #define CSTD_CPU_ARM 1
290 #elif defined(_M_MIPS)
292 #define CSTD_CPU_MIPS 1
295 #warning "Unsupported or unknown host CPU for MSVC tools"
299 #elif 1 == CSTD_TOOLCHAIN_GCC
300 #if defined(__amd64__)
301 #undef CSTD_CPU_X86_64
302 #define CSTD_CPU_X86_64 1
304 #elif defined(__i386__)
305 #undef CSTD_CPU_X86_32
306 #define CSTD_CPU_X86_32 1
308 #elif defined(__arm__)
310 #define CSTD_CPU_ARM 1
312 #elif defined(__aarch64__)
313 #undef CSTD_CPU_AARCH64
314 #define CSTD_CPU_AARCH64 1
316 #elif defined(__mips__)
318 #define CSTD_CPU_MIPS 1
321 #warning "Unsupported or unknown host CPU for GCC tools"
325 #elif 1 == CSTD_TOOLCHAIN_RVCT
327 #define CSTD_CPU_ARM 1
330 #warning "Unsupported or unknown toolchain"
334 /* ============================================================================
335 Determine the Processor Endianness
336 ============================================================================ */
338 #if ((1 == CSTD_CPU_X86_32) || (1 == CSTD_CPU_X86_64))
339 /* Note: x86 and x86-64 are always little endian, so leave at default. */
341 #elif 1 == CSTD_CPU_AARCH64
342 /* No big endian support? */
344 #elif 1 == CSTD_TOOLCHAIN_RVCT
345 #if defined(__BIG_ENDIAN)
346 #undef CSTD_ENDIAN_BIG
347 #define CSTD_ENDIAN_BIG 1
350 #elif ((1 == CSTD_TOOLCHAIN_GCC) && (1 == CSTD_CPU_ARM))
351 #if defined(__ARMEB__)
352 #undef CSTD_ENDIAN_BIG
353 #define CSTD_ENDIAN_BIG 1
356 #elif ((1 == CSTD_TOOLCHAIN_GCC) && (1 == CSTD_CPU_MIPS))
357 #if defined(__MIPSEB__)
358 #undef CSTD_ENDIAN_BIG
359 #define CSTD_ENDIAN_BIG 1
362 #elif 1 == CSTD_TOOLCHAIN_MSVC
363 /* Note: Microsoft only support little endian, so leave at default. */
366 #warning "Unsupported or unknown CPU"
370 /* ============================================================================
371 Determine the operating system and addressing width
372 ============================================================================ */
373 #if 1 == CSTD_TOOLCHAIN_MSVC
374 #if defined(_WIN32) && !defined(_WIN64)
375 #undef CSTD_OS_WINDOWS
376 #define CSTD_OS_WINDOWS 1
378 #define CSTD_OS_WIN32 1
379 #undef CSTD_CPU_32BIT
380 #define CSTD_CPU_32BIT 1
382 #elif defined(_WIN32) && defined(_WIN64)
383 #undef CSTD_OS_WINDOWS
384 #define CSTD_OS_WINDOWS 1
386 #define CSTD_OS_WIN64 1
387 #undef CSTD_CPU_64BIT
388 #define CSTD_CPU_64BIT 1
391 #warning "Unsupported or unknown host OS for MSVC tools"
395 #elif 1 == CSTD_TOOLCHAIN_GCC
396 #if defined(_WIN32) && defined(_WIN64)
397 #undef CSTD_OS_WINDOWS
398 #define CSTD_OS_WINDOWS 1
400 #define CSTD_OS_WIN64 1
401 #undef CSTD_CPU_64BIT
402 #define CSTD_CPU_64BIT 1
404 #elif defined(_WIN32) && !defined(_WIN64)
405 #undef CSTD_OS_WINDOWS
406 #define CSTD_OS_WINDOWS 1
408 #define CSTD_OS_WIN32 1
409 #undef CSTD_CPU_32BIT
410 #define CSTD_CPU_32BIT 1
412 #elif defined(ANDROID)
413 #undef CSTD_OS_ANDROID
414 #define CSTD_OS_ANDROID 1
416 #if defined(__KERNEL__)
417 #undef CSTD_OS_ANDROID_KERNEL
418 #define CSTD_OS_ANDROID_KERNEL 1
421 #if defined(__LP64__) || defined(_LP64)
422 #undef CSTD_OS_ANDROID64
423 #define CSTD_OS_ANDROID64 1
424 #undef CSTD_CPU_64BIT
425 #define CSTD_CPU_64BIT 1
427 #undef CSTD_OS_ANDROID32
428 #define CSTD_OS_ANDROID32 1
429 #undef CSTD_CPU_32BIT
430 #define CSTD_CPU_32BIT 1
433 #elif defined(__KERNEL__) || defined(__linux)
435 #define CSTD_OS_LINUX 1
437 #if defined(__KERNEL__)
438 #undef CSTD_OS_LINUX_KERNEL
439 #define CSTD_OS_LINUX_KERNEL 1
442 #if defined(__LP64__) || defined(_LP64)
443 #undef CSTD_OS_LINUX64
444 #define CSTD_OS_LINUX64 1
445 #undef CSTD_CPU_64BIT
446 #define CSTD_CPU_64BIT 1
448 #undef CSTD_OS_LINUX32
449 #define CSTD_OS_LINUX32 1
450 #undef CSTD_CPU_32BIT
451 #define CSTD_CPU_32BIT 1
454 #elif defined(__APPLE__)
455 #undef CSTD_OS_APPLEOS
456 #define CSTD_OS_APPLEOS 1
458 #if defined(__LP64__) || defined(_LP64)
459 #undef CSTD_OS_APPLEOS64
460 #define CSTD_OS_APPLEOS64 1
461 #undef CSTD_CPU_64BIT
462 #define CSTD_CPU_64BIT 1
464 #undef CSTD_OS_APPLEOS32
465 #define CSTD_OS_APPLEOS32 1
466 #undef CSTD_CPU_32BIT
467 #define CSTD_CPU_32BIT 1
470 #elif defined(__SYMBIAN32__)
471 #undef CSTD_OS_SYMBIAN
472 #define CSTD_OS_SYMBIAN 1
473 #undef CSTD_CPU_32BIT
474 #define CSTD_CPU_32BIT 1
478 #define CSTD_OS_NONE 1
479 #undef CSTD_CPU_32BIT
480 #define CSTD_CPU_32BIT 1
484 #elif 1 == CSTD_TOOLCHAIN_RVCT
487 #undef CSTD_OS_ANDROID
488 #undef CSTD_OS_ANDROID32
489 #define CSTD_OS_ANDROID 1
490 #define CSTD_OS_ANDROID32 1
492 #elif defined(__linux)
494 #undef CSTD_OS_LINUX32
495 #define CSTD_OS_LINUX 1
496 #define CSTD_OS_LINUX32 1
498 #elif defined(__SYMBIAN32__)
499 #undef CSTD_OS_SYMBIAN
500 #define CSTD_OS_SYMBIAN 1
504 #define CSTD_OS_NONE 1
509 #warning "Unsupported or unknown host OS"
513 /* ============================================================================
514 Determine the correct linker symbol Import and Export Macros
515 ============================================================================ */
517 * @defgroup arm_cstd_linkage_specifiers Linkage Specifiers
520 * This set of macros contain system-dependent linkage specifiers which
521 * determine the visibility of symbols across DLL boundaries. A header for a
522 * particular DLL should define a set of local macros derived from these,
523 * and should not use these macros to decorate functions directly as there may
524 * be multiple DLLs being used.
526 * These DLL library local macros should be (with appropriate library prefix)
527 * <tt>[MY_LIBRARY]_API</tt>, <tt>[MY_LIBRARY]_IMPL</tt>, and
528 * <tt>[MY_LIBRARY]_LOCAL</tt>.
530 * - <tt>[MY_LIBRARY]_API</tt> should be use to decorate the function
531 * declarations in the header. It should be defined as either
532 * @c CSTD_LINK_IMPORT or @c CSTD_LINK_EXPORT, depending whether the
533 * current situation is a compile of the DLL itself (use export) or a
534 * compile of an external user of the DLL (use import).
535 * - <tt>[MY_LIBRARY]_IMPL</tt> should be defined as @c CSTD_LINK_IMPL
536 * and should be used to decorate the definition of functions in the C
538 * - <tt>[MY_LIBRARY]_LOCAL</tt> should be used to decorate function
539 * declarations which are exported across translation units within the
540 * DLL, but which are not exported outside of the DLL boundary.
542 * Functions which are @c static in either a C file or in a header file do not
543 * need any form of linkage decoration, and should therefore have no linkage
544 * macro applied to them.
548 * @def CSTD_LINK_IMPORT
549 * Specifies a function as being imported to a translation unit across a DLL
554 * @def CSTD_LINK_EXPORT
555 * Specifies a function as being exported across a DLL boundary by a
560 * @def CSTD_LINK_IMPL
561 * Specifies a function which will be exported across a DLL boundary as
562 * being implemented by a translation unit.
566 * @def CSTD_LINK_LOCAL
567 * Specifies a function which is internal to a DLL, and which should not be
568 * exported outside of it.
575 #if 1 == CSTD_OS_LINUX
576 #define CSTD_LINK_IMPORT __attribute__((visibility("default")))
577 #define CSTD_LINK_EXPORT __attribute__((visibility("default")))
578 #define CSTD_LINK_IMPL __attribute__((visibility("default")))
579 #define CSTD_LINK_LOCAL __attribute__((visibility("hidden")))
581 #elif 1 == CSTD_OS_WINDOWS
582 #define CSTD_LINK_IMPORT __declspec(dllimport)
583 #define CSTD_LINK_EXPORT __declspec(dllexport)
584 #define CSTD_LINK_IMPL __declspec(dllexport)
585 #define CSTD_LINK_LOCAL
587 #elif 1 == CSTD_OS_SYMBIAN
588 #define CSTD_LINK_IMPORT IMPORT_C
589 #define CSTD_LINK_EXPORT IMPORT_C
590 #define CSTD_LINK_IMPL EXPORT_C
591 #define CSTD_LINK_LOCAL
593 #elif 1 == CSTD_OS_APPLEOS
594 #define CSTD_LINK_IMPORT __attribute__((visibility("default")))
595 #define CSTD_LINK_EXPORT __attribute__((visibility("default")))
596 #define CSTD_LINK_IMPL __attribute__((visibility("default")))
597 #define CSTD_LINK_LOCAL __attribute__((visibility("hidden")))
599 #elif 1 == CSTD_OS_ANDROID
600 #define CSTD_LINK_IMPORT __attribute__((visibility("default")))
601 #define CSTD_LINK_EXPORT __attribute__((visibility("default")))
602 #define CSTD_LINK_IMPL __attribute__((visibility("default")))
603 #define CSTD_LINK_LOCAL __attribute__((visibility("hidden")))
605 #else /* CSTD_OS_NONE */
606 #define CSTD_LINK_IMPORT
607 #define CSTD_LINK_EXPORT
608 #define CSTD_LINK_IMPL
609 #define CSTD_LINK_LOCAL
617 #endif /* End (_ARM_CSTD_COMPILERS_H_) */