[Bug 268518] Undefined symbol error when building shared library with environ(7)

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 22 Dec 2022 22:26:52 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=268518

            Bug ID: 268518
           Summary: Undefined symbol error when building shared library
                    with environ(7)
           Product: Base System
           Version: 13.1-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: triaxx@NetBSD.org

Considering the simple 'foo.c' file:
| extern char **environ;
| 
| int foo(int a)
| {
|   if (environ)
|   {
|     return 1;
|   }
|   return 0;
| }

and a Makefile to build a shared library from it:
| CC=clang -v
| 
| foo.o: foo.c
|         $(CC) -c -Wall -Werror -fPIC -o $@ $?
| 
| libfoo.so: foo.o
|         $(CC) -Wl,--no-undefined -shared -o $@ $?

The following error occurs:
| $ make libfoo.so
| clang -v -c -Wall -Werror -fPIC -o foo.o foo.c
| FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git
llvmorg-13.0.0-0-| gd7b669b3a303)
| Target: x86_64-unknown-freebsd13.1
| Thread model: posix
| InstalledDir: /usr/bin
|  (in-process)
|  "/usr/bin/clang" -cc1 -triple x86_64-unknown-freebsd13.1 -emit-obj
-mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier
-discard-value-names -main-file-name foo.c -mrelocation-model pic -pic-level 2
-fhalf-no-semantic-interposition -mframe-pointer=all -fno-rounding-math
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic
-debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/triaxx -resource-dir
/usr/lib/clang/13.0.0 -Wall -Werror -fdebug-compilation-dir=/home/triaxx
-ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig
-D__GCC_HAVE_DWARF2_CFI_ASM=1 -o foo.o -x c foo.c
| clang -cc1 version 13.0.0 based upon LLVM 13.0.0 default target
x86_64-unknown-freebsd13.1
| #include "..." search starts here:
| #include <...> search starts here:
|  /usr/lib/clang/13.0.0/include
|  /usr/include
| End of search list.
| clang -v -Wl,--no-undefined -shared -o libfoo.so foo.o
| FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git
llvmorg-13.0.0-0-gd7b669b3a303)
| Target: x86_64-unknown-freebsd13.1
| Thread model: posix
| InstalledDir: /usr/bin
|  "/usr/bin/ld" --eh-frame-hdr -Bshareable --hash-style=both
--enable-new-dtags -o libfoo.so /usr/lib/crti.o /usr/lib/crtbeginS.o -L/usr/lib
--no-undefined foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc
--as-needed -lgcc_s --no-as-needed /usr/lib/crtendS.o /usr/lib/crtn.o
| ld: error: undefined symbol: environ
| >>> referenced by foo.c
| >>>               foo.o:(foo)
| clang: error: linker command failed with exit code 1 (use -v to see
invocation)
| *** Error code 1
| 
| Stop.
| make: stopped in /home/triaxx

I noticed that environ symbol seems to be undefined in libc:
| $ readelf -s /lib/libc.so.7 | grep environ
|      2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND environ
while it seems to be present on other systems like Linux or NetBSD.

This issue produces a build error for Pulseaudio 16.1.

-- 
You are receiving this mail because:
You are the assignee for the bug.