File tree Expand file tree Collapse file tree 3 files changed +107
-0
lines changed
src/splat/segtypes/common Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Original file line number Diff line number Diff line change @@ -290,6 +290,24 @@ It looks for libraries in the [`lib_path`](https://github.com/ethteck/splat/wiki
290290- { type: lib, name: a_lib, object: b_obj, section: .text }
291291` ` `
292292
293+ # # `o`
294+
295+ Similar to the `lib` segment but used to reference an object file (for example extracted from a shared library file). Does not extract anything from the input binary.
296+
297+ ` ` ` yaml
298+ # link to .text of myobject.o
299+ - [auto, o, myobject]
300+ ` ` `
301+
302+ ` ` ` yaml
303+ # link to .rodata of myobject.o
304+ - [auto, o, myobject, .rodata]
305+ ` ` `
306+
307+ ` ` ` yaml
308+ # link to .text of myobject.o (dict representation)
309+ - { type: o, name: myobject, section: .text }
310+ ` ` `
293311
294312# # `pad`
295313
Original file line number Diff line number Diff line change 1+ from typing import Optional
2+
3+ from pathlib import Path
4+
5+ from ...util import options
6+ from ..common .lib import CommonSegment
7+ from ..segment import parse_segment_vram
8+
9+
10+ class CommonSegO (CommonSegment ):
11+ def __init__ (
12+ self ,
13+ rom_start : Optional [int ],
14+ rom_end : Optional [int ],
15+ type : str ,
16+ name : str ,
17+ vram_start : Optional [int ],
18+ args : list ,
19+ yaml ,
20+ ):
21+ super ().__init__ (
22+ rom_start ,
23+ rom_end ,
24+ type ,
25+ name ,
26+ vram_start ,
27+ args = args ,
28+ yaml = yaml ,
29+ )
30+
31+ vram = parse_segment_vram (self .yaml )
32+ if vram is not None :
33+ self .vram_start = vram
34+
35+ if isinstance (yaml , dict ):
36+ self .section = yaml .get ("section" , ".text" )
37+ else :
38+ if len (args ) > 0 :
39+ self .section = args [0 ]
40+ else :
41+ self .section = ".text"
42+
43+ self .extract = False
44+
45+ def get_linker_section (self ) -> str :
46+ return self .section
47+
48+ def out_path (self ) -> Optional [Path ]:
49+ out_path = options .opts .build_path / f"{ self .name } "
50+ return out_path
Original file line number Diff line number Diff line change 1616from src .splat .segtypes .common .code import CommonSegCode
1717from src .splat .segtypes .common .c import CommonSegC
1818from src .splat .segtypes .common .bss import CommonSegBss
19+ from src .splat .segtypes .common .o import CommonSegO
1920from src .splat .segtypes .segment import Segment
2021
2122
@@ -368,6 +369,44 @@ def test_disassemble_data(self):
368369 assert bss .spim_section .get_section ().bssVramEnd == 0x300
369370
370371
372+ class O (unittest .TestCase ):
373+ def test_o_text (self ):
374+ # Segment __init__ requires opts to be initialized
375+ test_init ()
376+
377+ o = CommonSegO (
378+ rom_start = 0x100 ,
379+ rom_end = 0x200 ,
380+ vram_start = 0x0 ,
381+ type = "o" ,
382+ name = "myobject" ,
383+ args = [],
384+ yaml = None ,
385+ )
386+ expected = Path ("test/basic_app/build/myobject" )
387+ self .assertEqual (expected , o .out_path ())
388+ self .assertEqual (".text" , o .get_linker_section ())
389+
390+ def test_o_rodata (self ):
391+ # Segment __init__ requires opts to be initialized
392+ test_init ()
393+
394+ section = ".rodata"
395+ o = CommonSegO (
396+ rom_start = 0x100 ,
397+ rom_end = 0x200 ,
398+ vram_start = 0x0 ,
399+ type = "o" ,
400+ name = "myobject" ,
401+ args = [section ],
402+ yaml = None ,
403+ )
404+ out_path = Path ("test/basic_app/build/myobject" )
405+
406+ self .assertEqual (out_path , o .out_path ())
407+ self .assertEqual (section , o .get_linker_section ())
408+
409+
371410class SymbolsInitialize (unittest .TestCase ):
372411 def test_attrs (self ):
373412 symbols .reset_symbols ()
You can’t perform that action at this time.
0 commit comments