Skip to content

Commit

Permalink
Prevent a segment from being its own sibling (#411)
Browse files Browse the repository at this point in the history
* Prevent a segment from being its own sibling

* version bump

* black

* update tests

* whoops
  • Loading branch information
AngheloAlf authored Oct 12, 2024
1 parent dbac842 commit a9950f9
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 103 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# splat Release Notes

### 0.27.3

* Fix a possible infinite recursion due to a segment being its own sibling.

### 0.27.2

* Added new global option `emit_subalign`. If disabled, subalign directives will not be emitted in the generated linker script. Enabled by default (no change in default behavior).

### 0.27.1
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The brackets corresponds to the optional dependencies to install while installin
If you use a `requirements.txt` file in your repository, then you can add this library with the following line:

```txt
splat64[mips]>=0.27.2,<1.0.0
splat64[mips]>=0.27.3,<1.0.0
```

### Optional dependencies
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "splat64"
# Should be synced with src/splat/__init__.py
version = "0.27.2"
version = "0.27.3"
description = "A binary splitting tool to assist with decompilation and modding projects"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
2 changes: 1 addition & 1 deletion src/splat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__package_name__ = __name__

# Should be synced with pyproject.toml
__version__ = "0.27.2"
__version__ = "0.27.3"
__author__ = "ethteck"

from . import util as util
Expand Down
16 changes: 8 additions & 8 deletions src/splat/segtypes/common/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def _generate_segment_from_all(
rep.given_dir = self.given_dir
rep.given_symbol_name_format = self.symbol_name_format
rep.given_symbol_name_format_no_rom = self.symbol_name_format_no_rom
assert rep != base_seg, rep
rep.sibling = base_seg
rep.parent = self
rep.is_generated = True
Expand Down Expand Up @@ -254,16 +255,15 @@ def parse_subsegments(self, segment_yaml) -> List[Segment]:
# We need base_segments to be fully constructed before start assigning siblings to segments,
# otherwise we may miss segments that are placed before any text segment
for segment in ret:
segment.sibling = base_segments.get(segment.name, None)
sibling = base_segments.get(segment.name, None)
if sibling == segment:
sibling = None
segment.sibling = sibling

if segment.sibling is not None:
if sibling is not None:
# Make siblings reference between them
segment.siblings[segment.sibling.get_linker_section_linksection()] = (
segment.sibling
)
segment.sibling.siblings[segment.get_linker_section_linksection()] = (
segment
)
segment.siblings[sibling.get_linker_section_linksection()] = sibling
sibling.siblings[segment.get_linker_section_linksection()] = segment

ret = self._insert_all_auto_sections(ret, base_segments, readonly_before)

Expand Down
2 changes: 1 addition & 1 deletion test/basic_app/expected/asm/data/main.bss.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
.section .bss

glabel D_80000540
/* 80000540 */ .space 0x80
/* 80000540 */ .space 0x80
8 changes: 4 additions & 4 deletions test/basic_app/expected/asm/data/main.data.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
.section .data

glabel D_80000500
/* 1100 80000500 00000001 */ .word 0x00000001
/* 1100 80000500 00000001 */ .word 0x00000001
.size D_80000500, . - D_80000500

glabel D_80000504
/* 1104 80000504 00000000 */ .word 0x00000000
/* 1108 80000508 00000000 */ .word 0x00000000
/* 110C 8000050C 00000000 */ .word 0x00000000
/* 1104 80000504 00000000 */ .word 0x00000000
/* 1108 80000508 00000000 */ .word 0x00000000
/* 110C 8000050C 00000000 */ .word 0x00000000
.size D_80000504, . - D_80000504
8 changes: 4 additions & 4 deletions test/basic_app/expected/asm/handwritten.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

/* Handwritten function */
glabel func_800004F0
/* 10F0 800004F0 00851020 */ add $v0, $a0, $a1 /* handwritten instruction */
/* 10F4 800004F4 03E00008 */ jr $ra
/* 10F8 800004F8 00000000 */ nop
/* 10FC 800004FC 00000000 */ nop
/* 10F0 800004F0 00851020 */ add $v0, $a0, $a1 /* handwritten instruction */
/* 10F4 800004F4 03E00008 */ jr $ra
/* 10F8 800004F8 00000000 */ nop
/* 10FC 800004FC 00000000 */ nop
.size func_800004F0, . - func_800004F0
4 changes: 2 additions & 2 deletions test/basic_app/expected/asm/nonmatchings/main/D_80000510.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.section .rodata

glabel D_80000510
/* 1110 80000510 00010203 */ .word 0x00010203
/* 1114 80000514 04050607 */ .word 0x04050607
/* 1110 80000510 00010203 */ .word 0x00010203
/* 1114 80000514 04050607 */ .word 0x04050607
.size D_80000510, . - D_80000510
120 changes: 60 additions & 60 deletions test/basic_app/expected/asm/nonmatchings/main/func_80000400.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,69 @@
.section .rodata
.align 3
glabel jtbl_80000518
/* 1118 80000518 80000448 */ .word .L80000448
/* 111C 8000051C 80000450 */ .word .L80000450
/* 1120 80000520 80000458 */ .word .L80000458
/* 1124 80000524 80000460 */ .word .L80000460
/* 1128 80000528 80000468 */ .word .L80000468
/* 112C 8000052C 80000470 */ .word .L80000470
/* 1130 80000530 80000478 */ .word .L80000478
/* 1134 80000534 80000480 */ .word .L80000480
/* 1138 80000538 00000000 */ .word 0x00000000
/* 113C 8000053C 00000000 */ .word 0x00000000
/* 1118 80000518 80000448 */ .word .L80000448
/* 111C 8000051C 80000450 */ .word .L80000450
/* 1120 80000520 80000458 */ .word .L80000458
/* 1124 80000524 80000460 */ .word .L80000460
/* 1128 80000528 80000468 */ .word .L80000468
/* 112C 8000052C 80000470 */ .word .L80000470
/* 1130 80000530 80000478 */ .word .L80000478
/* 1134 80000534 80000480 */ .word .L80000480
/* 1138 80000538 00000000 */ .word 0x00000000
/* 113C 8000053C 00000000 */ .word 0x00000000
.size jtbl_80000518, . - jtbl_80000518


.section .text
glabel func_80000400
/* 1000 80000400 27BDFFF8 */ addiu $sp, $sp, -0x8
/* 1004 80000404 AFBE0000 */ sw $fp, 0x0($sp)
/* 1008 80000408 03A0F021 */ addu $fp, $sp, $zero
/* 100C 8000040C 3C028000 */ lui $v0, %hi(D_80000504)
/* 1010 80000410 8C420504 */ lw $v0, %lo(D_80000504)($v0)
/* 1014 80000414 2C430008 */ sltiu $v1, $v0, 0x8
/* 1018 80000418 1060001B */ beqz $v1, .L80000488
/* 101C 8000041C 00000000 */ nop
/* 1020 80000420 3C028000 */ lui $v0, %hi(D_80000504)
/* 1024 80000424 8C420504 */ lw $v0, %lo(D_80000504)($v0)
/* 1028 80000428 00401821 */ addu $v1, $v0, $zero
/* 102C 8000042C 00031080 */ sll $v0, $v1, 2
/* 1030 80000430 3C038000 */ lui $v1, %hi(jtbl_80000518)
/* 1034 80000434 24630518 */ addiu $v1, $v1, %lo(jtbl_80000518)
/* 1038 80000438 00431021 */ addu $v0, $v0, $v1
/* 103C 8000043C 8C430000 */ lw $v1, 0x0($v0)
/* 1040 80000440 00600008 */ jr $v1
/* 1044 80000444 00000000 */ nop
.L80000448:
/* 1048 80000448 08000124 */ j .L80000490
/* 104C 8000044C 24020007 */ addiu $v0, $zero, 0x7
.L80000450:
/* 1050 80000450 08000124 */ j .L80000490
/* 1054 80000454 24020006 */ addiu $v0, $zero, 0x6
.L80000458:
/* 1058 80000458 08000124 */ j .L80000490
/* 105C 8000045C 24020005 */ addiu $v0, $zero, 0x5
.L80000460:
/* 1060 80000460 08000124 */ j .L80000490
/* 1064 80000464 24020004 */ addiu $v0, $zero, 0x4
.L80000468:
/* 1068 80000468 08000124 */ j .L80000490
/* 106C 8000046C 24020003 */ addiu $v0, $zero, 0x3
.L80000470:
/* 1070 80000470 08000124 */ j .L80000490
/* 1074 80000474 24020002 */ addiu $v0, $zero, 0x2
.L80000478:
/* 1078 80000478 08000124 */ j .L80000490
/* 107C 8000047C 24020001 */ addiu $v0, $zero, 0x1
.L80000480:
/* 1080 80000480 08000124 */ j .L80000490
/* 1084 80000484 00001021 */ addu $v0, $zero, $zero
.L80000488:
/* 1088 80000488 08000124 */ j .L80000490
/* 108C 8000048C 00001021 */ addu $v0, $zero, $zero
.L80000490:
/* 1090 80000490 03C0E821 */ addu $sp, $fp, $zero
/* 1094 80000494 8FBE0000 */ lw $fp, 0x0($sp)
/* 1098 80000498 03E00008 */ jr $ra
/* 109C 8000049C 27BD0008 */ addiu $sp, $sp, 0x8
/* 1000 80000400 27BDFFF8 */ addiu $sp, $sp, -0x8
/* 1004 80000404 AFBE0000 */ sw $fp, 0x0($sp)
/* 1008 80000408 03A0F021 */ addu $fp, $sp, $zero
/* 100C 8000040C 3C028000 */ lui $v0, %hi(D_80000504)
/* 1010 80000410 8C420504 */ lw $v0, %lo(D_80000504)($v0)
/* 1014 80000414 2C430008 */ sltiu $v1, $v0, 0x8
/* 1018 80000418 1060001B */ beqz $v1, .L80000488
/* 101C 8000041C 00000000 */ nop
/* 1020 80000420 3C028000 */ lui $v0, %hi(D_80000504)
/* 1024 80000424 8C420504 */ lw $v0, %lo(D_80000504)($v0)
/* 1028 80000428 00401821 */ addu $v1, $v0, $zero
/* 102C 8000042C 00031080 */ sll $v0, $v1, 2
/* 1030 80000430 3C038000 */ lui $v1, %hi(jtbl_80000518)
/* 1034 80000434 24630518 */ addiu $v1, $v1, %lo(jtbl_80000518)
/* 1038 80000438 00431021 */ addu $v0, $v0, $v1
/* 103C 8000043C 8C430000 */ lw $v1, 0x0($v0)
/* 1040 80000440 00600008 */ jr $v1
/* 1044 80000444 00000000 */ nop
.L80000448:
/* 1048 80000448 08000124 */ j .L80000490
/* 104C 8000044C 24020007 */ addiu $v0, $zero, 0x7
.L80000450:
/* 1050 80000450 08000124 */ j .L80000490
/* 1054 80000454 24020006 */ addiu $v0, $zero, 0x6
.L80000458:
/* 1058 80000458 08000124 */ j .L80000490
/* 105C 8000045C 24020005 */ addiu $v0, $zero, 0x5
.L80000460:
/* 1060 80000460 08000124 */ j .L80000490
/* 1064 80000464 24020004 */ addiu $v0, $zero, 0x4
.L80000468:
/* 1068 80000468 08000124 */ j .L80000490
/* 106C 8000046C 24020003 */ addiu $v0, $zero, 0x3
.L80000470:
/* 1070 80000470 08000124 */ j .L80000490
/* 1074 80000474 24020002 */ addiu $v0, $zero, 0x2
.L80000478:
/* 1078 80000478 08000124 */ j .L80000490
/* 107C 8000047C 24020001 */ addiu $v0, $zero, 0x1
.L80000480:
/* 1080 80000480 08000124 */ j .L80000490
/* 1084 80000484 00001021 */ addu $v0, $zero, $zero
.L80000488:
/* 1088 80000488 08000124 */ j .L80000490
/* 108C 8000048C 00001021 */ addu $v0, $zero, $zero
.L80000490:
/* 1090 80000490 03C0E821 */ addu $sp, $fp, $zero
/* 1094 80000494 8FBE0000 */ lw $fp, 0x0($sp)
/* 1098 80000498 03E00008 */ jr $ra
/* 109C 8000049C 27BD0008 */ addiu $sp, $sp, 0x8
.size func_80000400, . - func_80000400
42 changes: 21 additions & 21 deletions test/basic_app/expected/asm/nonmatchings/main/func_800004A0.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
.set noreorder /* don't insert nops after branches */

glabel func_800004A0
/* 10A0 800004A0 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 10A4 800004A4 AFBF0014 */ sw $ra, 0x14($sp)
/* 10A8 800004A8 AFBE0010 */ sw $fp, 0x10($sp)
/* 10AC 800004AC 0C000100 */ jal func_80000400
/* 10B0 800004B0 03A0F021 */ addu $fp, $sp, $zero
.L800004B4:
/* 10B4 800004B4 3C028000 */ lui $v0, %hi(D_80000500)
/* 10B8 800004B8 8C420500 */ lw $v0, %lo(D_80000500)($v0)
/* 10BC 800004BC 24430001 */ addiu $v1, $v0, 0x1
/* 10C0 800004C0 3C018000 */ lui $at, %hi(D_80000500)
/* 10C4 800004C4 AC230500 */ sw $v1, %lo(D_80000500)($at)
/* 10C8 800004C8 3C028000 */ lui $v0, %hi(D_80000500)
/* 10CC 800004CC 8C420500 */ lw $v0, %lo(D_80000500)($v0)
/* 10D0 800004D0 0800012D */ j .L800004B4
/* 10D4 800004D4 00000000 */ nop
/* 10D8 800004D8 03C0E821 */ addu $sp, $fp, $zero
/* 10DC 800004DC 8FBF0014 */ lw $ra, 0x14($sp)
/* 10E0 800004E0 8FBE0010 */ lw $fp, 0x10($sp)
/* 10E4 800004E4 03E00008 */ jr $ra
/* 10E8 800004E8 27BD0018 */ addiu $sp, $sp, 0x18
/* 10EC 800004EC 00000000 */ nop
/* 10A0 800004A0 27BDFFE8 */ addiu $sp, $sp, -0x18
/* 10A4 800004A4 AFBF0014 */ sw $ra, 0x14($sp)
/* 10A8 800004A8 AFBE0010 */ sw $fp, 0x10($sp)
/* 10AC 800004AC 0C000100 */ jal func_80000400
/* 10B0 800004B0 03A0F021 */ addu $fp, $sp, $zero
.L800004B4:
/* 10B4 800004B4 3C028000 */ lui $v0, %hi(D_80000500)
/* 10B8 800004B8 8C420500 */ lw $v0, %lo(D_80000500)($v0)
/* 10BC 800004BC 24430001 */ addiu $v1, $v0, 0x1
/* 10C0 800004C0 3C018000 */ lui $at, %hi(D_80000500)
/* 10C4 800004C4 AC230500 */ sw $v1, %lo(D_80000500)($at)
/* 10C8 800004C8 3C028000 */ lui $v0, %hi(D_80000500)
/* 10CC 800004CC 8C420500 */ lw $v0, %lo(D_80000500)($v0)
/* 10D0 800004D0 0800012D */ j .L800004B4
/* 10D4 800004D4 00000000 */ nop
/* 10D8 800004D8 03C0E821 */ addu $sp, $fp, $zero
/* 10DC 800004DC 8FBF0014 */ lw $ra, 0x14($sp)
/* 10E0 800004E0 8FBE0010 */ lw $fp, 0x10($sp)
/* 10E4 800004E4 03E00008 */ jr $ra
/* 10E8 800004E8 27BD0018 */ addiu $sp, $sp, 0x18
/* 10EC 800004EC 00000000 */ nop
.size func_800004A0, . - func_800004A0

0 comments on commit a9950f9

Please sign in to comment.