[Chapel Merge] Fix a bug in runtime code when building it for FreeBSD

Branch: refs/heads/main
Revision: ab9448daa43017d85c8b8f90693912ba5464f5f7
Author: dlongnecke-cray
Link: Fix a bug in runtime code when building it for FreeBSD by dlongnecke-cray · Pull Request #28770 · chapel-lang/chapel · GitHub
Log Message:
Fix a bug in runtime code when building it for FreeBSD (#28770)

This PR should hopefully fix a bug in nightly testing.

Apparently on FreeBSD it's not sufficient to just #define _GNU_SOURCE
and then #include <dlfcn.h>. You also need to make sure you #include <link.h> before you can get access to the definition of the Dl_info
type.

I originally had the idea to do this once in chpl-dynamic-loading.h
and then include that header, but that doesn't seem to work. It is
important that #define _GNU_SOURCE and #include <dlfcn.h> appear at
the top of the source file in order to get things working correctly.

Future work could consider writing runtime wrappers around dladdr and
Dl_info for extra portability (though they are standardized in POSIX
2024, if we wait long enough :D).

TESTING

  • CHPL_LLVM=none, CHPL_TARGET_COMPILER=gnu
  • CHPL_COMM=gasnet

Reviewed by @benharsh. Thanks much!

Compare: Comparing db2c97a9ec3bbd0360eee7e6304a5255e996ac9a...4cb84d276578516835a5ad5cf63601275e2b7122 · chapel-lang/chapel · GitHub

Diff:
M runtime/include/chpl-dynamic-loading.h
M runtime/src/chpl-dynamic-loading.c
M runtime/src/chpl-prginfo.c
M runtime/src/chpl-unwind.c
https://github.com/chapel-lang/chapel/pull/28770.diff