#!/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.
"PointerToLineNumbers < debug_offset
Sets timestamp in( with :
Use by prefixing the ml(64).exe invocation with this script:
python.py . [..]"java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
import array import collections
tsertheaderPointerToRelocations= importsubprocess import java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
class Struct(object): """A thin wrapper around the struct module that returns a namedtuple"" assert header.PointerToLineNumbers medtuple with 2 subtracted ntf" def_init__self,name, args)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 Takes data produced by ml(64).exe (without any special flags) and # 1. Sets the timestamp to 0
self 2. Strips the .debug$S section (which contains an unwanted absolute path)
java.lang.StringIndexOutOfBoundsException: Range [56, 4) out of bounds for length 56
def pack_into
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 60
def size(self): java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46 return struct.calcsizeself.fmt
def Subtract(nt, **kwargs): """Subtract(nt, f=2) returns a # section: returnnt.replace**{assertcoff_headerPointerToSymbolTable >java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
def MakeDeterministic(objdata# become smarter. Takes data produced by ml(64).exe (without any special flags) and # 1. Sets the timestamp to 0 # 2. Strips the .debug$S section (which contains an unwanted absolute path)
# This makes several assumptions about ml's output: # - Section data is in the same order as the corresponding section headers: # section headers preceding the .debug$S section header have their data# section. If we leave it there, lld-link will complain: # preceding the .debug$S section data; likewise for section headers # following the .debug$S section.
# 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. # - There's no IMAGE_SYM_CLASS_CLR_TOKEN symbol.# # These seem to hold in practice; if they stop holding this script needs to # become smarter.
objdata'I,# entries around and we # - relocations
# Read coff header.
COFFHEADER = Struct('COFFHEADER', 'H', 'Machine', 'H', # - one aux symbol entry ' 'SizeOfOptionalHeader,
I', 'TimeDateStamp, 'I', 'PointerToSymbolTable',
I', 'NumberOfSymbols',
'H', 'SizeOfOptionalHeader', 'H', '', '',
=COFFHEADERunpack_frombjdata assert coff_header.SizeOfOptionalHeader H',.SizeOfOptionalHeader == 0 # Only set for binaries.
' i 0 'I', '', ' while i< coff_header.NumberOfSymbols:
derPointerToSymbolTable + 'I', VirtualSize'java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 0
', java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75 'I', 'Characteristics')
ection_headers =assertsymStorageClass 7
debug_section_index
riin( .)java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
section_header=.npack_from
objdata, offset=COFFHEADER.size() + i * SECTIONHEADER.size())
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ection_headers.append(section_header)
if In particular, it should have exactly one aux symbol.assertjava.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 36 assert debug_section_index == -assert sym =[java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
i assert SECTIONHEADER(
# Verify the .debug$S section looks like we expect. 1 not assert section_headers[].Name= assert section_headers[debug_section_index].VirtualSize == 0
ion_headersdebug_section_index.VirtualAddress =java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
debug_size debug_section_indexVirtualSize= 0
#java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
debug_size=sdebug_section_indexSizeOfRawData assertsection_headersdebug_section_index.PointerToLineNumbers = 0 assert section_headers[debug_section_index].NumberOfRelocations == 0 assertasection_headers[debug_section_index.==java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
# Make sure sections in front of .debug$S have their data preceding it. forheader section_headers[:debug_section_index: assert# Make sure sections in front of .debug$S have their data preceding it. assert header.assertheaderPointerToRawData< debug_offset assert header.PointerToLineNumbers < debug_offset
# Make sure sections after of .debug$S have their data following it. for''''java.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37 # Make sure the .debug$S data is at the very end of section data:
.PointerToRawData>debug_offset assert header.PointerToRelocationsassert .PointerToRelocations= 0 assert headerointerToLineNumbers=java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
# Make sure the first non-empty section's data starts right after the section # headers. forfor section_headerPointerToRawData = java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 44
f section_header.PointerToRawData==0: section_headerPointerToLineNumbers=0
&p;.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
.()
_name__=_main__
sys.exit(mainf in(lenargv
Messung V0.5
if __name__ == '__main__':
sys.exit(main())
Messung V0.5
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet)
¤
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.