idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.46k stars 368 forks source link

FFI: segfault for conflicting names in C++ #3263

Open joelberkeley opened 2 months ago

joelberkeley commented 2 months ago

This is a complex one. I'm not sure if it's a bug in Idris, Bazel (the build system), or my use of Bazel, but ohad asked me to raise an issue for visibility. If it's not useful, feel free to close.

In this mwe repo I create two functions to index into an int* in C++. They are identical except the names. One is my_index, the other index.

When I run this code, the call to index segfaults before it enters the C function. This might be because there is an existing POSIX function index. However, in my much larger project, I was not seeing an error until I made a large change to a lot of code but not that function (I did change build files, I'm not sure how relevant that is). Also, when I list targets in my shared lib with nm -D, I don't see a definition for index if I omit that function. Unfortunately nm doesn't give me the function signature.

Curiously, when making the mwe, I discovered I can't reproduce this with gcc/g++, as they complain about conflicting declarations of index.