aboutsummaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-09-19 09:17:02 -0400
committerNico Weber <thakis@chromium.org>2020-09-19 09:17:02 -0400
commite22a4fd59de668af1cb943e23a6f4bfc93090e0f (patch)
treec05c54d07ecf1ae268b136b2e108e8524b391e97 /lld
parent70409b2897f2c894e389c5ab590931f983d3e6d7 (diff)
downloadllvm-e22a4fd59de668af1cb943e23a6f4bfc93090e0f.zip
llvm-e22a4fd59de668af1cb943e23a6f4bfc93090e0f.tar.gz
llvm-e22a4fd59de668af1cb943e23a6f4bfc93090e0f.tar.bz2
lld/mach-o: Make tool scripts from 2124ca1d5cb py2.7-compatible
Diffstat (limited to 'lld')
-rwxr-xr-xlld/test/MachO/tools/generate-cfi-funcs.py60
-rwxr-xr-xlld/test/MachO/tools/validate-unwind-info.py30
2 files changed, 47 insertions, 43 deletions
diff --git a/lld/test/MachO/tools/generate-cfi-funcs.py b/lld/test/MachO/tools/generate-cfi-funcs.py
index da61a0f..d9c6ecd 100755
--- a/lld/test/MachO/tools/generate-cfi-funcs.py
+++ b/lld/test/MachO/tools/generate-cfi-funcs.py
@@ -4,6 +4,7 @@
The purpose is to produce object-file test inputs to lld with a
variety of compact unwind encodings.
"""
+from __future__ import print_function
import random
import argparse
import string
@@ -18,7 +19,7 @@ saved_regs = ["%r15", "%r14", "%r13", "%r12", "%rbx"]
saved_regs_combined = list(list(permutations(saved_regs, i))
for i in range(0,6))
-def print_function(name: str):
+def print_function(name):
global lsda_odds
have_lsda = (random.random() < lsda_odds)
frame_size = random.randint(4, 64) * 16
@@ -32,41 +33,42 @@ def print_function(name: str):
if func_size_high % 0x10 == 0:
func_size_low += 1
- print(f"""\
-### {name} regs={reg_count} frame={frame_size} lsda={have_lsda} size={func_size}
+ print("""\
+### %s regs=%d frame=%d lsda=%s size=%d
.section __TEXT,__text,regular,pure_instructions
.p2align 4, 0x90
- .globl {name}
-{name}:
- .cfi_startproc""")
+ .globl %s
+%s:
+ .cfi_startproc""" % (
+ name, reg_count, frame_size, have_lsda, func_size, name, name))
if have_lsda:
global lsda_n
lsda_n += 1
- print(f"""\
+ print("""\
.cfi_personality 155, ___gxx_personality_v0
- .cfi_lsda 16, Lexception{lsda_n}""")
- print(f"""\
- pushq %rbp
- .cfi_def_cfa_offset {frame_size}
- .cfi_offset %rbp, {frame_offset+(6*8)}
- movq %rsp, %rbp
- .cfi_def_cfa_register %rbp""")
+ .cfi_lsda 16, Lexception%d""" % lsda_n)
+ print("""\
+ pushq %%rbp
+ .cfi_def_cfa_offset %d
+ .cfi_offset %%rbp, %d
+ movq %%rsp, %%rbp
+ .cfi_def_cfa_register %%rbp""" % (frame_size, frame_offset + 6*8))
for i in range(reg_count):
- print(f".cfi_offset {regs_saved[i]}, {frame_offset+(i*8)}")
- print(f"""\
- .fill {func_size - 6}
- popq %rbp
+ print(".cfi_offset %s, %d" % (regs_saved[i], frame_offset+(i*8)))
+ print("""\
+ .fill %d
+ popq %%rbp
retq
.cfi_endproc
-""")
+""" % (func_size - 6))
if have_lsda:
- print(f"""\
+ print("""\
.section __TEXT,__gcc_except_tab
.p2align 2
-Lexception{lsda_n}:
+Lexception%d:
.space 0x10
-""")
+""" % lsda_n)
return func_size
def random_seed():
@@ -103,22 +105,22 @@ compact unwind entries, plus some more. The calculatation is sloppy.
global lsda_odds
lsda_odds = args.lsda / 100.0
- print(f"""\
-### seed={args.seed} lsda={lsda_odds} p2align={p2align}
+ print("""\
+### seed=%s lsda=%f p2align=%d
.section __TEXT,__text,regular,pure_instructions
- .p2align {p2align}, 0x90
-""")
+ .p2align %d, 0x90
+""" % (args.seed, lsda_odds, p2align, p2align))
size = 0
base = (1 << p2align)
if args.functions:
for n in range(args.functions):
- size += print_function(f"x{size+base:08x}")
+ size += print_function("x%08x" % (size+base))
else:
while size < (args.pages << 24):
- size += print_function(f"x{size+base:08x}")
+ size += print_function("x%08x" % (size+base))
- print(f"""\
+ print("""\
.section __TEXT,__text,regular,pure_instructions
.globl _main
.p2align 4, 0x90
diff --git a/lld/test/MachO/tools/validate-unwind-info.py b/lld/test/MachO/tools/validate-unwind-info.py
index bfbf771..ee4cca4 100755
--- a/lld/test/MachO/tools/validate-unwind-info.py
+++ b/lld/test/MachO/tools/validate-unwind-info.py
@@ -3,6 +3,7 @@
"""Validate compact unwind info by cross checking the llvm-objdump
reports of the input object file vs final linked output.
"""
+from __future__ import print_function
import sys
import argparse
import re
@@ -25,11 +26,11 @@ def main():
object_encodings_list = [(symbol, encoding, personality, lsda)
for symbol, encoding, personality, lsda in
- re.findall(rf"start:\s+0x{hex}+\s+(\w+)\s+" +
- rf"length:\s+0x{hex}+\s+" +
- rf"compact encoding:\s+0x({hex}+)(?:\s+" +
- rf"personality function:\s+0x({hex}+)\s+\w+\s+" +
- rf"LSDA:\s+0x({hex}+)\s+\w+(?: \+ 0x{hex}+)?)?",
+ re.findall(r"start:\s+0x%s+\s+(\w+)\s+" % hex +
+ r"length:\s+0x%s+\s+" % hex +
+ r"compact encoding:\s+0x(%s+)(?:\s+" % hex +
+ r"personality function:\s+0x(%s+)\s+\w+\s+" % hex +
+ r"LSDA:\s+0x(%s+)\s+\w+(?: \+ 0x%s+)?)?" % (hex, hex),
objdump_string, re.DOTALL)]
object_encodings_map = {symbol:encoding
for symbol, encoding, _, _ in object_encodings_list}
@@ -38,21 +39,21 @@ def main():
program_symbols_map = {address:symbol
for address, symbol in
- re.findall(rf"^{hex8}({hex8}) g\s+F __TEXT,__text (x\1)$",
+ re.findall(r"^%s(%s) g\s+F __TEXT,__text (x\1)$" % (hex8, hex8),
objdump_string, re.MULTILINE)}
if not program_symbols_map:
sys.exit("no program symbols found in input")
program_common_encodings = (
- re.findall(rf"^\s+encoding\[\d+\]: 0x({hex}+)$",
+ re.findall(r"^\s+encoding\[\d+\]: 0x(%s+)$" % hex,
objdump_string, re.MULTILINE))
if not program_common_encodings:
sys.exit("no common encodings found in input")
program_encodings_map = {program_symbols_map[address]:encoding
for address, encoding in
- re.findall(rf"^\s+\[\d+\]: function offset=0x({hex}+), " +
- rf"encoding\[\d+\]=0x({hex}+)$",
+ re.findall(r"^\s+\[\d+\]: function offset=0x(%s+), " % hex +
+ r"encoding\[\d+\]=0x(%s+)$" % hex,
objdump_string, re.MULTILINE)}
if not object_encodings_map:
sys.exit("no program encodings found in input")
@@ -66,13 +67,14 @@ def main():
if fold:
del object_encodings_map[symbol]
if args.debug:
- print(f"{'delete' if fold else 'retain'} {symbol} with {encoding}")
+ print("%s %s with %s" % (
+ 'delete' if fold else 'retain', symbol, encoding))
encoding0 = encoding
if program_encodings_map != object_encodings_map:
if args.debug:
- pprint(f"program encodings map:\n{program_encodings_map}")
- pprint(f"object encodings map:\n{object_encodings_map}")
+ pprint("program encodings map:\n" + program_encodings_map)
+ pprint("object encodings map:\n" + object_encodings_map)
sys.exit("encoding maps differ")
# Count frequency of object-file folded encodings
@@ -87,8 +89,8 @@ def main():
if program_common_encodings != encoding_frequencies:
if args.debug:
- pprint(f"program common encodings:\n{program_common_encodings}")
- pprint(f"object encoding frequencies:\n{encoding_frequencies}")
+ pprint("program common encodings:\n" + program_common_encodings)
+ pprint("object encoding frequencies:\n" + encoding_frequencies)
sys.exit("encoding frequencies differ")