source: mainline/kernel/meson.build@ f0378c6

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f0378c6 was 62721d5, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 22 months ago

Workaround linker warnings about RWX segment

  • Property mode set to 100644
File size: 6.9 KB
Line 
1#
2# Copyright (c) 2005 Martin Decky
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# - Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# - Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14# - The name of the author may not be used to endorse or promote products
15# derived from this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28
29
30arch_src = []
31
32# Fills arch_src.
33subdir('arch' / KARCH)
34
35# Defines genarch_src.
36subdir('genarch')
37
38# Defines generic_src, instrumentable_src.
39subdir('generic')
40
41# Defines test_src
42subdir('test')
43
44## Cross-platform assembly to start a symtab.data section
45#
46symtab_section = '.section symtab.data, "a", ' + atsign + 'progbits;'
47
48kernel_include_dirs = include_directories(
49 'generic/include',
50 'genarch/include',
51 'arch' / KARCH / 'include',
52 '..' / 'abi' / 'arch' / KARCH / 'include',
53 '..' / 'abi' / 'include',
54 'test',
55)
56
57kernel_defs = [
58 '-imacros', meson.build_root() / 'config.h',
59 '-D_HELENOS_SOURCE',
60 '-DKERNEL',
61 '-DHELENOS_RELEASE=' + HELENOS_RELEASE,
62 '-DHELENOS_COPYRIGHT=' + HELENOS_COPYRIGHT,
63 '-DHELENOS_CODENAME=' + HELENOS_CODENAME,
64 '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
65]
66
67# Preprocess linker script using C preprocessor.
68kernel_ldscript = custom_target('_link.ld',
69 input: 'arch' / KARCH / '_link.ld.in',
70 output: '_link.ld',
71 command: [
72 cc.cmd_array(),
73 arch_kernel_c_args,
74 kernel_defs,
75 '-I' + meson.current_source_dir() / 'arch' / KARCH / 'include',
76 '-D__ASSEMBLER__',
77 '-D__LINKER__',
78 '-E',
79 '-P',
80 '-x', 'c',
81 '@INPUT@',
82 ],
83 capture: true,
84 build_by_default: true,
85)
86
87kernel_link_args = arch_kernel_link_args + [
88 '-Wl,--nmagic',
89 '-T', meson.current_build_dir() / '_link.ld',
90]
91# The kernel is built as ELF but then copied as a blob of bytes and
92# the permissions are not relevant anyway (needed for binutils 2.39+).
93kernel_link_args += ldflags_ignore_rwx_segments
94
95if CONFIG_LTO
96 kernel_link_args += [ '-flto' ]
97endif
98
99if CONFIG_STRIP_BINARIES
100 # TODO: do this after disassembling
101 kernel_link_args += [ '-s' ]
102endif
103
104kernel_c_args = arch_kernel_c_args + kernel_defs + [
105 '-ffreestanding',
106
107 cc.get_supported_arguments([
108 # TODO: remove this flag
109 '-Wno-cast-function-type',
110
111 # When accessing specific memory addresses that are below
112 # normal page size, the compiler may assume that we actually
113 # dereferenced NULL pointer and warns us about that.
114 # But in kernel we often need to access these addresses
115 # directly hence we need to ignore these warnings.
116 #
117 # TODO: might make more sense to disable this selectively
118 # in specific files (or better yet, for specific lines).
119 '--param=min-pagesize=0',
120 ]),
121]
122
123if CONFIG_LTO
124 kernel_c_args += [ '-flto' ]
125endif
126
127if cc.get_id() == 'clang'
128 kernel_c_args += [
129 '-fno-stack-protector',
130 '-fno-PIC',
131 '-mllvm', '-asm-macro-max-nesting-depth=1000',
132 ]
133endif
134
135instrumentables = static_library('instrumentables', instrumentable_src,
136 include_directories: kernel_include_dirs,
137 implicit_include_directories: false,
138 c_args: kernel_c_args + (CONFIG_TRACE ? [ '-finstrument-functions' ] : []),
139 pic: false,
140)
141
142noninstrumentables = static_library('noninstrumentables', arch_src, genarch_src, generic_src, test_src,
143 include_directories: kernel_include_dirs,
144 implicit_include_directories: false,
145 c_args: kernel_c_args,
146 pic: false,
147)
148
149all_kernel_objects = [ instrumentables, noninstrumentables ]
150
151# We iterate the build several times to get symbol table right.
152# Three times is sufficient to get correct even symbols after symtab.
153
154if CONFIG_SYMTAB
155 # Iterate build three times.
156 iterations = [ 1, 2, 3 ]
157
158 # Generates symbol table information as an object file.
159 genmap = find_program('tools/genmap.py')
160
161 # Symbol table dump needed for genmap.
162 kernel_syms = custom_target('kernel_syms.txt',
163 input: all_kernel_objects,
164 output: 'kernel_syms.txt',
165 command: [ objdump, '-t', '@INPUT@' ],
166 capture: true,
167 )
168else
169 # Build just once.
170 iterations = [ 1 ]
171endif
172
173# Empty symbol map for first iteration.
174kernel_map_S = custom_target('empty_map.S',
175 output: 'empty_map.S',
176 capture: true,
177 command: [ 'echo', kernel_as_prolog + symtab_section ],
178)
179
180foreach iter : iterations
181 is_last = (iter == iterations.length())
182 kernel_name = 'kernel.@0@.elf'.format(iter)
183 kernel_map_name = kernel_name + '.map'
184 kernel_map_path = meson.current_build_dir() / kernel_map_name
185
186 kernel_elf = executable(kernel_name, kernel_map_S,
187 include_directories: kernel_include_dirs,
188 implicit_include_directories: false,
189 c_args: kernel_c_args,
190 link_args: kernel_c_args + kernel_link_args + [
191 '-Wl,-Map,' + kernel_map_path,
192 ],
193 link_depends: kernel_ldscript,
194 link_whole: all_kernel_objects,
195 pie: false,
196 )
197
198 # Generate symbol table if this is not the final iteration.
199 if not is_last
200
201 # TODO: Teach kernel to read its own ELF symbol table and get rid of this nonsense.
202 # Need to first make sure all architectures (even future ones with dumb bootloaders) can use ELF formatted kernel.
203
204 kernel_map_bin = custom_target(kernel_map_name + '.bin',
205 output: kernel_map_name + '.bin',
206 input: [ kernel_elf, kernel_syms ],
207 command: [ genmap, kernel_map_path, '@INPUT1@', '@OUTPUT@' ],
208 )
209
210 kernel_map_S_name = kernel_name + '.map.S'
211
212 kernel_map_S = custom_target(kernel_map_S_name,
213 input: kernel_map_bin,
214 output: kernel_map_S_name,
215 capture: true,
216 command: [ 'echo', kernel_as_prolog + symtab_section + ' .incbin "@INPUT@"' ],
217 )
218 endif
219endforeach
220
221rd_init_binaries += [[ kernel_elf, 'boot/kernel.elf' ]]
222
223install_files += [[ 'boot', kernel_elf.full_path(), 'kernel.elf' ]]
224install_deps += [ kernel_elf ]
225
226kernel_disasm = custom_target('kernel.elf.disasm',
227 command: [ objdump, '-S', '@INPUT@' ],
228 input: kernel_elf,
229 output: 'kernel.elf.disasm',
230 capture: true,
231 build_by_default: true,
232)
233
234# TODO: Add configuration option for installing debug files
235if false
236 install_files += [[ 'boot', kernel_disasm.full_path(), 'kernel.elf.disasm' ]]
237 install_deps += [ kernel_disasm ]
238endif
Note: See TracBrowser for help on using the repository browser.