From: David Woodhouse David.Woodhouse@intel.com
I'm about to introduce some post-processing in checkrom.py which will want access to public symbols. So let's make sure they're defined in the final link even if they're *not* cross-referenced from a different code section.
Signed-off-by: David Woodhouse David.Woodhouse@intel.com --- tools/layoutrom.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/tools/layoutrom.py b/tools/layoutrom.py index 816ff9b..75c49be 100755 --- a/tools/layoutrom.py +++ b/tools/layoutrom.py @@ -248,7 +248,7 @@ def doLayout(sections, genreloc): ######################################################################
# Write LD script includes for the given cross references -def outXRefs(sections, useseg=0): +def outXRefs(sections, useseg=0, exportsyms=[]): xrefs = {} out = "" for section in sections: @@ -264,6 +264,16 @@ def outXRefs(sections, useseg=0): if useseg: loc = symbol.section.finalsegloc out += "%s = 0x%x ;\n" % (reloc.symbolname, loc + symbol.offset) + + for symbol in exportsyms: + if symbol.name in xrefs: + continue + xrefs[symbol.name] = 1 + loc = symbol.section.finalloc + if useseg: + loc = symbol.section.finalsegloc + out += "%s = 0x%x ;\n" % (symbol.name, loc + symbol.offset) + return out
# Write LD script includes for the given sections using relative offsets @@ -310,7 +320,7 @@ def getSectionsStart(sections, defaddr=0): if section.finalloc is not None] or [defaddr])
# Output the linker scripts for all required sections. -def writeLinkerScripts(li, entrysym, genreloc, out16, out32seg, out32flat): +def writeLinkerScripts(li, entrysym, genreloc, exportsyms, out16, out32seg, out32flat): # Write 16bit linker script out = outXRefs(li.sections16, useseg=1) + """ datalow_base = 0x%x ; @@ -361,7 +371,7 @@ def writeLinkerScripts(li, entrysym, genreloc, out16, out32seg, out32flat): + strRelocs("_reloc_datalow", "code32flat_start", lowrelocs)) numrelocs = len(absrelocs + relrelocs + initrelocs + lowrelocs) sec32all_start -= numrelocs * 4 - out = outXRefs(sections32all) + """ + out = outXRefs(sections32all, exportsyms=exportsyms) + """ %s = 0x%x ; _reloc_min_align = 0x%x ; datalow_base = 0x%x ; @@ -518,6 +528,7 @@ def parseObjDump(file, fileid): sectionmap = {} # symbols[symbolname] = symbol symbols = {} + exportsyms = {}
state = None for line in file.readlines(): @@ -569,6 +580,9 @@ def parseObjDump(file, fileid): symbol.name = name symbol.section = sectionmap.get(sectionname) symbols[name] = symbol + if ".export." in sectionname and sectionname != name: + exportsyms[symbol] = symbol + except ValueError: pass continue @@ -592,7 +606,7 @@ def parseObjDump(file, fileid): relocsection.relocs.append(reloc) except ValueError: pass - return sections, symbols + return sections, symbols, exportsyms
def main(): # Get output name @@ -613,6 +627,7 @@ def main():
# Separate 32bit flat into runtime and init parts findInit(sections) + exportsyms = dict(info16[2].items() + info32seg[2].items() + info32flat[2].items())
# Note "low memory" parts for section in getSectionsPrefix(sections, '.datalow.'): @@ -624,7 +639,7 @@ def main():
# Write out linker script files. entrysym = info16[1]['entry_elf'] - writeLinkerScripts(li, entrysym, genreloc, out16, out32seg, out32flat) + writeLinkerScripts(li, entrysym, genreloc, exportsyms, out16, out32seg, out32flat)
if __name__ == '__main__': main()