Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 1 | #!/bin/sh |
Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 2 | # SPDX-License-Identifier: GPL-2.0 |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 3 | # |
| 4 | # link vmlinux |
| 5 | # |
| 6 | # vmlinux is linked from the objects selected by $(KBUILD_VMLINUX_INIT) and |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 7 | # $(KBUILD_VMLINUX_MAIN) and $(KBUILD_VMLINUX_LIBS). Most are built-in.a files |
Nicholas Piggin | 3a166fc | 2017-06-20 01:52:05 +1000 | [diff] [blame] | 8 | # from top-level directories in the kernel tree, others are specified in |
| 9 | # arch/$(ARCH)/Makefile. Ordering when linking is important, and |
| 10 | # $(KBUILD_VMLINUX_INIT) must be first. $(KBUILD_VMLINUX_LIBS) are archives |
| 11 | # which are linked conditionally (not within --whole-archive), and do not |
| 12 | # require symbol indexes added. |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 13 | # |
| 14 | # vmlinux |
| 15 | # ^ |
| 16 | # | |
| 17 | # +-< $(KBUILD_VMLINUX_INIT) |
| 18 | # | +--< init/version.o + more |
| 19 | # | |
| 20 | # +--< $(KBUILD_VMLINUX_MAIN) |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 21 | # | +--< drivers/built-in.a mm/built-in.a + more |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 22 | # | |
Nicholas Piggin | 3a166fc | 2017-06-20 01:52:05 +1000 | [diff] [blame] | 23 | # +--< $(KBUILD_VMLINUX_LIBS) |
| 24 | # | +--< lib/lib.a + more |
| 25 | # | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 26 | # +-< ${kallsymso} (see description in KALLSYMS section) |
| 27 | # |
| 28 | # vmlinux version (uname -v) cannot be updated during normal |
| 29 | # descending-into-subdirs phase since we do not yet know if we need to |
| 30 | # update vmlinux. |
| 31 | # Therefore this step is delayed until just before final link of vmlinux. |
| 32 | # |
| 33 | # System.map is generated to document addresses of all kernel symbols |
| 34 | |
| 35 | # Error out on error |
| 36 | set -e |
| 37 | |
| 38 | # Nice output in kbuild format |
| 39 | # Will be supressed by "make -s" |
| 40 | info() |
| 41 | { |
| 42 | if [ "${quiet}" != "silent_" ]; then |
| 43 | printf " %-7s %s\n" ${1} ${2} |
| 44 | fi |
| 45 | } |
| 46 | |
Nicholas Piggin | 3a166fc | 2017-06-20 01:52:05 +1000 | [diff] [blame] | 47 | # Thin archive build here makes a final archive with symbol table and indexes |
| 48 | # from vmlinux objects INIT and MAIN, which can be used as input to linker. |
| 49 | # KBUILD_VMLINUX_LIBS archives should already have symbol table and indexes |
| 50 | # added. |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 51 | # |
| 52 | # Traditional incremental style of link does not require this step |
| 53 | # |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 54 | # built-in.a output file |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 55 | # |
| 56 | archive_builtin() |
| 57 | { |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 58 | info AR built-in.a |
| 59 | rm -f built-in.a; |
| 60 | ${AR} rcsTP${KBUILD_ARFLAGS} built-in.a \ |
Nicholas Piggin | 6358d6e | 2018-02-11 00:25:03 +1000 | [diff] [blame] | 61 | ${KBUILD_VMLINUX_INIT} \ |
| 62 | ${KBUILD_VMLINUX_MAIN} |
Sami Tolvanen | 0e0752eb | 2017-11-28 08:48:49 -0800 | [diff] [blame] | 63 | |
| 64 | # rebuild with llvm-ar to update the symbol table |
| 65 | if [ -n "${CONFIG_LTO_CLANG}" ]; then |
| 66 | mv -f built-in.a built-in.a.tmp |
| 67 | ${LLVM_AR} rcsT${KBUILD_ARFLAGS} built-in.a $(${AR} t built-in.a.tmp) |
| 68 | rm -f built-in.a.tmp |
| 69 | fi |
| 70 | } |
| 71 | |
Sami Tolvanen | 93185a9 | 2017-12-08 15:49:24 -0800 | [diff] [blame] | 72 | # If CONFIG_LTO_CLANG is selected, generate a linker script to ensure correct |
| 73 | # ordering of initcalls, and with CONFIG_MODVERSIONS also enabled, collect the |
| 74 | # previously generated symbol versions into the same script. |
| 75 | lto_lds() |
Sami Tolvanen | 0e0752eb | 2017-11-28 08:48:49 -0800 | [diff] [blame] | 76 | { |
| 77 | if [ -z "${CONFIG_LTO_CLANG}" ]; then |
| 78 | return |
| 79 | fi |
| 80 | |
Sami Tolvanen | 93185a9 | 2017-12-08 15:49:24 -0800 | [diff] [blame] | 81 | ${srctree}/scripts/generate_initcall_order.pl \ |
| 82 | built-in.a ${KBUILD_VMLINUX_LIBS} \ |
| 83 | > .tmp_lto.lds |
| 84 | |
| 85 | if [ -n "${CONFIG_MODVERSIONS}" ]; then |
| 86 | for a in built-in.a ${KBUILD_VMLINUX_LIBS}; do |
| 87 | for o in $(${AR} t $a); do |
| 88 | if [ -f ${o}.symversions ]; then |
| 89 | cat ${o}.symversions >> .tmp_lto.lds |
| 90 | fi |
| 91 | done |
| 92 | done |
Sami Tolvanen | 0e0752eb | 2017-11-28 08:48:49 -0800 | [diff] [blame] | 93 | fi |
| 94 | |
Sami Tolvanen | 93185a9 | 2017-12-08 15:49:24 -0800 | [diff] [blame] | 95 | echo "-T .tmp_lto.lds" |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 96 | } |
| 97 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 98 | # Link of vmlinux.o used for section mismatch analysis |
| 99 | # ${1} output file |
| 100 | modpost_link() |
| 101 | { |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 102 | local objects |
| 103 | |
Nicholas Piggin | 6358d6e | 2018-02-11 00:25:03 +1000 | [diff] [blame] | 104 | objects="--whole-archive \ |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 105 | built-in.a \ |
Nicholas Piggin | 6358d6e | 2018-02-11 00:25:03 +1000 | [diff] [blame] | 106 | --no-whole-archive \ |
| 107 | --start-group \ |
| 108 | ${KBUILD_VMLINUX_LIBS} \ |
| 109 | --end-group" |
| 110 | |
Sami Tolvanen | 0e0752eb | 2017-11-28 08:48:49 -0800 | [diff] [blame] | 111 | if [ -n "${CONFIG_LTO_CLANG}" ]; then |
| 112 | # This might take a while, so indicate that we're doing |
| 113 | # an LTO link |
| 114 | info LTO vmlinux.o |
| 115 | fi |
| 116 | |
Sami Tolvanen | 93185a9 | 2017-12-08 15:49:24 -0800 | [diff] [blame] | 117 | ${LD} ${KBUILD_LDFLAGS} -r -o ${1} $(lto_lds) ${objects} |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Sami Tolvanen | c274f83 | 2019-05-08 13:22:12 -0700 | [diff] [blame] | 120 | # If CONFIG_LTO_CLANG is selected, we postpone running recordmcount until |
| 121 | # we have compiled LLVM IR to an object file. |
| 122 | recordmcount() |
| 123 | { |
| 124 | if [ -z "${CONFIG_LTO_CLANG}" ]; then |
| 125 | return |
| 126 | fi |
| 127 | |
| 128 | if [ -n "${CONFIG_FTRACE_MCOUNT_RECORD}" ]; then |
| 129 | scripts/recordmcount ${RECORDMCOUNT_FLAGS} $* |
| 130 | fi |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | # Link of vmlinux |
| 134 | # ${1} - optional extra .o files |
| 135 | # ${2} - output file |
| 136 | vmlinux_link() |
| 137 | { |
| 138 | local lds="${objtree}/${KBUILD_LDS}" |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 139 | local objects |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 140 | |
| 141 | if [ "${SRCARCH}" != "um" ]; then |
Sami Tolvanen | 0e0752eb | 2017-11-28 08:48:49 -0800 | [diff] [blame] | 142 | if [ -z "${CONFIG_LTO_CLANG}" ]; then |
| 143 | objects="--whole-archive \ |
| 144 | built-in.a \ |
| 145 | --no-whole-archive \ |
| 146 | --start-group \ |
| 147 | ${KBUILD_VMLINUX_LIBS} \ |
| 148 | --end-group \ |
| 149 | ${1}" |
| 150 | else |
| 151 | objects="--start-group \ |
| 152 | vmlinux.o \ |
| 153 | --end-group \ |
| 154 | ${1}" |
| 155 | fi |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 156 | |
Masahiro Yamada | d503ac5 | 2018-08-24 08:20:39 +0900 | [diff] [blame] | 157 | ${LD} ${KBUILD_LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 158 | -T ${lds} ${objects} |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 159 | else |
Nicholas Piggin | 6358d6e | 2018-02-11 00:25:03 +1000 | [diff] [blame] | 160 | objects="-Wl,--whole-archive \ |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 161 | built-in.a \ |
Nicholas Piggin | 6358d6e | 2018-02-11 00:25:03 +1000 | [diff] [blame] | 162 | -Wl,--no-whole-archive \ |
| 163 | -Wl,--start-group \ |
| 164 | ${KBUILD_VMLINUX_LIBS} \ |
| 165 | -Wl,--end-group \ |
| 166 | ${1}" |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 167 | |
Nicholas Piggin | 6358d6e | 2018-02-11 00:25:03 +1000 | [diff] [blame] | 168 | ${CC} ${CFLAGS_vmlinux} -o ${2} \ |
| 169 | -Wl,-T,${lds} \ |
| 170 | ${objects} \ |
Stephen Rothwell | a5967db | 2016-08-24 22:29:19 +1000 | [diff] [blame] | 171 | -lutil -lrt -lpthread |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 172 | rm -f linux |
| 173 | fi |
| 174 | } |
| 175 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 176 | # Create ${2} .o file with all symbols from the ${1} object file |
| 177 | kallsyms() |
| 178 | { |
| 179 | info KSYM ${2} |
| 180 | local kallsymopt; |
| 181 | |
| 182 | if [ -n "${CONFIG_KALLSYMS_ALL}" ]; then |
James Hogan | 6895f97 | 2012-09-06 22:11:25 +0100 | [diff] [blame] | 183 | kallsymopt="${kallsymopt} --all-symbols" |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 184 | fi |
| 185 | |
Ard Biesheuvel | 4d5d566 | 2016-03-15 14:58:12 -0700 | [diff] [blame] | 186 | if [ -n "${CONFIG_KALLSYMS_ABSOLUTE_PERCPU}" ]; then |
Rusty Russell | c6bda7c | 2014-03-17 14:05:46 +1030 | [diff] [blame] | 187 | kallsymopt="${kallsymopt} --absolute-percpu" |
| 188 | fi |
| 189 | |
Ard Biesheuvel | 2213e9a | 2016-03-15 14:58:19 -0700 | [diff] [blame] | 190 | if [ -n "${CONFIG_KALLSYMS_BASE_RELATIVE}" ]; then |
| 191 | kallsymopt="${kallsymopt} --base-relative" |
| 192 | fi |
| 193 | |
Sam Ravnborg | 00e6c28c | 2012-05-08 19:53:46 +0200 | [diff] [blame] | 194 | local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ |
| 195 | ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}" |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 196 | |
Ard Biesheuvel | a043934 | 2016-02-05 11:25:05 +0100 | [diff] [blame] | 197 | local afile="`basename ${2} .o`.S" |
| 198 | |
| 199 | ${NM} -n ${1} | scripts/kallsyms ${kallsymopt} > ${afile} |
| 200 | ${CC} ${aflags} -c -o ${2} ${afile} |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Preeti Nagar | f097e72 | 2019-04-30 15:07:27 +0530 | [diff] [blame] | 203 | # Generates ${2} .o file with RTIC MP's from the ${1} object file (vmlinux) |
| 204 | # ${3} the file name where the sizes of the RTIC MP structure are stored |
| 205 | # just in case, save copy of the RTIC mp to ${4} |
| 206 | # Note: RTIC_MPGEN has to be set if MPGen is available |
| 207 | rtic_mp() |
| 208 | { |
| 209 | # assume that RTIC_MP_O generation may fail |
| 210 | RTIC_MP_O= |
| 211 | |
| 212 | local aflags="${KBUILD_AFLAGS} ${KBUILD_AFLAGS_KERNEL} \ |
| 213 | ${NOSTDINC_FLAGS} ${LINUXINCLUDE} ${KBUILD_CPPFLAGS}" |
| 214 | |
| 215 | ${RTIC_MPGEN} --objcopy="${OBJCOPY}" --objdump="${OBJDUMP}" \ |
| 216 | --binpath='' --vmlinux=${1} --config=${KCONFIG_CONFIG} && \ |
| 217 | cat rtic_mp.c | ${CC} ${aflags} -c -o ${2} -x c - && \ |
| 218 | cp rtic_mp.c ${4} && \ |
| 219 | ${NM} --print-size --size-sort ${2} > ${3} && \ |
| 220 | RTIC_MP_O=${2} || echo “RTIC MP generation has failed” |
| 221 | # NM - save generated variable sizes for verification |
| 222 | # RTIC_MP_O is our retval - great success if set to generated .o file |
| 223 | # Echo statement above prints the error message in case any of the |
| 224 | # above RTIC MP generation commands fail and it ensures rtic mp failure |
| 225 | # does not cause kernel compilation to fail. |
| 226 | } |
| 227 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 228 | # Create map file with all symbols from ${1} |
| 229 | # See mksymap for additional details |
| 230 | mksysmap() |
| 231 | { |
| 232 | ${CONFIG_SHELL} "${srctree}/scripts/mksysmap" ${1} ${2} |
| 233 | } |
| 234 | |
Linus Torvalds | 1347a2ce | 2012-05-28 10:32:28 -0700 | [diff] [blame] | 235 | sortextable() |
| 236 | { |
| 237 | ${objtree}/scripts/sortextable ${1} |
| 238 | } |
| 239 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 240 | # Delete output files in case of error |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 241 | cleanup() |
| 242 | { |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 243 | rm -f .tmp_System.map |
| 244 | rm -f .tmp_kallsyms* |
Sami Tolvanen | 93185a9 | 2017-12-08 15:49:24 -0800 | [diff] [blame] | 245 | rm -f .tmp_lto.lds |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 246 | rm -f .tmp_vmlinux* |
Nicholas Piggin | f49821e | 2018-02-11 00:25:04 +1000 | [diff] [blame] | 247 | rm -f built-in.a |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 248 | rm -f System.map |
| 249 | rm -f vmlinux |
| 250 | rm -f vmlinux.o |
Preeti Nagar | f097e72 | 2019-04-30 15:07:27 +0530 | [diff] [blame] | 251 | rm -f .tmp_rtic_mp_sz* |
| 252 | rm -f rtic_mp.* |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Sylvain BERTRAND | ab160db | 2015-05-07 00:36:04 +0000 | [diff] [blame] | 255 | on_exit() |
| 256 | { |
| 257 | if [ $? -ne 0 ]; then |
| 258 | cleanup |
| 259 | fi |
| 260 | } |
| 261 | trap on_exit EXIT |
| 262 | |
| 263 | on_signals() |
| 264 | { |
| 265 | exit 1 |
| 266 | } |
| 267 | trap on_signals HUP INT QUIT TERM |
| 268 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 269 | # |
| 270 | # |
| 271 | # Use "make V=1" to debug this script |
| 272 | case "${KBUILD_VERBOSE}" in |
| 273 | *1*) |
| 274 | set -x |
| 275 | ;; |
| 276 | esac |
| 277 | |
| 278 | if [ "$1" = "clean" ]; then |
| 279 | cleanup |
| 280 | exit 0 |
| 281 | fi |
| 282 | |
| 283 | # We need access to CONFIG_ symbols |
Michal Marek | 423a815 | 2013-02-25 13:47:53 +0100 | [diff] [blame] | 284 | case "${KCONFIG_CONFIG}" in |
| 285 | */*) |
| 286 | . "${KCONFIG_CONFIG}" |
| 287 | ;; |
| 288 | *) |
| 289 | # Force using a file from the current directory |
| 290 | . "./${KCONFIG_CONFIG}" |
| 291 | esac |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 292 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 293 | # Update version |
| 294 | info GEN .version |
Masahiro Yamada | 278ae60 | 2017-09-22 14:31:13 +0900 | [diff] [blame] | 295 | if [ -r .version ]; then |
| 296 | VERSION=$(expr 0$(cat .version) + 1) |
| 297 | echo $VERSION > .version |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 298 | else |
Masahiro Yamada | 278ae60 | 2017-09-22 14:31:13 +0900 | [diff] [blame] | 299 | rm -f .version |
| 300 | echo 1 > .version |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 301 | fi; |
| 302 | |
| 303 | # final build of init/ |
Cao jin | a7b151f | 2018-02-21 12:25:07 +0800 | [diff] [blame] | 304 | ${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 305 | |
Nicholas Piggin | abac4c8 | 2016-11-24 03:41:43 +1100 | [diff] [blame] | 306 | archive_builtin |
| 307 | |
| 308 | #link vmlinux.o |
Nicholas Piggin | abac4c8 | 2016-11-24 03:41:43 +1100 | [diff] [blame] | 309 | modpost_link vmlinux.o |
| 310 | |
| 311 | # modpost vmlinux.o to check for section mismatches |
| 312 | ${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o |
| 313 | |
Sami Tolvanen | c274f83 | 2019-05-08 13:22:12 -0700 | [diff] [blame] | 314 | if [ -n "${CONFIG_LTO_CLANG}" ]; then |
| 315 | # Call recordmcount if needed |
| 316 | recordmcount vmlinux.o |
| 317 | fi |
| 318 | |
Preeti Nagar | f097e72 | 2019-04-30 15:07:27 +0530 | [diff] [blame] | 319 | # Generate RTIC MP placeholder compile unit of the correct size |
| 320 | # and add it to the list of link objects |
| 321 | # this needs to be done before generating kallsyms |
| 322 | if [ ! -z ${RTIC_MPGEN+x} ]; then |
| 323 | rtic_mp vmlinux.o rtic_mp.o .tmp_rtic_mp_sz1 .tmp_rtic_mp1.c |
| 324 | KBUILD_VMLINUX_LIBS+=" " |
| 325 | KBUILD_VMLINUX_LIBS+=$RTIC_MP_O |
| 326 | fi |
| 327 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 328 | kallsymso="" |
| 329 | kallsyms_vmlinux="" |
| 330 | if [ -n "${CONFIG_KALLSYMS}" ]; then |
| 331 | |
| 332 | # kallsyms support |
| 333 | # Generate section listing all symbols and add it into vmlinux |
| 334 | # It's a three step process: |
| 335 | # 1) Link .tmp_vmlinux1 so it has all symbols and sections, |
| 336 | # but __kallsyms is empty. |
| 337 | # Running kallsyms on that gives us .tmp_kallsyms1.o with |
| 338 | # the right size |
| 339 | # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of |
| 340 | # the right size, but due to the added section, some |
| 341 | # addresses have shifted. |
| 342 | # From here, we generate a correct .tmp_kallsyms2.o |
Nicholas Piggin | 7e2b37c | 2016-11-24 03:41:37 +1100 | [diff] [blame] | 343 | # 3) That link may have expanded the kernel image enough that |
| 344 | # more linker branch stubs / trampolines had to be added, which |
| 345 | # introduces new names, which further expands kallsyms. Do another |
| 346 | # pass if that is the case. In theory it's possible this results |
| 347 | # in even more stubs, but unlikely. |
| 348 | # KALLSYMS_EXTRA_PASS=1 may also used to debug or work around |
| 349 | # other bugs. |
| 350 | # 4) The correct ${kallsymso} is linked into the final vmlinux. |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 351 | # |
| 352 | # a) Verify that the System.map from vmlinux matches the map from |
| 353 | # ${kallsymso}. |
| 354 | |
| 355 | kallsymso=.tmp_kallsyms2.o |
| 356 | kallsyms_vmlinux=.tmp_vmlinux2 |
| 357 | |
| 358 | # step 1 |
| 359 | vmlinux_link "" .tmp_vmlinux1 |
| 360 | kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o |
| 361 | |
| 362 | # step 2 |
| 363 | vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2 |
| 364 | kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o |
| 365 | |
Nicholas Piggin | 7e2b37c | 2016-11-24 03:41:37 +1100 | [diff] [blame] | 366 | # step 3 |
Michael Forney | a670b0b | 2018-03-18 17:54:02 -0700 | [diff] [blame] | 367 | size1=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms1.o) |
| 368 | size2=$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" .tmp_kallsyms2.o) |
Nicholas Piggin | 7e2b37c | 2016-11-24 03:41:37 +1100 | [diff] [blame] | 369 | |
| 370 | if [ $size1 -ne $size2 ] || [ -n "${KALLSYMS_EXTRA_PASS}" ]; then |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 371 | kallsymso=.tmp_kallsyms3.o |
| 372 | kallsyms_vmlinux=.tmp_vmlinux3 |
| 373 | |
| 374 | vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3 |
| 375 | |
| 376 | kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o |
| 377 | fi |
| 378 | fi |
| 379 | |
Preeti Nagar | f097e72 | 2019-04-30 15:07:27 +0530 | [diff] [blame] | 380 | # Update RTIC MP object by replacing the place holder |
| 381 | # with actual MP data of the same size |
| 382 | # Also double check that object size did not change |
| 383 | # Note: Check initilally if RTIC_MP_O is not empty or uninitialized, |
| 384 | # as incase RTIC_MPGEN is set and failure occurs in RTIC_MP_O |
| 385 | # generation, below check for comparing object sizes fails |
| 386 | # due to an empty RTIC_MP_O object. |
| 387 | if [ ! -z ${RTIC_MP_O} ]; then |
| 388 | rtic_mp "${kallsyms_vmlinux}" rtic_mp.o .tmp_rtic_mp_sz2 \ |
| 389 | .tmp_rtic_mp2.c |
| 390 | if ! cmp -s .tmp_rtic_mp_sz1 .tmp_rtic_mp_sz2; then |
| 391 | echo >&2 'ERROR: RTIC MP object files size mismatch' |
| 392 | exit 1 |
| 393 | fi |
| 394 | fi |
| 395 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 396 | info LD vmlinux |
| 397 | vmlinux_link "${kallsymso}" vmlinux |
| 398 | |
Linus Torvalds | 1347a2ce | 2012-05-28 10:32:28 -0700 | [diff] [blame] | 399 | if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then |
| 400 | info SORTEX vmlinux |
| 401 | sortextable vmlinux |
| 402 | fi |
| 403 | |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 404 | info SYSMAP System.map |
| 405 | mksysmap vmlinux System.map |
| 406 | |
| 407 | # step a (see comment above) |
| 408 | if [ -n "${CONFIG_KALLSYMS}" ]; then |
| 409 | mksysmap ${kallsyms_vmlinux} .tmp_System.map |
| 410 | |
| 411 | if ! cmp -s System.map .tmp_System.map; then |
Michal Marek | 5369f55 | 2012-07-07 23:04:40 +0200 | [diff] [blame] | 412 | echo >&2 Inconsistent kallsyms data |
Michal Marek | 367e43c | 2012-08-10 11:55:11 +0200 | [diff] [blame] | 413 | echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround |
Sam Ravnborg | 1f2bfbd | 2012-05-05 10:18:41 +0200 | [diff] [blame] | 414 | exit 1 |
| 415 | fi |
| 416 | fi |
James Shao | 6fe790c | 2019-08-16 16:04:16 -0700 | [diff] [blame] | 417 | |
| 418 | # Starting Android Q, the DTB's are part of dtb.img and not part |
| 419 | # of the kernel image. RTIC DTS relies on the kernel environment |
| 420 | # and could not build outside of the kernel. Generate RTIC DTS after |
| 421 | # successful kernel build if MPGen is enabled. The DTB will be |
| 422 | # generated with dtb.img in kernel_definitions.mk. |
| 423 | if [ ! -z ${RTIC_MPGEN+x} ]; then |
| 424 | ${RTIC_MPGEN} --objcopy="${OBJCOPY}" --objdump="${OBJDUMP}" \ |
| 425 | --binpath="" --vmlinux="vmlinux" --config=${KCONFIG_CONFIG} \ |
Preeti Nagar | c34b1ec | 2019-10-01 12:44:46 +0530 | [diff] [blame] | 426 | --cc="${CC} ${KBUILD_AFLAGS}" --dts=rtic_mp.dts \ |
| 427 | || echo “RTIC MP DTS generation has failed” |
| 428 | # Echo statement above prints the error message in case above |
| 429 | # RTIC MP DTS generation command fails and it ensures rtic mp |
| 430 | # failure does not cause kernel compilation to fail. |
James Shao | 6fe790c | 2019-08-16 16:04:16 -0700 | [diff] [blame] | 431 | fi |