Skip to content

Commit 867a686

Browse files
committed
Cleanup for PR
1 parent 558c83b commit 867a686

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

Lib/test/test_jit_stencils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ def test_jit_stencils(self):
7171
actual = self._build_jit_stencils(target)
7272
found = True
7373
self._check_jit_stencils(expected, actual, test_jit_stencils_h)
74-
# This is a local build. If the JIT is available, at least one test should run:
75-
assert found, "No JIT stencils built!"
74+
self.assertTrue(found, "No JIT stencils built!")
7675

7776

7877
if __name__ == "__main__":

Tools/jit/_targets.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -393,30 +393,30 @@ def _handle_section(
393393
elif section_type in {"SHT_PROGBITS", "SHT_NOBITS"}:
394394
if "SHF_ALLOC" not in flags:
395395
return
396+
if "SectionData" in section:
397+
section_data_bytes = section["SectionData"]["Bytes"]
398+
else:
399+
# Zeroed BSS data:
400+
section_data_bytes = [0] * section["Size"]
396401
if "SHF_EXECINSTR" in flags:
397402
value = _stencils.HoleValue.CODE
398403
stencil = group.code
399404
else:
400405
value = _stencils.HoleValue.DATA
401406
stencil = group.data
402-
if section_type == "SHT_PROGBITS":
403-
assert "SectionData" in section
404-
section_data_bytes = section["SectionData"]["Bytes"]
405-
else:
406-
# Zeroed BSS data:
407-
section_data_bytes = [0] * section["Size"]
408407
if "SHF_WRITE" in flags:
409408
assert value is _stencils.HoleValue.DATA
410409
value = _stencils.HoleValue.WRITABLE
411410
section_data_bytes = []
412-
group.symbols[section["Index"]] = value, len(stencil.body)
411+
base = len(stencil.body)
412+
group.symbols[section["Index"]] = value, base
413+
stencil.body.extend(section_data_bytes)
413414
for wrapped_symbol in section["Symbols"]:
414415
symbol = wrapped_symbol["Symbol"]
415-
offset = len(stencil.body) + symbol["Value"]
416+
offset = base + symbol["Value"]
416417
name = symbol["Name"]["Name"]
417418
name = name.removeprefix(self.symbol_prefix)
418419
group.symbols[name] = value, offset
419-
stencil.body.extend(section_data_bytes)
420420
assert not section["Relocations"]
421421
else:
422422
assert section_type in {
@@ -474,15 +474,12 @@ class _MachO(
474474
def _handle_section(
475475
self, section: _schema.MachOSection, group: _stencils.StencilGroup
476476
) -> None:
477-
assert section["Address"] >= len(group.code.body)
478477
if "SectionData" in section:
479478
section_data_bytes = section["SectionData"]["Bytes"]
480479
else:
481480
# Zeroed BSS data:
482481
section_data_bytes = [0] * section["Size"]
483482
flags = {flag["Name"] for flag in section["Attributes"]["Flags"]}
484-
name = section["Name"]["Value"]
485-
name = name.removeprefix(self.symbol_prefix)
486483
if "Debug" in flags:
487484
return
488485
if "PureInstructions" in flags:
@@ -492,19 +489,20 @@ def _handle_section(
492489
value = _stencils.HoleValue.DATA
493490
stencil = group.data
494491
segment = section["Segment"]["Value"]
492+
assert segment in {"__DATA", "__TEXT"}, segment
495493
if segment == "__DATA":
496494
value = _stencils.HoleValue.WRITABLE
497495
section_data_bytes = []
498-
else:
499-
assert segment == "__TEXT", segment
500496
base = len(stencil.body)
501-
group.symbols[name] = value, base
502497
group.symbols[section["Index"]] = value, base
503498
stencil.body.extend(section_data_bytes)
499+
name = section["Name"]["Value"]
500+
name = name.removeprefix(self.symbol_prefix)
501+
group.symbols[name] = value, base
504502
assert "Symbols" in section
505503
for wrapped_symbol in section["Symbols"]:
506504
symbol = wrapped_symbol["Symbol"]
507-
offset = symbol["Value"] - section["Address"] + base
505+
offset = base + symbol["Value"] - section["Address"]
508506
name = symbol["Name"]["Name"]
509507
name = name.removeprefix(self.symbol_prefix)
510508
group.symbols[name] = value, offset
@@ -589,23 +587,23 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
589587
target = _MachO(host, condition, optimizer=optimizer)
590588
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
591589
host = "aarch64-pc-windows-msvc"
592-
args = ["-fms-runtime-lib=dll", "-fplt"]
593590
condition = "defined(_M_ARM64)"
591+
args = ["-fms-runtime-lib=dll", "-fplt"]
594592
optimizer = _optimizers.OptimizerAArch64
595593
target = _COFF64(host, condition, args=args, optimizer=optimizer)
596594
elif re.fullmatch(r"aarch64-.*-linux-gnu", host):
597595
host = "aarch64-unknown-linux-gnu"
596+
condition = "defined(__aarch64__) && defined(__linux__)"
598597
# -mno-outline-atomics: Keep intrinsics from being emitted.
599598
args = ["-fpic", "-mno-outline-atomics"]
600-
condition = "defined(__aarch64__) && defined(__linux__)"
601599
optimizer = _optimizers.OptimizerAArch64
602600
target = _ELF(host, condition, args=args, optimizer=optimizer)
603601
elif re.fullmatch(r"i686-pc-windows-msvc", host):
604602
host = "i686-pc-windows-msvc"
603+
condition = "defined(_M_IX86)"
605604
# -Wno-ignored-attributes: __attribute__((preserve_none)) is not supported here.
606605
args = ["-DPy_NO_ENABLE_SHARED", "-Wno-ignored-attributes"]
607606
optimizer = _optimizers.OptimizerX86
608-
condition = "defined(_M_IX86)"
609607
target = _COFF32(host, condition, args=args, optimizer=optimizer)
610608
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
611609
host = "x86_64-apple-darwin"
@@ -614,14 +612,14 @@ def get_target(host: str) -> _COFF32 | _COFF64 | _ELF | _MachO:
614612
target = _MachO(host, condition, optimizer=optimizer)
615613
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
616614
host = "x86_64-pc-windows-msvc"
617-
args = ["-fms-runtime-lib=dll"]
618615
condition = "defined(_M_X64)"
616+
args = ["-fms-runtime-lib=dll"]
619617
optimizer = _optimizers.OptimizerX86
620618
target = _COFF64(host, condition, args=args, optimizer=optimizer)
621619
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
622620
host = "x86_64-unknown-linux-gnu"
623-
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"]
624621
condition = "defined(__x86_64__) && defined(__linux__)"
622+
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"]
625623
optimizer = _optimizers.OptimizerX86
626624
target = _ELF(host, condition, args=args, optimizer=optimizer)
627625
else:

0 commit comments

Comments
 (0)