| 782 | return path.parent / (path.name + ".MAP") |
| 783 | |
| 784 | class LinkStep: |
| 785 | def __init__(self, config: BuildConfigModule) -> None: |
| 786 | self.name = config["name"] |
| 787 | self.module_id = config["module_id"] |
| 788 | self.ldscript: Optional[Path] = Path(config["ldscript"]) |
| 789 | self.entry = config["entry"] |
| 790 | self.inputs: List[str] = [] |
| 791 | |
| 792 | def add(self, obj: Path) -> None: |
| 793 | self.inputs.append(serialize_path(obj)) |
| 794 | |
| 795 | def output(self) -> Path: |
| 796 | if self.module_id == 0: |
| 797 | return build_path / f"{self.name}.dol" |
| 798 | else: |
| 799 | return build_path / self.name / f"{self.name}.rel" |
| 800 | |
| 801 | def partial_output(self) -> Path: |
| 802 | if self.module_id == 0: |
| 803 | return build_path / f"{self.name}.elf" |
| 804 | else: |
| 805 | return build_path / self.name / f"{self.name}.plf" |
| 806 | |
| 807 | def write(self, n: ninja_syntax.Writer) -> None: |
| 808 | n.comment(f"Link {self.name}") |
| 809 | if self.module_id == 0: |
| 810 | elf_path = build_path / f"{self.name}.elf" |
| 811 | elf_ldflags = f"$ldflags -lcf {serialize_path(self.ldscript)}" |
| 812 | if config.generate_map: |
| 813 | elf_map = map_path(elf_path) |
| 814 | elf_ldflags += f" -map {serialize_path(elf_map)}" |
| 815 | else: |
| 816 | elf_map = None |
| 817 | n.build( |
| 818 | outputs=elf_path, |
| 819 | rule="link", |
| 820 | inputs=self.inputs, |
| 821 | implicit=[ |
| 822 | self.ldscript, |
| 823 | *mwld_implicit, |
| 824 | ], |
| 825 | implicit_outputs=elf_map, |
| 826 | variables={"ldflags": elf_ldflags}, |
| 827 | order_only="post-compile", |
| 828 | ) |
| 829 | else: |
| 830 | preplf_path = build_path / self.name / f"{self.name}.preplf" |
| 831 | plf_path = build_path / self.name / f"{self.name}.plf" |
| 832 | preplf_ldflags = "$ldflags -sdata 0 -sdata2 0 -r" |
| 833 | plf_ldflags = f"$ldflags -sdata 0 -sdata2 0 -r1 -lcf {serialize_path(self.ldscript)}" |
| 834 | if self.entry: |
| 835 | plf_ldflags += f" -m {self.entry}" |
| 836 | # -strip_partial is only valid with -m |
| 837 | if config.rel_strip_partial: |
| 838 | plf_ldflags += " -strip_partial" |
| 839 | if config.generate_map: |
| 840 | preplf_map = map_path(preplf_path) |
| 841 | preplf_ldflags += f" -map {serialize_path(preplf_map)}" |
no outgoing calls
no test coverage detected