source: mainline/kernel/meson.build@ da13982

topic/msim-upgrade topic/simplify-dev-export
Last change on this file since da13982 was da13982, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 2 years ago

Read symbol table from ELF sections

Instead of the currently broken data generated using genmap.py,
read the ELF symbol table for stack traces and symbol names.
In addition to that, prepare ground for accessing DWARF debug
sections.

Because neither .symtab, nor .debug_* sections are
normally part of the program image, these have to be provided
externally. Instead of the previous way of relinking kernel
to bake in the symbol data, we now only link kernel once
and the extra debug data is loaded as part of the initrd image.

  • Property mode set to 100644
File size: 5.6 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
44kernel_include_dirs = include_directories(
45 'generic/include',
46 'genarch/include',
47 'arch' / KARCH / 'include',
48 '..' / 'abi' / 'arch' / KARCH / 'include',
49 '..' / 'abi' / 'include',
50 'test',
51)
52
53kernel_defs = [
54 '-imacros', meson.build_root() / 'config.h',
55 '-D_HELENOS_SOURCE',
56 '-DKERNEL',
57 '-DHELENOS_RELEASE=' + HELENOS_RELEASE,
58 '-DHELENOS_COPYRIGHT=' + HELENOS_COPYRIGHT,
59 '-DHELENOS_CODENAME=' + HELENOS_CODENAME,
60 '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
61]
62
63# Preprocess linker script using C preprocessor.
64kernel_ldscript = custom_target('_link.ld',
65 input: 'arch' / KARCH / '_link.ld.in',
66 output: '_link.ld',
67 command: [
68 cc.cmd_array(),
69 arch_kernel_c_args,
70 kernel_defs,
71 '-I' + meson.current_source_dir() / 'arch' / KARCH / 'include',
72 '-D__ASSEMBLER__',
73 '-D__LINKER__',
74 '-E',
75 '-P',
76 '-x', 'c',
77 '@INPUT@',
78 ],
79 capture: true,
80 build_by_default: true,
81)
82
83kernel_link_args = arch_kernel_link_args + [
84 '-Wl,--nmagic',
85 '-T', meson.current_build_dir() / '_link.ld',
86]
87# The kernel is built as ELF but then copied as a blob of bytes and
88# the permissions are not relevant anyway (needed for binutils 2.39+).
89kernel_link_args += ldflags_ignore_rwx_segments
90
91if CONFIG_LTO
92 kernel_link_args += [ '-flto' ]
93endif
94
95kernel_c_args = arch_kernel_c_args + kernel_defs + [
96 '-ffreestanding',
97
98 cc.get_supported_arguments([
99 # TODO: remove this flag
100 '-Wno-cast-function-type',
101
102 # When accessing specific memory addresses that are below
103 # normal page size, the compiler may assume that we actually
104 # dereferenced NULL pointer and warns us about that.
105 # But in kernel we often need to access these addresses
106 # directly hence we need to ignore these warnings.
107 #
108 # TODO: might make more sense to disable this selectively
109 # in specific files (or better yet, for specific lines).
110 '--param=min-pagesize=0',
111 ]),
112]
113
114if CONFIG_LTO
115 kernel_c_args += [ '-flto' ]
116endif
117
118if cc.get_id() == 'clang'
119 kernel_c_args += [
120 '-fno-stack-protector',
121 '-fno-PIC',
122 '-mllvm', '-asm-macro-max-nesting-depth=1000',
123 ]
124endif
125
126instrumentables = static_library('instrumentables', instrumentable_src,
127 include_directories: kernel_include_dirs,
128 implicit_include_directories: false,
129 c_args: kernel_c_args + (CONFIG_TRACE ? [ '-finstrument-functions' ] : []),
130 pic: false,
131)
132
133noninstrumentables = static_library('noninstrumentables', arch_src, genarch_src, generic_src, test_src,
134 include_directories: kernel_include_dirs,
135 implicit_include_directories: false,
136 c_args: kernel_c_args,
137 pic: false,
138)
139
140all_kernel_objects = [ instrumentables, noninstrumentables ]
141
142kernel_name = 'kernel.elf'
143kernel_map_name = kernel_name + '.map'
144kernel_map_path = meson.current_build_dir() / kernel_map_name
145
146kernel_elf = executable(kernel_name,
147 include_directories: kernel_include_dirs,
148 implicit_include_directories: false,
149 c_args: kernel_c_args,
150 link_args: kernel_c_args + kernel_link_args + [
151 '-Wl,-Map,' + kernel_map_path,
152 ],
153 link_depends: kernel_ldscript,
154 link_whole: all_kernel_objects,
155 pie: false,
156)
157
158kernel_dbg = custom_target('kernel.dbg',
159 output: 'kernel.dbg',
160 input: kernel_elf,
161 command: [
162 objcopy,
163 '--only-keep-debug',
164 '@INPUT@',
165 '@OUTPUT@',
166 ],
167)
168
169kernel_elf_stripped = custom_target(kernel_name + '.stripped',
170 output: kernel_name + '.stripped',
171 input: kernel_elf,
172 command: [
173 objcopy,
174 '--strip-unneeded',
175 '@INPUT@',
176 '@OUTPUT@',
177 ],
178)
179
180rd_init_binaries += [[ kernel_elf_stripped, 'boot/kernel.elf' ]]
181install_files += [[ 'boot', kernel_elf_stripped.full_path(), 'kernel.elf' ]]
182install_deps += [ kernel_elf_stripped ]
183
184if CONFIG_SYMTAB
185 rd_init_binaries += [[ kernel_dbg, 'kernel.dbg' ]]
186 install_files += [[ 'boot', kernel_dbg.full_path(), 'kernel.dbg' ]]
187 install_deps += [ kernel_dbg ]
188endif
189
190kernel_disasm = custom_target('kernel.elf.disasm',
191 command: [ objdump, '-S', '@INPUT@' ],
192 input: kernel_elf,
193 output: 'kernel.elf.disasm',
194 capture: true,
195 build_by_default: true,
196)
197
198# TODO: Add configuration option for installing debug files
199if false
200 install_files += [[ 'boot', kernel_disasm.full_path(), 'kernel.elf.disasm' ]]
201 install_deps += [ kernel_disasm ]
202endif
Note: See TracBrowser for help on using the repository browser.