This executable https://people.freebsd.org/~yuri/hello_world was built by the ghdl project (VHDL simulator). Based on its manpage environ(7) it doesn't require any shared libraries. This symbol should be just available. But it looks for 'environ' in /lib/libc.so.7 and fails: > $ ./hello_world > ld-elf.so.1: /lib/libc.so.7: Undefined symbol "environ"
FreeBSD 13.1
How was the binary built? It appears like you might be using a non-standard linking option like -nostdlib, which prevented the standard C runtime (crt1.o, built from lib/csu) from getting linked. (there are some other options that can inhibit the use of standard C runtime startup routines, but you would want to look at how the binary was linked)
environ is provided by csu indeed. It must be linked in and exported.
The executable is linked with .ver file: -Wl,--version-script=/usr/local/lib/ghdl/grt.ver ANY { global: vpi_chk_error; vpi_control; vpi_free_object; vpi_get; vpi_get_str; vpi_get_time; vpi_get_value; vpi_get_vlog_info; vpi_handle; vpi_handle_by_index; vpi_handle_by_name; vpi_iterate; vpi_mcd_close; vpi_mcd_name; vpi_mcd_open; vpi_put_value; vpi_register_cb; vpi_register_systf; vpi_remove_cb; vpi_scan; vpi_vprintf; vpi_printf; vhpi_register_cb; vhpi_remove_cb; vhpi_disable_cb; vhpi_enable_cb; vhpi_get_cb_info; vhpi_handle_by_name; vhpi_handle_by_index; vhpi_handle; vhpi_iterator; vhpi_scan; vhpi_get; vhpi_get_str; vhpi_get_real; vhpi_get_phys; vhpi_protected_call; vhpi_get_value; vhpi_put_value; vhpi_schedule_transaction; vhpi_format_value; vhpi_get_time; vhpi_get_next_time; vhpi_control; vhpi_printf; vhpi_vprintf; vhpi_is_printable; vhpi_compare_handles; vhpi_check_error; vhpi_release_handle; vhpi_create; vhpi_register_foreignf; vhpi_get_foreignf_info; vhpi_get_data; vhpi_put_data; local: *; };
The problem goes away when this argument is removed.
I can reproduce this issue with a minimal codes: #include <stdlib.h> #include <stdio.h> int main() { puts(getenv("PATH")); } > $ clang -lutil -pg a.c > $ ./a.out ld-elf.so.1: /lib/libc.so.7: Undefined symbol "environ"
(In reply to AN Long from comment #6) I can't seem to be able to reproduce this issue on main built on March 31. $ clang --version FreeBSD clang version 17.0.6 (https://github.com/llvm/llvm-project.git llvmorg-17.0.6-0-g6009708b4367) Target: x86_64-unknown-freebsd15.0 Thread model: posix InstalledDir: /usr/bin $ clang -lutil -pg a.c $ ./a.out /sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin
(In reply to Xin LI from comment #7) Sorry, I forgot to post the environment information. I'm using FreeBSD13: > $ uname > FreeBSD f13 13.3-RELEASE FreeBSD 13.3-RELEASE releng/13.3-n257428-80d2b634ddf0 GENERIC amd64 > $ clang --version > FreeBSD clang version 17.0.6 (https://github.com/llvm/llvm-project.git > llvmorg-17.0.6-0-g6009708b4367) > Target: x86_64-unknown-freebsd13.3 > Thread model: posix > InstalledDir: /usr/bin I testes it on x86_64, but other people can reproduce this problem in arm64, see: https://github.com/python/cpython/issues/114453#issuecomment-2032044151