from typing import Optional


def _rewrite_elf_needed(dep: str) -> Optional[str]:
    """Rewrite an ELF DT_NEEDED dependency name.

    Args:
        dep: dependency name as it appears in ELF DT_NEEDED entry (e.g. 'libc.so')
    Returns:
        None if the dependency should be ignored, or the input dependency name,
        possibly rewritten for specific cases (e.g. 'libc.so' -> 'ld.so.1')
    """
    if dep == 'libzircon.so':
        # libzircon.so being injected by the kernel into user processes, it should
        # not appear in Fuchsia packages, and thus should be ignored.
        return None
    if dep == 'libc.so':
        # ld.so.1 acts as both the dynamic loader and C library, so any reference
        # to libc.so should be rewritten as 'ld.so.1'
        return 'ld.so.1'

    # For all other cases, just return the unmodified dependency name.
    return dep