blob: dd770fe49db98bbd25341ea5ab5ce4b7a77150da [file] [log] [blame]
Kevin O'Connor202024a2009-01-17 10:41:28 -05001#!/usr/bin/env python
Kevin O'Connor5b8f8092009-09-20 19:47:45 -04002# Script to analyze code and arrange ld sections.
Kevin O'Connor202024a2009-01-17 10:41:28 -05003#
Kevin O'Connorab482e02014-06-11 14:00:21 -04004# Copyright (C) 2008-2014 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor202024a2009-01-17 10:41:28 -05005#
6# This file may be distributed under the terms of the GNU GPLv3 license.
7
Johannes Krampf0a82fc72014-01-12 11:39:57 -05008import operator
Kevin O'Connor202024a2009-01-17 10:41:28 -05009import sys
10
Kevin O'Connor5b8f8092009-09-20 19:47:45 -040011# LD script headers/trailers
12COMMONHEADER = """
Kevin O'Connorffc06872014-06-11 15:40:04 -040013/* DO NOT EDIT! This is an autogenerated file. See scripts/layoutrom.py. */
Kevin O'Connor5b8f8092009-09-20 19:47:45 -040014OUTPUT_FORMAT("elf32-i386")
15OUTPUT_ARCH("i386")
16SECTIONS
17{
18"""
19COMMONTRAILER = """
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040020
21 /* Discard regular data sections to force a link error if
22 * code attempts to access data not marked with VAR16 (or other
23 * appropriate macro)
24 */
25 /DISCARD/ : {
26 *(.text*) *(.data*) *(.bss*) *(.rodata*)
Kevin O'Connor90ebed42012-06-21 20:54:53 -040027 *(COMMON) *(.discard*) *(.eh_frame) *(.note*)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040028 }
Kevin O'Connor5b8f8092009-09-20 19:47:45 -040029}
30"""
31
Kevin O'Connorc0693942009-06-10 21:56:01 -040032
33######################################################################
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040034# Determine section locations
Kevin O'Connorc0693942009-06-10 21:56:01 -040035######################################################################
36
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040037# Align 'pos' to 'alignbytes' offset
38def alignpos(pos, alignbytes):
39 mask = alignbytes - 1
40 return (pos + mask) & ~mask
41
42# Determine the final addresses for a list of sections that end at an
Kevin O'Connor5b8f8092009-09-20 19:47:45 -040043# address.
Kevin O'Connor46b82622012-05-13 12:10:30 -040044def setSectionsStart(sections, endaddr, minalign=1, segoffset=0):
Kevin O'Connor5b8f8092009-09-20 19:47:45 -040045 totspace = 0
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040046 for section in sections:
47 if section.align > minalign:
48 minalign = section.align
49 totspace = alignpos(totspace, section.align) + section.size
Johannes Krampf9d7d0442014-01-12 11:19:22 -050050 startaddr = int((endaddr - totspace) / minalign) * minalign
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040051 curaddr = startaddr
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040052 for section in sections:
53 curaddr = alignpos(curaddr, section.align)
54 section.finalloc = curaddr
Kevin O'Connor46b82622012-05-13 12:10:30 -040055 section.finalsegloc = curaddr - segoffset
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040056 curaddr += section.size
Kevin O'Connor46b82622012-05-13 12:10:30 -040057 return startaddr, minalign
Kevin O'Connorc0693942009-06-10 21:56:01 -040058
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040059# The 16bit code can't exceed 64K of space.
60BUILD_BIOS_ADDR = 0xf0000
61BUILD_BIOS_SIZE = 0x10000
Kevin O'Connor46b82622012-05-13 12:10:30 -040062BUILD_ROM_START = 0xc0000
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -040063BUILD_LOWRAM_END = 0xa0000
Kevin O'Connor6d152642013-02-19 21:35:20 -050064# Space to reserve in f-segment for dynamic allocations
65BUILD_MIN_BIOSTABLE = 2048
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040066
67# Layout the 16bit code. This ensures sections with fixed offset
68# requirements are placed in the correct location. It also places the
69# 16bit code as high as possible in the f-segment.
70def fitSections(sections, fillsections):
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040071 # fixedsections = [(addr, section), ...]
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040072 fixedsections = []
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040073 for section in sections:
74 if section.name.startswith('.fixedaddr.'):
75 addr = int(section.name[11:], 16)
Kevin O'Connor46b82622012-05-13 12:10:30 -040076 section.finalloc = addr + BUILD_BIOS_ADDR
77 section.finalsegloc = addr
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040078 fixedsections.append((addr, section))
79 if section.align != 1:
Johannes Krampf064fd062014-01-12 11:14:54 -050080 print("Error: Fixed section %s has non-zero alignment (%d)" % (
81 section.name, section.align))
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040082 sys.exit(1)
Johannes Krampf0a82fc72014-01-12 11:39:57 -050083 fixedsections.sort(key=operator.itemgetter(0))
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040084 firstfixed = fixedsections[0][0]
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040085
86 # Find freespace in fixed address area
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040087 # fixedAddr = [(freespace, section), ...]
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040088 fixedAddr = []
89 for i in range(len(fixedsections)):
90 fixedsectioninfo = fixedsections[i]
91 addr, section = fixedsectioninfo
92 if i == len(fixedsections) - 1:
93 nextaddr = BUILD_BIOS_SIZE
94 else:
95 nextaddr = fixedsections[i+1][0]
Kevin O'Connor1a4885e2010-09-15 21:28:31 -040096 avail = nextaddr - addr - section.size
97 fixedAddr.append((avail, section))
Johannes Krampf0a82fc72014-01-12 11:39:57 -050098 fixedAddr.sort(key=operator.itemgetter(0))
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -040099
100 # Attempt to fit other sections into fixed area
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400101 canrelocate = [(section.size, section.align, section.name, section)
102 for section in fillsections]
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400103 canrelocate.sort()
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400104 canrelocate = [section for size, align, name, section in canrelocate]
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400105 totalused = 0
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400106 for freespace, fixedsection in fixedAddr:
Kevin O'Connor46b82622012-05-13 12:10:30 -0400107 addpos = fixedsection.finalsegloc + fixedsection.size
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400108 totalused += fixedsection.size
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400109 nextfixedaddr = addpos + freespace
Johannes Krampf064fd062014-01-12 11:14:54 -0500110# print("Filling section %x uses %d, next=%x, available=%d" % (
111# fixedsection.finalloc, fixedsection.size, nextfixedaddr, freespace))
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400112 while 1:
113 canfit = None
114 for fitsection in canrelocate:
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400115 if addpos + fitsection.size > nextfixedaddr:
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400116 # Can't fit and nothing else will fit.
117 break
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400118 fitnextaddr = alignpos(addpos, fitsection.align) + fitsection.size
Johannes Krampf064fd062014-01-12 11:14:54 -0500119# print("Test %s - %x vs %x" % (
120# fitsection.name, fitnextaddr, nextfixedaddr))
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400121 if fitnextaddr > nextfixedaddr:
122 # This item can't fit.
123 continue
124 canfit = (fitnextaddr, fitsection)
125 if canfit is None:
126 break
127 # Found a section that can fit.
128 fitnextaddr, fitsection = canfit
129 canrelocate.remove(fitsection)
Kevin O'Connor46b82622012-05-13 12:10:30 -0400130 fitsection.finalloc = addpos + BUILD_BIOS_ADDR
131 fitsection.finalsegloc = addpos
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400132 addpos = fitnextaddr
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400133 totalused += fitsection.size
Johannes Krampf064fd062014-01-12 11:14:54 -0500134# print(" Adding %s (size %d align %d) pos=%x avail=%d" % (
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400135# fitsection[2], fitsection[0], fitsection[1]
Johannes Krampf064fd062014-01-12 11:14:54 -0500136# , fitnextaddr, nextfixedaddr - fitnextaddr))
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400137
138 # Report stats
139 total = BUILD_BIOS_SIZE-firstfixed
140 slack = total - totalused
141 print ("Fixed space: 0x%x-0x%x total: %d slack: %d"
142 " Percent slack: %.1f%%" % (
143 firstfixed, BUILD_BIOS_SIZE, total, slack,
144 (float(slack) / total) * 100.0))
145
Kevin O'Connor46b82622012-05-13 12:10:30 -0400146 return firstfixed + BUILD_BIOS_ADDR
147
148# Return the subset of sections with a given category
149def getSectionsCategory(sections, category):
150 return [section for section in sections if section.category == category]
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400151
Kevin O'Connor8216a472014-06-10 17:59:53 -0400152# Return the subset of sections with a given fileid
153def getSectionsFileid(sections, fileid):
154 return [section for section in sections if section.fileid == fileid]
155
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400156# Return the subset of sections with a given name prefix
Kevin O'Connor46b82622012-05-13 12:10:30 -0400157def getSectionsPrefix(sections, prefix):
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400158 return [section for section in sections
Kevin O'Connor46b82622012-05-13 12:10:30 -0400159 if section.name.startswith(prefix)]
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400160
Kevin O'Connor46b82622012-05-13 12:10:30 -0400161# The sections (and associated information) to be placed in output rom
162class LayoutInfo:
Kevin O'Connor8216a472014-06-10 17:59:53 -0400163 sections = None
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500164 genreloc = None
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400165 sec32init_start = sec32init_end = sec32init_align = None
166 sec32low_start = sec32low_end = None
167 zonelow_base = final_sec32low_start = None
Kevin O'Connor6d152642013-02-19 21:35:20 -0500168 zonefseg_start = zonefseg_end = None
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500169 final_readonly_start = None
Kevin O'Connoree952532014-06-09 14:37:23 -0400170 varlowsyms = entrysym = None
Kevin O'Connor46b82622012-05-13 12:10:30 -0400171
172# Determine final memory addresses for sections
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500173def doLayout(sections, config, genreloc):
Kevin O'Connor46b82622012-05-13 12:10:30 -0400174 li = LayoutInfo()
Kevin O'Connor8216a472014-06-10 17:59:53 -0400175 li.sections = sections
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500176 li.genreloc = genreloc
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400177 # Determine 16bit positions
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400178 sections16 = getSectionsCategory(sections, '16')
179 textsections = getSectionsPrefix(sections16, '.text.')
180 rodatasections = getSectionsPrefix(sections16, '.rodata')
181 datasections = getSectionsPrefix(sections16, '.data16.')
Kevin O'Connorab482e02014-06-11 14:00:21 -0400182 fixedsections = getSectionsCategory(sections, 'fixed')
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400183
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400184 firstfixed = fitSections(fixedsections, textsections)
185 remsections = [s for s in textsections+rodatasections+datasections
186 if s.finalloc is None]
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400187 sec16_start, sec16_align = setSectionsStart(
Kevin O'Connor46b82622012-05-13 12:10:30 -0400188 remsections, firstfixed, segoffset=BUILD_BIOS_ADDR)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400189
190 # Determine 32seg positions
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400191 sections32seg = getSectionsCategory(sections, '32seg')
192 textsections = getSectionsPrefix(sections32seg, '.text.')
193 rodatasections = getSectionsPrefix(sections32seg, '.rodata')
194 datasections = getSectionsPrefix(sections32seg, '.data32seg.')
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400195
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400196 sec32seg_start, sec32seg_align = setSectionsStart(
197 textsections + rodatasections + datasections, sec16_start
Kevin O'Connor46b82622012-05-13 12:10:30 -0400198 , segoffset=BUILD_BIOS_ADDR)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400199
Kevin O'Connoreb88bf72014-09-24 15:58:12 -0400200 # Determine 32bit "fseg memory" data positions
201 sections32textfseg = getSectionsCategory(sections, '32textfseg')
202 sec32textfseg_start, sec32textfseg_align = setSectionsStart(
203 sections32textfseg, sec32seg_start, 16)
Kevin O'Connor41953492013-02-18 23:09:01 -0500204
Kevin O'Connoreb88bf72014-09-24 15:58:12 -0400205 sections32fseg = getSectionsCategory(sections, '32fseg')
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400206 sec32fseg_start, sec32fseg_align = setSectionsStart(
Kevin O'Connoreb88bf72014-09-24 15:58:12 -0400207 sections32fseg, sec32textfseg_start, 16
Kevin O'Connor41953492013-02-18 23:09:01 -0500208 , segoffset=BUILD_BIOS_ADDR)
209
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400210 # Determine 32flat runtime positions
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400211 sections32flat = getSectionsCategory(sections, '32flat')
212 textsections = getSectionsPrefix(sections32flat, '.text.')
213 rodatasections = getSectionsPrefix(sections32flat, '.rodata')
214 datasections = getSectionsPrefix(sections32flat, '.data.')
215 bsssections = getSectionsPrefix(sections32flat, '.bss.')
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400216
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400217 sec32flat_start, sec32flat_align = setSectionsStart(
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400218 textsections + rodatasections + datasections + bsssections
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400219 , sec32fseg_start, 16)
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500220
221 # Determine 32flat init positions
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400222 sections32init = getSectionsCategory(sections, '32init')
223 init32_textsections = getSectionsPrefix(sections32init, '.text.')
224 init32_rodatasections = getSectionsPrefix(sections32init, '.rodata')
225 init32_datasections = getSectionsPrefix(sections32init, '.data.')
226 init32_bsssections = getSectionsPrefix(sections32init, '.bss.')
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500227
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400228 sec32init_start, sec32init_align = setSectionsStart(
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500229 init32_textsections + init32_rodatasections
230 + init32_datasections + init32_bsssections
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400231 , sec32flat_start, 16)
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500232
233 # Determine location of ZoneFSeg memory.
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400234 zonefseg_end = sec32flat_start
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500235 if not genreloc:
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400236 zonefseg_end = sec32init_start
237 zonefseg_start = BUILD_BIOS_ADDR
238 if zonefseg_start + BUILD_MIN_BIOSTABLE > zonefseg_end:
Kevin O'Connor6d152642013-02-19 21:35:20 -0500239 # Not enough ZoneFSeg space - force a minimum space.
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400240 zonefseg_end = sec32fseg_start
241 zonefseg_start = zonefseg_end - BUILD_MIN_BIOSTABLE
242 sec32flat_start, sec32flat_align = setSectionsStart(
Kevin O'Connor6d152642013-02-19 21:35:20 -0500243 textsections + rodatasections + datasections + bsssections
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400244 , zonefseg_start, 16)
245 sec32init_start, sec32init_align = setSectionsStart(
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500246 init32_textsections + init32_rodatasections
247 + init32_datasections + init32_bsssections
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400248 , sec32flat_start, 16)
249 li.sec32init_start = sec32init_start
250 li.sec32init_end = sec32flat_start
251 li.sec32init_align = sec32init_align
252 final_readonly_start = min(BUILD_BIOS_ADDR, sec32flat_start)
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500253 if not genreloc:
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400254 final_readonly_start = min(BUILD_BIOS_ADDR, sec32init_start)
255 li.zonefseg_start = zonefseg_start
256 li.zonefseg_end = zonefseg_end
257 li.final_readonly_start = final_readonly_start
Kevin O'Connor46b82622012-05-13 12:10:30 -0400258
259 # Determine "low memory" data positions
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400260 sections32low = getSectionsCategory(sections, '32low')
261 sec32low_end = sec32init_start
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400262 if config.get('CONFIG_MALLOC_UPPERMEMORY'):
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400263 final_sec32low_end = final_readonly_start
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400264 zonelow_base = final_sec32low_end - 64*1024
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400265 zonelow_base = max(BUILD_ROM_START, alignpos(zonelow_base, 2*1024))
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400266 else:
267 final_sec32low_end = BUILD_LOWRAM_END
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400268 zonelow_base = final_sec32low_end - 64*1024
Kevin O'Connor3be89a12013-02-23 16:07:00 -0500269 relocdelta = final_sec32low_end - sec32low_end
Kevin O'Connor46b82622012-05-13 12:10:30 -0400270 li.sec32low_start, li.sec32low_align = setSectionsStart(
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400271 sections32low, sec32low_end, 16
272 , segoffset=zonelow_base - relocdelta)
273 li.sec32low_end = sec32low_end
274 li.zonelow_base = zonelow_base
Kevin O'Connorc91da7a2012-06-08 21:14:19 -0400275 li.final_sec32low_start = li.sec32low_start + relocdelta
Kevin O'Connord1b4f962010-09-15 21:38:16 -0400276
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400277 # Print statistics
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400278 size16 = BUILD_BIOS_ADDR + BUILD_BIOS_SIZE - sec16_start
279 size32seg = sec16_start - sec32seg_start
Kevin O'Connoreb88bf72014-09-24 15:58:12 -0400280 size32textfseg = sec32seg_start - sec32textfseg_start
281 size32fseg = sec32textfseg_start - sec32fseg_start
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400282 size32flat = sec32fseg_start - sec32flat_start
283 size32init = sec32flat_start - sec32init_start
284 sizelow = li.sec32low_end - li.sec32low_start
Johannes Krampf064fd062014-01-12 11:14:54 -0500285 print("16bit size: %d" % size16)
286 print("32bit segmented size: %d" % size32seg)
Kevin O'Connoreb88bf72014-09-24 15:58:12 -0400287 print("32bit flat size: %d" % (size32flat + size32textfseg))
Johannes Krampf064fd062014-01-12 11:14:54 -0500288 print("32bit flat init size: %d" % size32init)
289 print("Lowmem size: %d" % sizelow)
290 print("f-segment var size: %d" % size32fseg)
Kevin O'Connor46b82622012-05-13 12:10:30 -0400291 return li
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400292
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400293
294######################################################################
295# Linker script output
296######################################################################
297
298# Write LD script includes for the given cross references
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500299def outXRefs(sections, useseg=0, exportsyms=[], forcedelta=0):
Kevin O'Connora3c48f52013-02-05 22:36:13 -0500300 xrefs = dict([(symbol.name, symbol) for symbol in exportsyms])
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400301 out = ""
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400302 for section in sections:
303 for reloc in section.relocs:
304 symbol = reloc.symbol
Kevin O'Connora3c48f52013-02-05 22:36:13 -0500305 if (symbol.section is not None
306 and (symbol.section.fileid != section.fileid
307 or symbol.name != reloc.symbolname)):
308 xrefs[reloc.symbolname] = symbol
309 for symbolname, symbol in xrefs.items():
310 loc = symbol.section.finalloc
311 if useseg:
312 loc = symbol.section.finalsegloc
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500313 out += "%s = 0x%x ;\n" % (symbolname, loc + forcedelta + symbol.offset)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400314 return out
315
Kevin O'Connore5749972014-06-07 15:55:00 -0400316# Write LD script includes for the given sections
317def outSections(sections, useseg=0):
318 out = ""
319 for section in sections:
320 loc = section.finalloc
321 if useseg:
322 loc = section.finalsegloc
323 out += "%s 0x%x : { *(%s) }\n" % (section.name, loc, section.name)
324 return out
325
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400326# Write LD script includes for the given sections using relative offsets
Kevin O'Connor46b82622012-05-13 12:10:30 -0400327def outRelSections(sections, startsym, useseg=0):
328 sections = [(section.finalloc, section) for section in sections
329 if section.finalloc is not None]
Johannes Krampf0a82fc72014-01-12 11:39:57 -0500330 sections.sort(key=operator.itemgetter(0))
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400331 out = ""
Kevin O'Connor46b82622012-05-13 12:10:30 -0400332 for addr, section in sections:
333 loc = section.finalloc
334 if useseg:
335 loc = section.finalsegloc
336 out += ". = ( 0x%x - %s ) ;\n" % (loc, startsym)
Kevin O'Connore5749972014-06-07 15:55:00 -0400337 if section.name in ('.rodata.str1.1', '.rodata'):
338 out += "_rodata%s = . ;\n" % (section.fileid,)
339 out += "*%s.*(%s)\n" % (section.fileid, section.name)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400340 return out
341
Kevin O'Connor46b82622012-05-13 12:10:30 -0400342# Build linker script output for a list of relocations.
343def strRelocs(outname, outrel, relocs):
344 relocs.sort()
345 return (" %s_start = ABSOLUTE(.) ;\n" % (outname,)
346 + "".join(["LONG(0x%x - %s)\n" % (pos, outrel)
347 for pos in relocs])
348 + " %s_end = ABSOLUTE(.) ;\n" % (outname,))
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500349
Kevin O'Connorb40016f2014-06-11 14:40:45 -0400350# Find relocations to the given sections
351def getRelocs(sections, tosection, type=None):
352 return [section.finalloc + reloc.offset
353 for section in sections
354 for reloc in section.relocs
355 if (reloc.symbol.section in tosection
356 and (type is None or reloc.type == type))]
Kevin O'Connor46b82622012-05-13 12:10:30 -0400357
Kevin O'Connor46b82622012-05-13 12:10:30 -0400358# Output the linker scripts for all required sections.
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500359def writeLinkerScripts(li, out16, out32seg, out32flat):
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400360 # Write 16bit linker script
Kevin O'Connor8216a472014-06-10 17:59:53 -0400361 filesections16 = getSectionsFileid(li.sections, '16')
362 out = outXRefs(filesections16, useseg=1) + """
Kevin O'Connorc9243442013-02-17 13:58:28 -0500363 zonelow_base = 0x%x ;
364 _zonelow_seg = 0x%x ;
Kevin O'Connor46b82622012-05-13 12:10:30 -0400365
Kevin O'Connor46b82622012-05-13 12:10:30 -0400366%s
Kevin O'Connorc9243442013-02-17 13:58:28 -0500367""" % (li.zonelow_base,
Johannes Krampf9d7d0442014-01-12 11:19:22 -0500368 int(li.zonelow_base / 16),
Kevin O'Connor8216a472014-06-10 17:59:53 -0400369 outSections(filesections16, useseg=1))
Johannes Krampf19f789b2014-01-19 16:03:49 +0100370 outfile = open(out16, 'w')
Kevin O'Connor46b82622012-05-13 12:10:30 -0400371 outfile.write(COMMONHEADER + out + COMMONTRAILER)
372 outfile.close()
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500373
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400374 # Write 32seg linker script
Kevin O'Connor8216a472014-06-10 17:59:53 -0400375 filesections32seg = getSectionsFileid(li.sections, '32seg')
376 out = (outXRefs(filesections32seg, useseg=1)
377 + outSections(filesections32seg, useseg=1))
Johannes Krampf19f789b2014-01-19 16:03:49 +0100378 outfile = open(out32seg, 'w')
Kevin O'Connor46b82622012-05-13 12:10:30 -0400379 outfile.write(COMMONHEADER + out + COMMONTRAILER)
380 outfile.close()
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500381
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400382 # Write 32flat linker script
Kevin O'Connor46b82622012-05-13 12:10:30 -0400383 sec32all_start = li.sec32low_start
Kevin O'Connor402fd9c2010-09-15 00:26:19 -0400384 relocstr = ""
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500385 if li.genreloc:
Kevin O'Connor402fd9c2010-09-15 00:26:19 -0400386 # Generate relocations
Kevin O'Connor8216a472014-06-10 17:59:53 -0400387 initsections = dict([
388 (s, 1) for s in getSectionsCategory(li.sections, '32init')])
389 noninitsections = dict([(s, 1) for s in li.sections
390 if s not in initsections])
Kevin O'Connorb40016f2014-06-11 14:40:45 -0400391 absrelocs = getRelocs(initsections, initsections, type='R_386_32')
392 relrelocs = getRelocs(initsections, noninitsections, type='R_386_PC32')
393 initrelocs = getRelocs(noninitsections, initsections)
Kevin O'Connor46b82622012-05-13 12:10:30 -0400394 relocstr = (strRelocs("_reloc_abs", "code32init_start", absrelocs)
395 + strRelocs("_reloc_rel", "code32init_start", relrelocs)
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500396 + strRelocs("_reloc_init", "code32flat_start", initrelocs))
397 numrelocs = len(absrelocs + relrelocs + initrelocs)
Kevin O'Connor46b82622012-05-13 12:10:30 -0400398 sec32all_start -= numrelocs * 4
Kevin O'Connor8216a472014-06-10 17:59:53 -0400399 filesections32flat = getSectionsFileid(li.sections, '32flat')
400 out = outXRefs([], exportsyms=li.varlowsyms
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500401 , forcedelta=li.final_sec32low_start-li.sec32low_start)
Kevin O'Connor8216a472014-06-10 17:59:53 -0400402 out += outXRefs(filesections32flat, exportsyms=[li.entrysym]) + """
Kevin O'Connor402fd9c2010-09-15 00:26:19 -0400403 _reloc_min_align = 0x%x ;
Kevin O'Connor6d152642013-02-19 21:35:20 -0500404 zonefseg_start = 0x%x ;
405 zonefseg_end = 0x%x ;
Kevin O'Connorc9243442013-02-17 13:58:28 -0500406 zonelow_base = 0x%x ;
407 final_varlow_start = 0x%x ;
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500408 final_readonly_start = 0x%x ;
Kevin O'Connor8216a472014-06-10 17:59:53 -0400409 varlow_start = 0x%x ;
410 varlow_end = 0x%x ;
411 code32init_start = 0x%x ;
412 code32init_end = 0x%x ;
Kevin O'Connor46b82622012-05-13 12:10:30 -0400413
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400414 code32flat_start = 0x%x ;
415 .text code32flat_start : {
Kevin O'Connor46b82622012-05-13 12:10:30 -0400416%s
Kevin O'Connor46b82622012-05-13 12:10:30 -0400417%s
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400418 code32flat_end = ABSOLUTE(.) ;
419 } :text
Kevin O'Connora3c48f52013-02-05 22:36:13 -0500420""" % (li.sec32init_align,
Kevin O'Connor6d152642013-02-19 21:35:20 -0500421 li.zonefseg_start,
422 li.zonefseg_end,
Kevin O'Connorc9243442013-02-17 13:58:28 -0500423 li.zonelow_base,
Kevin O'Connorc91da7a2012-06-08 21:14:19 -0400424 li.final_sec32low_start,
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500425 li.final_readonly_start,
Kevin O'Connor8216a472014-06-10 17:59:53 -0400426 li.sec32low_start,
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400427 li.sec32low_end,
Kevin O'Connor8216a472014-06-10 17:59:53 -0400428 li.sec32init_start,
Kevin O'Connor38729bc2014-06-11 13:39:02 -0400429 li.sec32init_end,
Kevin O'Connor46b82622012-05-13 12:10:30 -0400430 sec32all_start,
431 relocstr,
Kevin O'Connor8216a472014-06-10 17:59:53 -0400432 outRelSections(li.sections, 'code32flat_start'))
Kevin O'Connor46b82622012-05-13 12:10:30 -0400433 out = COMMONHEADER + out + COMMONTRAILER + """
Kevin O'Connoree952532014-06-09 14:37:23 -0400434ENTRY(%s)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400435PHDRS
436{
437 text PT_LOAD AT ( code32flat_start ) ;
438}
Kevin O'Connoree952532014-06-09 14:37:23 -0400439""" % (li.entrysym.name,)
Johannes Krampf19f789b2014-01-19 16:03:49 +0100440 outfile = open(out32flat, 'w')
Kevin O'Connor46b82622012-05-13 12:10:30 -0400441 outfile.write(out)
442 outfile.close()
Kevin O'Connorc0693942009-06-10 21:56:01 -0400443
444
445######################################################################
Kevin O'Connorbf70fbf2014-06-10 00:00:20 -0400446# Detection of unused sections and init sections
Kevin O'Connord1b4f962010-09-15 21:38:16 -0400447######################################################################
448
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400449# Visit all sections reachable from a given set of start sections
450def findReachable(anchorsections, checkreloc, data):
451 anchorsections = dict([(section, []) for section in anchorsections])
452 pending = list(anchorsections)
453 while pending:
454 section = pending.pop()
455 for reloc in section.relocs:
456 chain = anchorsections[section] + [section.name]
457 if not checkreloc(reloc, section, data, chain):
458 continue
459 nextsection = reloc.symbol.section
460 if nextsection not in anchorsections:
461 anchorsections[nextsection] = chain
462 pending.append(nextsection)
463 return anchorsections
464
Kevin O'Connorbf70fbf2014-06-10 00:00:20 -0400465# Find "runtime" sections (ie, not init only sections).
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400466def checkRuntime(reloc, rsection, data, chain):
467 section = reloc.symbol.section
Kevin O'Connorbf70fbf2014-06-10 00:00:20 -0400468 if section is None or '.init.' in section.name:
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400469 return 0
Kevin O'Connor2af52da2013-03-08 19:36:28 -0500470 if '.data.varinit.' in section.name:
Johannes Krampf064fd062014-01-12 11:14:54 -0500471 print("ERROR: %s is VARVERIFY32INIT but used from %s" % (
472 section.name, chain))
Kevin O'Connor2af52da2013-03-08 19:36:28 -0500473 sys.exit(1)
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400474 return 1
Kevin O'Connord1b4f962010-09-15 21:38:16 -0400475
Kevin O'Connorfdca4182010-01-01 12:46:54 -0500476# Find and keep the section associated with a symbol (if available).
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400477def checkKeepSym(reloc, syms, fileid, isxref):
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500478 symbolname = reloc.symbolname
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400479 mustbecfunc = symbolname.startswith('_cfunc')
480 if mustbecfunc:
481 symprefix = '_cfunc' + fileid + '_'
482 if not symbolname.startswith(symprefix):
483 return 0
484 symbolname = symbolname[len(symprefix):]
485 symbol = syms.get(symbolname)
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400486 if (symbol is None or symbol.section is None
487 or symbol.section.name.startswith('.discard.')):
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400488 return 0
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500489 isdestcfunc = (symbol.section.name.startswith('.text.')
490 and not symbol.section.name.startswith('.text.asm.'))
491 if ((mustbecfunc and not isdestcfunc)
492 or (not mustbecfunc and isdestcfunc and isxref)):
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400493 return 0
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500494
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400495 reloc.symbol = symbol
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400496 return 1
Kevin O'Connorfdca4182010-01-01 12:46:54 -0500497
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400498# Resolve a relocation and check if it should be kept in the final binary.
Kevin O'Connorc228d702014-06-09 14:59:25 -0400499def checkKeep(reloc, section, symbols, chain):
500 ret = checkKeepSym(reloc, symbols[section.fileid], section.fileid, 0)
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400501 if ret:
502 return ret
503 # Not in primary sections - it may be a cross 16/32 reference
504 for fileid in ('16', '32seg', '32flat'):
505 if fileid != section.fileid:
Kevin O'Connorc228d702014-06-09 14:59:25 -0400506 ret = checkKeepSym(reloc, symbols[fileid], fileid, 1)
Kevin O'Connorcc132ab2014-06-09 12:48:13 -0400507 if ret:
508 return ret
509 return 0
Kevin O'Connorc0693942009-06-10 21:56:01 -0400510
Kevin O'Connorc0693942009-06-10 21:56:01 -0400511
512######################################################################
513# Startup and input parsing
514######################################################################
515
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400516class Section:
517 name = size = alignment = fileid = relocs = None
Kevin O'Connorc228d702014-06-09 14:59:25 -0400518 finalloc = finalsegloc = category = None
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400519class Reloc:
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500520 offset = type = symbolname = symbol = None
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400521class Symbol:
522 name = offset = section = None
523
Kevin O'Connorc0693942009-06-10 21:56:01 -0400524# Read in output from objdump
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400525def parseObjDump(file, fileid):
526 # sections = [section, ...]
Kevin O'Connorc0693942009-06-10 21:56:01 -0400527 sections = []
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400528 sectionmap = {}
529 # symbols[symbolname] = symbol
Kevin O'Connorc0693942009-06-10 21:56:01 -0400530 symbols = {}
Kevin O'Connorc0693942009-06-10 21:56:01 -0400531
532 state = None
533 for line in file.readlines():
534 line = line.rstrip()
535 if line == 'Sections:':
536 state = 'section'
537 continue
538 if line == 'SYMBOL TABLE:':
539 state = 'symbol'
540 continue
Kevin O'Connor6c2e7812010-09-13 18:04:02 -0400541 if line.startswith('RELOCATION RECORDS FOR ['):
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400542 sectionname = line[24:-2]
543 if sectionname.startswith('.debug_'):
544 # Skip debugging sections (to reduce parsing time)
545 state = None
546 continue
Kevin O'Connorc0693942009-06-10 21:56:01 -0400547 state = 'reloc'
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400548 relocsection = sectionmap[sectionname]
Kevin O'Connorc0693942009-06-10 21:56:01 -0400549 continue
550
551 if state == 'section':
552 try:
553 idx, name, size, vma, lma, fileoff, align = line.split()
554 if align[:3] != '2**':
555 continue
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400556 section = Section()
557 section.name = name
558 section.size = int(size, 16)
559 section.align = 2**int(align[3:])
560 section.fileid = fileid
561 section.relocs = []
562 sections.append(section)
563 sectionmap[name] = section
564 except ValueError:
Kevin O'Connorc0693942009-06-10 21:56:01 -0400565 pass
566 continue
567 if state == 'symbol':
568 try:
Kevin O'Connor90ebed42012-06-21 20:54:53 -0400569 parts = line[17:].split()
570 if len(parts) == 3:
571 sectionname, size, name = parts
572 elif len(parts) == 4 and parts[2] == '.hidden':
573 sectionname, size, hidden, name = parts
574 else:
575 continue
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400576 symbol = Symbol()
577 symbol.size = int(size, 16)
578 symbol.offset = int(line[:8], 16)
579 symbol.name = name
580 symbol.section = sectionmap.get(sectionname)
581 symbols[name] = symbol
582 except ValueError:
Kevin O'Connorc0693942009-06-10 21:56:01 -0400583 pass
584 continue
585 if state == 'reloc':
586 try:
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400587 off, type, symbolname = line.split()
588 reloc = Reloc()
589 reloc.offset = int(off, 16)
590 reloc.type = type
Kevin O'Connorf3fe3aa2010-12-05 12:38:33 -0500591 reloc.symbolname = symbolname
Kevin O'Connor67863be2010-12-24 10:23:10 -0500592 reloc.symbol = symbols.get(symbolname)
593 if reloc.symbol is None:
594 # Some binutils (2.20.1) give section name instead
595 # of a symbol - create a dummy symbol.
596 reloc.symbol = symbol = Symbol()
597 symbol.size = 0
598 symbol.offset = 0
599 symbol.name = symbolname
600 symbol.section = sectionmap.get(symbolname)
601 symbols[symbolname] = symbol
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400602 relocsection.relocs.append(reloc)
603 except ValueError:
Kevin O'Connorc0693942009-06-10 21:56:01 -0400604 pass
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400605 return sections, symbols
Kevin O'Connorc0693942009-06-10 21:56:01 -0400606
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400607# Parser for constants in simple C header files.
608def scanconfig(file):
Johannes Krampf19f789b2014-01-19 16:03:49 +0100609 f = open(file, 'r')
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400610 opts = {}
611 for l in f.readlines():
612 parts = l.split()
613 if len(parts) != 3:
614 continue
615 if parts[0] != '#define':
616 continue
617 value = parts[2]
618 if value.isdigit() or (value.startswith('0x') and value[2:].isdigit()):
619 value = int(value, 0)
620 opts[parts[1]] = value
621 return opts
622
Kevin O'Connorc0693942009-06-10 21:56:01 -0400623def main():
624 # Get output name
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400625 in16, in32seg, in32flat, cfgfile, out16, out32seg, out32flat = sys.argv[1:]
Kevin O'Connorc0693942009-06-10 21:56:01 -0400626
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400627 # Read in the objdump information
Johannes Krampf19f789b2014-01-19 16:03:49 +0100628 infile16 = open(in16, 'r')
629 infile32seg = open(in32seg, 'r')
630 infile32flat = open(in32flat, 'r')
Kevin O'Connorc0693942009-06-10 21:56:01 -0400631
Kevin O'Connor1a4885e2010-09-15 21:28:31 -0400632 # infoX = (sections, symbols)
633 info16 = parseObjDump(infile16, '16')
634 info32seg = parseObjDump(infile32seg, '32seg')
635 info32flat = parseObjDump(infile32flat, '32flat')
Kevin O'Connorc0693942009-06-10 21:56:01 -0400636
Kevin O'Connor2b0fb8c2013-08-07 23:03:47 -0400637 # Read kconfig config file
638 config = scanconfig(cfgfile)
639
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400640 # Figure out which sections to keep.
Kevin O'Connorc228d702014-06-09 14:59:25 -0400641 allsections = info16[0] + info32seg[0] + info32flat[0]
642 symbols = {'16': info16[1], '32seg': info32seg[1], '32flat': info32flat[1]}
Kevin O'Connoree952532014-06-09 14:37:23 -0400643 if config.get('CONFIG_COREBOOT'):
644 entrysym = symbols['16'].get('entry_elf')
645 elif config.get('CONFIG_CSM'):
646 entrysym = symbols['16'].get('entry_csm')
647 else:
648 entrysym = symbols['16'].get('reset_vector')
649 anchorsections = [entrysym.section] + [
Kevin O'Connorab482e02014-06-11 14:00:21 -0400650 section for section in allsections
Kevin O'Connoree952532014-06-09 14:37:23 -0400651 if section.name.startswith('.fixedaddr.')]
Kevin O'Connorc228d702014-06-09 14:59:25 -0400652 keepsections = findReachable(anchorsections, checkKeep, symbols)
653 sections = [section for section in allsections if section in keepsections]
Kevin O'Connorc0693942009-06-10 21:56:01 -0400654
Kevin O'Connorbf70fbf2014-06-10 00:00:20 -0400655 # Separate 32bit flat into runtime, init, and special variable parts
656 anchorsections = [
657 section for section in sections
658 if ('.data.varlow.' in section.name or '.data.varfseg.' in section.name
Kevin O'Connorab482e02014-06-11 14:00:21 -0400659 or '.fixedaddr.' in section.name or '.runtime.' in section.name)]
Kevin O'Connorbf70fbf2014-06-10 00:00:20 -0400660 runtimesections = findReachable(anchorsections, checkRuntime, None)
661 for section in sections:
662 if section.name.startswith('.data.varlow.'):
663 section.category = '32low'
664 elif section.name.startswith('.data.varfseg.'):
665 section.category = '32fseg'
Kevin O'Connoreb88bf72014-09-24 15:58:12 -0400666 elif section.name.startswith('.text.32fseg.'):
667 section.category = '32textfseg'
Kevin O'Connorab482e02014-06-11 14:00:21 -0400668 elif section.name.startswith('.fixedaddr.'):
669 section.category = 'fixed'
Kevin O'Connorbf70fbf2014-06-10 00:00:20 -0400670 elif section.fileid == '32flat' and section not in runtimesections:
671 section.category = '32init'
672 else:
673 section.category = section.fileid
Kevin O'Connor46b82622012-05-13 12:10:30 -0400674
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400675 # Determine the final memory locations of each kept section.
Kevin O'Connorc228d702014-06-09 14:59:25 -0400676 genreloc = '_reloc_abs_start' in symbols['32flat']
Kevin O'Connorb94170c2013-12-06 13:52:16 -0500677 li = doLayout(sections, config, genreloc)
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400678
Kevin O'Connora3c48f52013-02-05 22:36:13 -0500679 # Exported symbols
Kevin O'Connorc228d702014-06-09 14:59:25 -0400680 li.varlowsyms = [symbol for symbol in symbols['32flat'].values()
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500681 if (symbol.section is not None
682 and symbol.section.finalloc is not None
683 and '.data.varlow.' in symbol.section.name
684 and symbol.name != symbol.section.name)]
Kevin O'Connoree952532014-06-09 14:37:23 -0400685 li.entrysym = entrysym
Kevin O'Connora3c48f52013-02-05 22:36:13 -0500686
Kevin O'Connor9ba1dea2010-05-01 09:50:13 -0400687 # Write out linker script files.
Kevin O'Connor6afc6f82013-02-19 01:02:50 -0500688 writeLinkerScripts(li, out16, out32seg, out32flat)
Kevin O'Connorc0693942009-06-10 21:56:01 -0400689
Kevin O'Connor202024a2009-01-17 10:41:28 -0500690if __name__ == '__main__':
691 main()