]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/arm64/kernel/image.h
Merge branch 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-zesty-kernel.git] / arch / arm64 / kernel / image.h
CommitLineData
a2c1d73b
MR
1/*
2 * Linker script macros to generate Image header fields.
3 *
4 * Copyright (C) 2014 ARM Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef __ASM_IMAGE_H
19#define __ASM_IMAGE_H
20
21#ifndef LINKER_SCRIPT
22#error This file should only be included in vmlinux.lds.S
23#endif
24
25/*
26 * There aren't any ELF relocations we can use to endian-swap values known only
27 * at link time (e.g. the subtraction of two symbol addresses), so we must get
28 * the linker to endian-swap certain values before emitting them.
6ad1fe5d
AB
29 *
30 * Note that, in order for this to work when building the ELF64 PIE executable
31 * (for KASLR), these values should not be referenced via R_AARCH64_ABS64
32 * relocations, since these are fixed up at runtime rather than at build time
33 * when PIE is in effect. So we need to split them up in 32-bit high and low
34 * words.
a2c1d73b
MR
35 */
36#ifdef CONFIG_CPU_BIG_ENDIAN
6ad1fe5d
AB
37#define DATA_LE32(data) \
38 ((((data) & 0x000000ff) << 24) | \
39 (((data) & 0x0000ff00) << 8) | \
40 (((data) & 0x00ff0000) >> 8) | \
41 (((data) & 0xff000000) >> 24))
a2c1d73b 42#else
6ad1fe5d 43#define DATA_LE32(data) ((data) & 0xffffffff)
a2c1d73b
MR
44#endif
45
6ad1fe5d
AB
46#define DEFINE_IMAGE_LE64(sym, data) \
47 sym##_lo32 = DATA_LE32((data) & 0xffffffff); \
48 sym##_hi32 = DATA_LE32((data) >> 32)
49
a2c1d73b 50#ifdef CONFIG_CPU_BIG_ENDIAN
a7f8de16 51#define __HEAD_FLAG_BE 1
a2c1d73b 52#else
a7f8de16 53#define __HEAD_FLAG_BE 0
a2c1d73b
MR
54#endif
55
a7f8de16 56#define __HEAD_FLAG_PAGE_SIZE ((PAGE_SHIFT - 10) / 2)
9d372c9f 57
a7f8de16 58#define __HEAD_FLAG_PHYS_BASE 1
9d372c9f 59
a7f8de16
AB
60#define __HEAD_FLAGS ((__HEAD_FLAG_BE << 0) | \
61 (__HEAD_FLAG_PAGE_SIZE << 1) | \
62 (__HEAD_FLAG_PHYS_BASE << 3))
a2c1d73b
MR
63
64/*
65 * These will output as part of the Image header, which should be little-endian
66 * regardless of the endianness of the kernel. While constant values could be
67 * endian swapped in head.S, all are done here for consistency.
68 */
69#define HEAD_SYMBOLS \
6ad1fe5d
AB
70 DEFINE_IMAGE_LE64(_kernel_size_le, _end - _text); \
71 DEFINE_IMAGE_LE64(_kernel_offset_le, TEXT_OFFSET); \
72 DEFINE_IMAGE_LE64(_kernel_flags_le, __HEAD_FLAGS);
a2c1d73b 73
e8f3010f
AB
74#ifdef CONFIG_EFI
75
546c8c44
AB
76__efistub_stext_offset = stext - _text;
77
75feee3d
AB
78/*
79 * Prevent the symbol aliases below from being emitted into the kallsyms
80 * table, by forcing them to be absolute symbols (which are conveniently
81 * ignored by scripts/kallsyms) rather than section relative symbols.
82 * The distinction is only relevant for partial linking, and only for symbols
83 * that are defined within a section declaration (which is not the case for
84 * the definitions below) so the resulting values will be identical.
85 */
86#define KALLSYMS_HIDE(sym) ABSOLUTE(sym)
87
e8f3010f
AB
88/*
89 * The EFI stub has its own symbol namespace prefixed by __efistub_, to
90 * isolate it from the kernel proper. The following symbols are legally
91 * accessed by the stub, so provide some aliases to make them accessible.
92 * Only include data symbols here, or text symbols of functions that are
93 * guaranteed to be safe when executed at another offset than they were
94 * linked at. The routines below are all implemented in assembler in a
95 * position independent manner
96 */
75feee3d
AB
97__efistub_memcmp = KALLSYMS_HIDE(__pi_memcmp);
98__efistub_memchr = KALLSYMS_HIDE(__pi_memchr);
99__efistub_memcpy = KALLSYMS_HIDE(__pi_memcpy);
100__efistub_memmove = KALLSYMS_HIDE(__pi_memmove);
101__efistub_memset = KALLSYMS_HIDE(__pi_memset);
102__efistub_strlen = KALLSYMS_HIDE(__pi_strlen);
7f4e3462 103__efistub_strnlen = KALLSYMS_HIDE(__pi_strnlen);
75feee3d
AB
104__efistub_strcmp = KALLSYMS_HIDE(__pi_strcmp);
105__efistub_strncmp = KALLSYMS_HIDE(__pi_strncmp);
106__efistub___flush_dcache_area = KALLSYMS_HIDE(__pi___flush_dcache_area);
e8f3010f 107
39d114dd 108#ifdef CONFIG_KASAN
75feee3d
AB
109__efistub___memcpy = KALLSYMS_HIDE(__pi_memcpy);
110__efistub___memmove = KALLSYMS_HIDE(__pi_memmove);
111__efistub___memset = KALLSYMS_HIDE(__pi_memset);
39d114dd
AR
112#endif
113
75feee3d
AB
114__efistub__text = KALLSYMS_HIDE(_text);
115__efistub__end = KALLSYMS_HIDE(_end);
116__efistub__edata = KALLSYMS_HIDE(_edata);
57fdb89a 117__efistub_screen_info = KALLSYMS_HIDE(screen_info);
e8f3010f
AB
118
119#endif
120
a2c1d73b 121#endif /* __ASM_IMAGE_H */