Changes in kernel/meson.build [c21d4d6:b169619] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/meson.build

    rc21d4d6 rb169619  
    4242subdir('test')
    4343
    44 ## Cross-platform assembly to start a symtab.data section
    45 #
    46 symtab_section = '.section symtab.data, "a", ' + atsign + 'progbits;'
    47 
    4844kernel_include_dirs = include_directories(
    4945        'generic/include',
     
    5248        '..' / 'abi' / 'arch' / KARCH / 'include',
    5349        '..' / 'abi' / 'include',
     50        '..' / 'common' / 'include',
    5451        'test',
    5552)
     
    8986        '-T', meson.current_build_dir() / '_link.ld',
    9087]
     88# The kernel is built as ELF but then copied as a blob of bytes and
     89# the permissions are not relevant anyway (needed for binutils 2.39+).
     90kernel_link_args += ldflags_ignore_rwx_segments
    9191
    9292if CONFIG_LTO
     
    9494endif
    9595
    96 if CONFIG_STRIP_BINARIES
    97         # TODO: do this after disassembling
    98         kernel_link_args += [ '-s' ]
    99 endif
    100 
    10196kernel_c_args = arch_kernel_c_args + kernel_defs + [
    10297        '-ffreestanding',
    103         # TODO: remove this flag
    104         cc.get_supported_arguments([ '-Wno-cast-function-type' ]),
     98        '-fdebug-prefix-map=../../kernel/=',
     99        '-fdebug-prefix-map=../../../kernel/=',
     100
     101        cc.get_supported_arguments([
     102                # TODO: remove this flag
     103                '-Wno-cast-function-type',
     104
     105                # When accessing specific memory addresses that are below
     106                # normal page size, the compiler may assume that we actually
     107                # dereferenced NULL pointer and warns us about that.
     108                # But in kernel we often need to access these addresses
     109                # directly hence we need to ignore these warnings.
     110                #
     111                # TODO: might make more sense to disable this selectively
     112                # in specific files (or better yet, for specific lines).
     113                '--param=min-pagesize=0',
     114        ]),
    105115]
     116
     117if not CONFIG_LINE_DEBUG
     118        # Keep the debug info needed to get file names for kernel stack traces.
     119        kernel_c_args += [ '-gdwarf-5', '-g1', '-gno-statement-frontiers' ]
     120endif
    106121
    107122if CONFIG_LTO
     
    133148all_kernel_objects = [ instrumentables, noninstrumentables ]
    134149
    135 # We iterate the build several times to get symbol table right.
    136 # Three times is sufficient to get correct even symbols after symtab.
     150kernel_name = 'kernel.elf'
     151kernel_map_name = kernel_name + '.map'
     152kernel_map_path = meson.current_build_dir() / kernel_map_name
     153
     154kernel_elf = executable(kernel_name,
     155        include_directories: kernel_include_dirs,
     156        implicit_include_directories: false,
     157        c_args: kernel_c_args,
     158        link_args: kernel_c_args + kernel_link_args + [
     159                '-Wl,-Map,' + kernel_map_path,
     160        ],
     161        link_depends: kernel_ldscript,
     162        link_whole: all_kernel_objects,
     163        pie: false,
     164)
     165
     166kernel_dbg = custom_target('kernel.dbg',
     167        output: 'kernel.dbg',
     168        input: kernel_elf,
     169        command: [
     170                objcopy,
     171                '--only-keep-debug',
     172                '@INPUT@',
     173                '@OUTPUT@',
     174        ],
     175)
     176
     177kernel_elf_stripped = custom_target(kernel_name + '.stripped',
     178        output: kernel_name + '.stripped',
     179        input: kernel_elf,
     180        command: [
     181                objcopy,
     182                '--strip-unneeded',
     183                '@INPUT@',
     184                '@OUTPUT@',
     185        ],
     186)
     187
     188rd_init_binaries += [[ kernel_elf_stripped, 'boot/kernel.elf' ]]
     189install_files += [[ 'boot', kernel_elf_stripped.full_path(), 'kernel.elf' ]]
     190install_deps += [ kernel_elf_stripped ]
    137191
    138192if CONFIG_SYMTAB
    139         # Iterate build three times.
    140         iterations = [ 1, 2, 3 ]
    141 
    142         # Generates symbol table information as an object file.
    143         genmap = find_program('tools/genmap.py')
    144 
    145         # Symbol table dump needed for genmap.
    146         kernel_syms = custom_target('kernel_syms.txt',
    147                 input: all_kernel_objects,
    148                 output: 'kernel_syms.txt',
    149                 command: [ objdump, '-t', '@INPUT@' ],
    150                 capture: true,
    151         )
    152 else
    153         # Build just once.
    154         iterations = [ 1 ]
    155 endif
    156 
    157 # Empty symbol map for first iteration.
    158 kernel_map_S = custom_target('empty_map.S',
    159         output: 'empty_map.S',
    160         capture: true,
    161         command: [ 'echo', kernel_as_prolog + symtab_section ],
    162 )
    163 
    164 foreach iter : iterations
    165         is_last = (iter == iterations.length())
    166         kernel_name = 'kernel.@0@.elf'.format(iter)
    167         kernel_map_name = kernel_name + '.map'
    168         kernel_map_path = meson.current_build_dir() / kernel_map_name
    169 
    170         kernel_elf = executable(kernel_name, kernel_map_S,
    171                 include_directories: kernel_include_dirs,
    172                 implicit_include_directories: false,
    173                 c_args: kernel_c_args,
    174                 link_args: kernel_c_args + kernel_link_args + [
    175                         '-Wl,-Map,' + kernel_map_path,
    176                 ],
    177                 link_depends: kernel_ldscript,
    178                 link_whole: all_kernel_objects,
    179                 pie: false,
    180         )
    181 
    182         # Generate symbol table if this is not the final iteration.
    183         if not is_last
    184 
    185                 # TODO: Teach kernel to read its own ELF symbol table and get rid of this nonsense.
    186                 # Need to first make sure all architectures (even future ones with dumb bootloaders) can use ELF formatted kernel.
    187 
    188                 kernel_map_bin = custom_target(kernel_map_name + '.bin',
    189                         output: kernel_map_name + '.bin',
    190                         input: [ kernel_elf, kernel_syms ],
    191                         command: [ genmap, kernel_map_path, '@INPUT1@', '@OUTPUT@' ],
    192                 )
    193 
    194                 kernel_map_S_name = kernel_name + '.map.S'
    195 
    196                 kernel_map_S = custom_target(kernel_map_S_name,
    197                         input: kernel_map_bin,
    198                         output: kernel_map_S_name,
    199                         capture: true,
    200                         command: [ 'echo', kernel_as_prolog + symtab_section + ' .incbin "@INPUT@"' ],
    201                 )
    202         endif
    203 endforeach
    204 
    205 rd_init_binaries += [[ kernel_elf, 'boot/kernel.elf' ]]
    206 
    207 install_files += [[ 'boot', kernel_elf.full_path(), 'kernel.elf' ]]
    208 install_deps += [ kernel_elf ]
     193        rd_init_binaries += [[ kernel_dbg, 'kernel.dbg' ]]
     194        install_files += [[ 'boot', kernel_dbg.full_path(), 'kernel.dbg' ]]
     195        install_deps += [ kernel_dbg ]
     196endif
    209197
    210198kernel_disasm = custom_target('kernel.elf.disasm',
Note: See TracChangeset for help on using the changeset viewer.