Skip to content
The Chat Archive
claude-2.1· Anthropic Arena Human Preference 55K

How can I fix "call to function lacks nop, can't restore toc;" ld error

  1. User

    How can I fix "call to function lacks nop, can't restore toc;" ld error

  2. Assistant

    Here are a few things you can try to fix the "call to function lacks nop, can't restore toc;" linker error:

    1. Add a nop instruction before any call instructions that are generating this error. On PowerPC, a nop is needed to provide space for the linker to insert a toc restore instruction.
    nop
    bl some_function
    
    1. If you are calling C functions from assembly, make sure you are following the proper ABI conventions for preserving and restoring the toc pointer. You may need to save off the toc pointer at the start of the function and restore it at the end.

    2. Enable the linker option -relax if building for PowerPC. This will allow the linker more flexibility with inserting toc restore instructions.

    3. Make sure all object files and libraries you are linking were compiled with consistent ABI conventions regarding the toc pointer. Mixing toc models can cause this type of error.

    4. If linking C and C++ code, use extern "C" to ensure C linkage and compatibility with the standard C ABI.

    5. As a last resort, you can disable toc optimization entirely in the linker using -bno-toc-optimize. But this may have performance implications.

    Pay close attention to places where you transition from one compilation unit to another, like calls between functions. The linker needs to be able to insert toc restore instructions at these boundaries.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.