brintos

brintos / llvm-project-archived public Read only

0
0
Text · 808 B · 4867ab7 Raw
31 lines · plain
1# RUN: yaml2obj %S/Inputs/long-section-name.yaml -o %t.obj2 3## Replace the section name field of the object file with /4\0abcde emulating4## a section name field not fully null-padded at the end.5# RUN: %python %s %t.obj6 7## This should print the LongSectionName section.8# RUN: llvm-objdump --headers %t.obj | FileCheck %s9 10# CHECK: LongSectionName11 12import sys13 14if len(sys.argv) < 2:15  print("Use: python3 long-section-name.test <OBJECT_FILE>")16  exit(1)17 18pattern = b'/4'19replacement = b'/4\0abcde'20 21data = None22with open(sys.argv[1], "rb") as inp:23  data = inp.read()24with open(sys.argv[1], "wb") as outp:25  pos = data.find(pattern)26  if pos == -1:27    sys.exit("Error: Pattern /4 not found in " + sys.argv[1])28  outp.write(data[:pos])29  outp.write(replacement)30  outp.write(data[pos + len(replacement):])31