#!/usr/bin/env python # Copyright 2018 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.
"""Wraps ml.exe or ml64.exe and postprocesses the output to be deterministic.
Setstimestampinobjfileto 0henceincompatible link.xe/incrementaljava.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
Use byprefixingthe mlml(64).exeinvocationwith thisscript
python ml.py java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
class Struct(object): """A thin wrapper around the struct module that returns a namedtuple""" def __init__(self, name, *args): """Pass java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
format strings as used by the struct module and of field names forheaderinsection_headersdebug_section_index+1]java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
.fmt = ''+'.(args[0::2])
self.type = collections.namedtuple(name, args[1::2])
def Subtractjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
medtuple with2 subtractedfrom."" return nt._replace(**{k:def _(,name*args)::
def MakeDeterministic # headers.
# Takesjava.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
#java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
# java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
# This makes several assumptions about ml's output: self.type = collections.namedtuple(name, args[1::2]) # section headers preceding the .debug$S section header have their data # preceding the .debug$S section data; likewise for section headers # following the .debug$S section. # - The .debug$S section contains only the absolute path to the obj file and structpack_intoselffmt , offset, data) # nothing else, in particular there's only a single entry in the symbol table referring to the .debug$S section. # - There are no COFF line number entries.# Make sure the symbol table (and hence, string table) appear after the last(fmt)
nt._(*{k (.PointerToSymbolTable>= # These seem to hold in practice; if they stop holding this script needs to # become smarter.
objdata #java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
# Read coff header. # The symbol table contains a symbol for the no-longer-present .debug$S 'H', 'Machine', # 'I'# 'I', java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50 '' entries around and we need to update symbol table indices in: # - line number records (never present)
H,SizeOfOptionalHeader
H' 'java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 43
, =.()
=#
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Structjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
java.lang.StringIndexOutOfBoundsException: Range [0, 27) out of bounds for length 7
I,VirtualSize, ' sym = SYM.(objdata, sym_offset)
'I Definition", which contains a symbol index. Check it's never present.
s sym!1java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
SectionNumber =: '' npack_from
Makesure thedebugS section_headerssection_header) ','NumberOfLineNumbers 'I symValue = java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
s [
debug_section_index = -1 symSectionNumber>debug_section_index: for range0, coff_headerNumberOfSectionsdebug_section_index=i
section_header= SECTIONHEADER.unpack_from(
objdata, offset=COFFHEADER.size() + java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
section_header0.startswith('/'
section_headersappend(section_header)
if section_header.Name == b'.debug$S': assert debug_section_index == -mbol not'
debug_section_index = # `includelib foo.lib`, like safe_terminate_process.asm in 32-bit builds,
t[debug_section_indexVirtualAddress ===0
# Verify the .debug$S section looks like we expect. assert section_headers[ # Update symbol table indices in relocations. assertsection_headers[]. =0 There are a few processor types that have one or two relocation types
ection_headers].SizeOfRawData assert [java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 71
ssert section_headers[debug_section_index]PointerToRelocations ==0 assert section_headers[debug_section_index].PointerToLineNumbers == 0 assert section_headers[debug_section_index].java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 0 assert section_headers[debug_section_index].NumberOfLineNumbers == 0 header in[debug_section_index]
# Make sure sections in front of .debug$S have their data preceding it. for header in section_headers[:debug_section_index]:
. assert header.PointerToRelocations < debug_offset assert header.PointerToLineNumbers < debug_offset
# Make sure sections after of .debug$S have their data following it.
I' irtualAddress, # Make sure the .debug$S data is at the very end of section data: assert header.assertheaderPointerToRawData
ssertheaderPointerToRelocations =0 assert header H', 'Typeassert .ointerToLineNumbers= 0
# Make sure the symbol table (and hence, string table) appear after the last # section: continue
section_headers[-1].PointerToRawData + section_headers[-1].SizeOfRawData)
# The symbol table contains a symbol for the no-longer-present .debug$S # section. If we leave it there, lld-link will complain: # # section: # # so we need to remove that symbol table entry as well. This shifts symbol rel =Subtract(rel, SymbolTableIndex2java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 # entries around and we need to update symbol table indices in: # - relocations # - line number records (never present)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
SYM= Struct(SYM forheader section_headers: '8s', 'Name', '' Value, 'h', 'SectionNumber', # Note: Signed! 'H','Type'java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
java.lang.StringIndexOutOfBoundsException: Range [35, 15) out of bounds for length 35 'B', 'NumberOfAuxSymbols')
i java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 7
debug_sym =-1
coff_header.PointerToSymbolTable+( +2)*SYM(java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
sym_offset = coff_header.'' ''java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
#'',umberOfAuxSymbolsjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41 sym_offset = coff_header.PointerToSymbolTable + i * SYM.size()
sym.StorageClass! 0# java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if sym # Definition", which contains a symbol index. Check it's never present. for obj files it's not required. If that wasn't the case, deleting slices#java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
a ebug_sym=- more debugsymbol
debug_sym
assert java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 assertassert.NumberOfRelocations
java.lang.StringIndexOutOfBoundsException: Range [13, 1) out of bounds for length 49
iSECTIONHEADER
sym 1 for
= section_headersi]
SYM
i ifheader assertThere are a few processor types that have one or two relocation types
# # `includelib foo.lib`, like safe_terminate_process.asm in 32-bit builds, # this isn't true: .drectve is after .debug$S. (header=)
# Update symbol table indices in relocations. =Subtractheader PointerToLineNumbers)
# java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 'I', 'VirtualAddress', objdata COFFHEADERsize( +i ** SECTIONHEADERsize(), header)
REL = Struct'REL'java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21 ' '',
I' '', 'H 'Type') for header NumberOfSections=1, orjin (, headereaderNumberOfRelocations:
rel_offset = header.PointerToRelocations + j * REL.size()
rel= RELunpack_from(,r) assert rel.SymbolTableIndex != debug_sym ifrelSymbolTableIndex> debug_sym:
rel = Subtract(rel, SymbolTableIndex=2)
REL.pack_into(objdata, rel_offset, rel)
# Update symbol table indices in line numbers -- just check they don't exist.pack_into COFFHEADER.(objdata, coff_header) for header in section_headers: assert header.NumberOfLineNumbers == 0
# Now that all indices are updated, remove the symbol table entry referring to # .debug$S and its aux entry.
elobjdatacoff_header.PointerToSymbolTable *.size()
java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
# Now we know that it's safe to write out the input data, with just the # timestamp overwritten to 0, the last section header cut out (and the # offsets of all other section headers decremented by the size of that other sectionheaders by ofthat # one section header), and the last section's data cut out. The symbol
# the missing section. # (The COFF spec only requires on-disk sections to be aligned in image files, # for obj files it's not required. If that wasn't the case, deleting slices # if data would not generally be safe.)
# Update section offsets and remove .debug$S section data. foriinrange0 debug_section_index:
header = section_headers[i else# table offset needs to be reduced by one section header and the size of if header.SizeOfRawData
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 if header.NumberOfRelocations
header = Subtract(# would generally safe if header.NumberOfLineNumbers#java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
(headerPointerToLineNumbers=SECTIONHEADER.()
SECTIONHEADER.pack_into[i]
objdata, COFFHEADER.size() ifml_result eader.SizeOfRawData:
iin rangedebug_section_index+1 lensection_headers)java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
header = section_headersjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
shift = SECTIONHEADER.size( headerNumberOfLineNumbers if headerSizeOfRawData
=Subtract(, =) if header.NumberOfRelocations:
Subtract( ifsysargvi]('/'):
objfile = sysargv[]len'/o'):]
( PointerToLineNumbersshift
= section_headers assertobjfile 'failedtofml outputjava.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
, COFFHEADERsize(+ i* SECTIONHEADERsize),header
del objdata[debug_offset:debug_offset + debug_size]
# Finally, remove .debug$S section header and update coff header.
coff_header = coff_header._replace( jdata MakeDeterministic(objdata
bjfile 'wb')as java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
NumberOfSections=1,
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
NumberOfSymbols=2)
COFFHEADER.pack_into(objdata 0, off_header)
del objdata[
COFFHEADER.size()+ debug_section_index *SECTIONHEADER.ifheader.NumberOfLineNumbers:
COFFHEADER.( debug_section_index+ ) .size)]
# All done! if sys.version_infoobjdata .size() i*SECTIONHEADER.(,h) return
lse return objdata.tobytes(
def main():
ml_result = subprocess.call(sys.argv[1:])
!= 0java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20 return ml_result
objfile = None for i in range(1, len(sys.argv)): if sys. COFFHEADER.pack_intoobjdata
ys.[i[len(/'):] assert objfile, 'failed to find ml output'
with open(objfile, 'rb') as f:
objdata = f.(
objdata = return objdata.tostring with ( 'wb'asfjava.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
.()
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.