source: mainline/kernel/meson.build@ 3706d93

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3706d93 was 28fcaee, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

amd64 boot

  • Property mode set to 100644
File size: 4.7 KB
Line 
1
2arch_src = []
3
4# Fills arch_src.
5subdir('arch' / KARCH)
6
7# Defines genarch_src.
8subdir('genarch')
9
10# Defines generic_src, instrumentable_src.
11subdir('generic')
12
13# Defines test_src
14subdir('test')
15
16## Cross-platform assembly to start a symtab.data section
17#
18symtab_section = '.section symtab.data, "a", ' + atsign + 'progbits;'
19
20kernel_include_dirs = include_directories(
21 'generic/include',
22 'genarch/include',
23 'arch' / KARCH / 'include',
24 '..' / 'abi' / 'arch' / KARCH / 'include',
25 '..' / 'abi' / 'include',
26 'test',
27)
28
29kernel_defs = [
30 '-imacros', meson.source_root() / 'config.h',
31 '-D_HELENOS_SOURCE',
32 '-DKERNEL',
33 '-DRELEASE=' + HELENOS_RELEASE,
34 '-DCOPYRIGHT=' + HELENOS_COPYRIGHT,
35 '-DNAME=' + HELENOS_NAME,
36 '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
37]
38
39# Preprocess linker script using C preprocessor.
40kernel_ldscript = custom_target('_link.ld',
41 input: 'arch' / KARCH / '_link.ld.in',
42 output: '_link.ld',
43 command: [
44 cc.cmd_array(),
45 arch_kernel_c_args,
46 kernel_defs,
47 '-I' + meson.current_source_dir() / 'arch' / KARCH / 'include',
48 '-D__ASSEMBLER__',
49 '-D__LINKER__',
50 '-E',
51 '-P',
52 '-x', 'c',
53 '@INPUT@',
54 ],
55 capture: true,
56)
57
58kernel_link_args = arch_kernel_link_args + [
59 '-Wl,--nmagic',
60 '-T', meson.current_build_dir() / '_link.ld',
61]
62
63if CONFIG_STRIP_BINARIES
64 # TODO: let meson do this
65 kernel_link_args += [ '-s' ]
66endif
67
68kernel_c_args = arch_kernel_c_args + kernel_defs + [
69 '-ffreestanding',
70 # TODO: remove this flag
71 '-Wno-cast-function-type',
72]
73
74if cc.get_id() == 'clang'
75 kernel_c_args += [
76 '-fno-stack-protector',
77 '-fno-PIC',
78 '-mllvm', '-asm-macro-max-nesting-depth=1000',
79 ]
80endif
81
82instrumentables = static_library('instrumentables', instrumentable_src,
83 include_directories: kernel_include_dirs,
84 implicit_include_directories: false,
85 c_args: kernel_c_args + (CONFIG_TRACE ? [ '-finstrument-functions' ] : []),
86 pic: false,
87)
88
89noninstrumentables = static_library('noninstrumentables', arch_src, genarch_src, generic_src, test_src,
90 include_directories: kernel_include_dirs,
91 implicit_include_directories: false,
92 c_args: kernel_c_args,
93 pic: false,
94)
95
96all_kernel_objects = [ instrumentables, noninstrumentables ]
97
98# We iterate the build several times to get symbol table right.
99# Three times is sufficient to get correct even symbols after symtab.
100
101if CONFIG_SYMTAB
102 # Iterate build three times.
103 iterations = [ 1, 2, 3 ]
104
105 # Generates symbol table information as an object file.
106 genmap = find_program('tools/genmap.py')
107
108 # Symbol table dump needed for genmap.
109 kernel_syms = custom_target('kernel_syms.txt',
110 input: all_kernel_objects,
111 output: 'kernel_syms.txt',
112 command: [ objdump, '-t', '@INPUT@' ],
113 capture: true,
114 )
115else
116 # Build just once.
117 iterations = [ 1 ]
118endif
119
120# Empty symbol map for first iteration.
121kernel_map_S = custom_target('empty_map.S',
122 output: 'empty_map.S',
123 capture: true,
124 command: [ 'echo', kernel_as_prolog + symtab_section ],
125)
126
127foreach iter : iterations
128 is_last = (iter == iterations.length())
129 kernel_name = 'kernel.@0@.elf'.format(iter)
130 kernel_map_name = kernel_name + '.map'
131 kernel_map_path = meson.current_build_dir() / kernel_map_name
132
133 kernel_elf = executable(kernel_name, kernel_map_S,
134 include_directories: kernel_include_dirs,
135 implicit_include_directories: false,
136 c_args: kernel_c_args,
137 link_args: kernel_c_args + kernel_link_args + [
138 '-Wl,-Map,' + kernel_map_path,
139 ],
140 link_depends: kernel_ldscript,
141 link_whole: all_kernel_objects,
142 pie: false,
143 )
144
145 # Generate symbol table if this is not the final iteration.
146 if not is_last
147
148 # TODO: Teach kernel to read its own ELF symbol table and get rid of this nonsense.
149 # Need to first make sure all architectures (even future ones with dumb bootloaders) can use ELF formatted kernel.
150
151 kernel_map_bin = custom_target(kernel_map_name + '.bin',
152 output: kernel_map_name + '.bin',
153 input: [ kernel_elf, kernel_syms ],
154 command: [ genmap, kernel_map_path, '@INPUT1@', '@OUTPUT@' ],
155 )
156
157 kernel_map_S_name = kernel_name + '.map.S'
158
159 kernel_map_S = custom_target(kernel_map_S_name,
160 input: kernel_map_bin,
161 output: kernel_map_S_name,
162 capture: true,
163 command: [ 'echo', kernel_as_prolog + symtab_section + ' .incbin "@INPUT@"' ],
164 )
165 endif
166endforeach
167
168rd_init_binaries += [[ kernel_elf, 'boot/kernel.elf' ]]
169
170install_files += [[ 'boot', kernel_elf.full_path(), 'kernel.elf' ]]
171install_deps += [ kernel_elf ]
172
173kernel_disasm = custom_target('kernel.elf.disasm',
174 command: [ objdump, '-S', '@INPUT@' ],
175 input: kernel_elf,
176 output: 'kernel.elf.disasm',
177 capture: true,
178 build_by_default: true,
179)
180
181# TODO: Add configuration option for installing debug files
182if false
183 install_files += [[ 'boot', kernel_disasm.full_path(), 'kernel.elf.disasm' ]]
184 install_deps += [ kernel_disasm ]
185endif
Note: See TracBrowser for help on using the repository browser.