Skip to content

gnu_ppc.py

ofrak_patch_maker.toolchain.gnu_ppc

GNU_PPC_LINUX_10_Toolchain (GNU_10_Toolchain)

segment_alignment: int property readonly

For example, x86 returns 16. This will most often be used when programmatically allocating memory for code/data.

Returns:

Type Description
int

required alignment factor for the toolchain/ISA

name: str property readonly

Returns:

Type Description
str

name property that matches the value used in toolchain.conf to access paths

_get_assembler_target(self, processor) private

Red Balloon Security strongly recommends all users provide their specific hardware target for best results.

Parameters:

Name Type Description Default
processor ArchInfo required

Returns:

Type Description
Optional[str]

a default assembler target for the provided processor unless one is provided in self._config.

Exceptions:

Type Description
PatchMakerException

if no target provided and program attributes do not correspond to a default value.

Source code in ofrak_patch_maker/toolchain/gnu_ppc.py
def _get_assembler_target(self, processor: ArchInfo) -> Optional[str]:
    if processor.isa != InstructionSet.PPC:
        raise ValueError(
            f"The GNU PPC toolchain does not support ISAs that are not PPC. "
            f"(Got: {processor.isa.name}.)"
        )
    if self._config.assembler_target:
        return self._config.assembler_target

    # PPC GNU 10 does not implement -march. See:
    # https://gcc.gnu.org/onlinedocs/gcc-10.4.0/gcc/RS_002f6000-and-PowerPC-Options.html#RS_002f6000-and-PowerPC-Options
    return None

ld_generate_placeholder_reloc_sections(self)

GCC generates these sections for relocatable binaries even if they are completely unnecessary.

They don't seem to make it into the final executable, so there should be no risk of injecting them inadvertently.

Todo

No clear way to get size, so way overestimate.

Source code in ofrak_patch_maker/toolchain/gnu_ppc.py
def ld_generate_placeholder_reloc_sections(self):
    regions, sections = super().ld_generate_placeholder_reloc_sections()
    (
        got_region,
        got_name,
    ) = self._ld_generate_got_region(0xDEADBEEF + 0x30000, 0x1000)
    regions.append(got_region)
    sections.append(self._ld_generate_got_section(got_name))
    return regions, sections