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


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/meson.build

    rd231a54 rc21d4d6  
    4242subdir('test')
    4343
     44## Cross-platform assembly to start a symtab.data section
     45#
     46symtab_section = '.section symtab.data, "a", ' + atsign + 'progbits;'
     47
    4448kernel_include_dirs = include_directories(
    4549        'generic/include',
     
    4852        '..' / 'abi' / 'arch' / KARCH / 'include',
    4953        '..' / 'abi' / 'include',
    50         '..' / 'common' / 'include',
    5154        'test',
    5255)
     
    8689        '-T', meson.current_build_dir() / '_link.ld',
    8790]
    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+).
    90 kernel_link_args += ldflags_ignore_rwx_segments
    9191
    9292if CONFIG_LTO
     
    9494endif
    9595
     96if CONFIG_STRIP_BINARIES
     97        # TODO: do this after disassembling
     98        kernel_link_args += [ '-s' ]
     99endif
     100
    96101kernel_c_args = arch_kernel_c_args + kernel_defs + [
    97102        '-ffreestanding',
    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         ]),
     103        # TODO: remove this flag
     104        cc.get_supported_arguments([ '-Wno-cast-function-type' ]),
    115105]
    116 
    117 if not CONFIG_LINE_DEBUG
    118         # Keep the debug info needed to get file names for kernel stack traces.
    119         kernel_c_args += cc.get_supported_arguments([ '-gdwarf-5', '-g1', '-gno-statement-frontiers' ])
    120 endif
    121106
    122107if CONFIG_LTO
     
    148133all_kernel_objects = [ instrumentables, noninstrumentables ]
    149134
    150 kernel_name = 'kernel.elf'
    151 kernel_map_name = kernel_name + '.map'
    152 kernel_map_path = meson.current_build_dir() / kernel_map_name
    153 
    154 kernel_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 
    166 kernel_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 
    177 kernel_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 
    188 rd_init_binaries += [[ kernel_elf_stripped, 'boot/kernel.elf' ]]
    189 install_files += [[ 'boot', kernel_elf_stripped.full_path(), 'kernel.elf' ]]
    190 install_deps += [ kernel_elf_stripped ]
     135# We iterate the build several times to get symbol table right.
     136# Three times is sufficient to get correct even symbols after symtab.
    191137
    192138if CONFIG_SYMTAB
    193         rd_init_binaries += [[ kernel_dbg, 'kernel.dbg' ]]
    194         install_files += [[ 'boot', kernel_dbg.full_path(), 'kernel.dbg' ]]
    195         install_deps += [ kernel_dbg ]
    196 endif
     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        )
     152else
     153        # Build just once.
     154        iterations = [ 1 ]
     155endif
     156
     157# Empty symbol map for first iteration.
     158kernel_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
     164foreach 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
     203endforeach
     204
     205rd_init_binaries += [[ kernel_elf, 'boot/kernel.elf' ]]
     206
     207install_files += [[ 'boot', kernel_elf.full_path(), 'kernel.elf' ]]
     208install_deps += [ kernel_elf ]
    197209
    198210kernel_disasm = custom_target('kernel.elf.disasm',
Note: See TracChangeset for help on using the changeset viewer.