Dynamic libraries do not load in dlopen under FreeBSD

Summary

Under FreeBSD, FPC seems to add envp parameter to the linked shared object library, which is not handled correctly by dlopen function. The bug is not reproducible on Linux.

System Information

  • Operating system: FreeBSD 12/13 (Possibly older as well)
  • Processor architecture: x86-64
  • Compiler version: 3.2.2
  • Device: Computer

Steps to reproduce

Compile any library under FreeBSD, try to load it with dlopen.

Example Project

https://github.com/PerlFFI/FFI-Platypus-Lang-Pascal

Issue: https://github.com/PerlFFI/FFI-Platypus-Lang-Pascal/issues/17

Probably related: https://github.com/zamronypj/mod_pascal/issues/1

What is the current bug behavior?

dlopen call fails with t/ffi/libtest.so: Undefined symbol "operatingsystem_parameter_envp". Makes any application using dlopen incompatible with FPC dynamic libraries.

What is the expected (correct) behavior?

dlopen handles shared object library correctly.

Relevant logs and/or screenshots

# nm -g -P -D libtest.so
Add T 0000000000010130 0000000000000005
operatingsystem_parameter_argc U
operatingsystem_parameter_argv U
operatingsystem_parameter_envp U

Possible fixes

Edited by bbrtj