1/*
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include <wtf/Platform.h>
29
30#if !CPU(UNKNOWN)
31
32/* asm directive helpers */
33
34#if OS(DARWIN) || (OS(WINDOWS) && CPU(X86))
35#define SYMBOL_STRING(name) "_" #name
36#else
37#define SYMBOL_STRING(name) #name
38#endif
39
40#if OS(IOS_FAMILY)
41#define THUMB_FUNC_PARAM(name) SYMBOL_STRING(name)
42#else
43#define THUMB_FUNC_PARAM(name)
44#endif
45
46#if (OS(LINUX) || OS(FREEBSD)) && CPU(X86_64)
47#define GLOBAL_REFERENCE(name) #name "@plt"
48#elif CPU(X86) && COMPILER(MINGW)
49#define GLOBAL_REFERENCE(name) "@" #name "@4"
50#elif OS(LINUX) && CPU(X86) && defined(__PIC__)
51#define GLOBAL_REFERENCE(name) SYMBOL_STRING(name) "@plt"
52#else
53#define GLOBAL_REFERENCE(name) SYMBOL_STRING(name)
54#endif
55
56#if HAVE(INTERNAL_VISIBILITY)
57#define LOCAL_REFERENCE(name) SYMBOL_STRING(name)
58#else
59#define LOCAL_REFERENCE(name) GLOBAL_REFERENCE(name)
60#endif
61
62#if OS(DARWIN)
63 // Mach-O platform
64#define HIDE_SYMBOL(name) ".private_extern _" #name
65#elif OS(AIX)
66 // IBM's own file format
67#define HIDE_SYMBOL(name) ".lglobl " #name
68#elif OS(LINUX) \
69 || OS(FREEBSD) \
70 || OS(FUCHSIA) \
71 || OS(OPENBSD) \
72 || OS(HPUX) \
73 || OS(NETBSD)
74 // ELF platform
75#define HIDE_SYMBOL(name) ".hidden " #name
76#else
77#define HIDE_SYMBOL(name)
78#endif
79
80// FIXME: figure out how this works on all the platforms. I know that
81// on ELF, the preferred form is ".Lstuff" as opposed to "Lstuff".
82// Don't know about any of the others.
83#if OS(DARWIN)
84#define LOCAL_LABEL_STRING(name) "L" #name
85#elif OS(LINUX) \
86 || OS(FREEBSD) \
87 || OS(FUCHSIA) \
88 || OS(OPENBSD) \
89 || OS(HURD) \
90 || OS(NETBSD) \
91 || COMPILER(MINGW)
92 // GNU as-compatible syntax.
93#define LOCAL_LABEL_STRING(name) ".L" #name
94#endif
95
96#if CPU(ARM_THUMB2)
97#define INLINE_ARM_FUNCTION(name) ".thumb" "\n" ".thumb_func " THUMB_FUNC_PARAM(name) "\n"
98#else
99#define INLINE_ARM_FUNCTION(name)
100#endif
101
102#endif // !CPU(UNKNOWN)
103