Skip to content

Guard trampoline calls against backend symbols that failed to resolve - #16

Open
casparvl wants to merge 1 commit into
ocaisa:mainfrom
casparvl:fix-null-backend-symbols
Open

casparvl wants to merge 1 commit into
ocaisa:mainfrom
casparvl:fix-null-backend-symbols

Conversation

@casparvl

@casparvl casparvl commented Oct 5, 2026

Copy link
Copy Markdown

The problem: every generated MPI wrapper called through a function pointer without checking it. At startup the library looks up each symbol in the backend MPI library and only counts the ones it can't find. Calling one of those missing functions then dereferenced a NULL pointer and
crashed with a segfault and no message. This can happen with an older backend, or one built without the mpif patch, which lacks the MPI_*_f2c/c2f functions.

The fix (in trampi/emitter.py): each wrapper now checks the pointer before calling.

  • A function returning int returns MPI_ERR_UNSUPPORTED_OPERATION.
  • A void function just returns.
  • Any other return type, such as double MPI_Wtime, prints a TRAMPI:: message naming the missing function and aborts, since there is no sensible value to return.
  • The verbose-mode warning text now says this instead of "calls will fail".

Testing: I compiled a proxy against a backend with no MPI symbols. MPI_Barrier returned 55 (MPI_ERR_UNSUPPORTED_OPERATION) instead of crashing, and MPI_Wtime printed the message and aborted. The new unit test passes. pytest isn't installed here, so I ran only that test by hand, not
the full suite, and I haven't tried a real MPICH or Open MPI backend.

To open the PR:

The returned error code bypasses the MPI error handler, so an application relying on MPI_ERRORS_ARE_FATAL won't see the usual fatal behaviour. The abort for non-int return types is my judgement call.

Smaller problems I noticed but did not change (also listed in the PR text):

  • MPI_Pcontrol prints a message and returns success instead of forwarding the call.
  • The header parser only skips comment lines that start with /*, so a prototype-looking line inside a multi-line comment would be picked up as a real prototype.
  • The library aborts at load time if no backend is configured, even for programs that never call MPI.

Disclaimer: fully generated by Claude AI, at request of @ocaisa

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ocaisa

ocaisa commented Oct 5, 2026

Copy link
Copy Markdown
Owner

I think there is a better way that doesn't involve logic checks:

  • If the functions don't exist, create placeholder functions that hold the logic of your guards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants