Bug 269370 - environ(7) isn't found: /lib/libc.so.7: Undefined symbol "environ"
Summary: environ(7) isn't found: /lib/libc.so.7: Undefined symbol "environ"
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: 13.1-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: Yuri Victorovich
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-06 12:53 UTC by Yuri Victorovich
Modified: 2024-04-05 06:13 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yuri Victorovich freebsd_committer freebsd_triage 2023-02-06 12:53:01 UTC
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"
Comment 1 Yuri Victorovich freebsd_committer freebsd_triage 2023-02-06 12:54:02 UTC
FreeBSD 13.1
Comment 2 Xin LI freebsd_committer freebsd_triage 2023-02-13 00:35:40 UTC
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)
Comment 3 Konstantin Belousov freebsd_committer freebsd_triage 2023-02-14 01:23:29 UTC
environ is provided by csu indeed.  It must be linked in and exported.
Comment 4 Yuri Victorovich freebsd_committer freebsd_triage 2023-02-23 17:58:33 UTC
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:
	*;
};
Comment 5 Yuri Victorovich freebsd_committer freebsd_triage 2023-02-23 17:59:03 UTC
The problem goes away when this argument is removed.
Comment 6 AN Long 2024-04-02 13:38:38 UTC
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"
Comment 7 Xin LI freebsd_committer freebsd_triage 2024-04-04 05:54:00 UTC
(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
Comment 8 AN Long 2024-04-05 06:13:41 UTC
(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