Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined symbols for architecture x86_64: "_environ" #276

Closed
Schamschula opened this issue Jun 28, 2023 · 11 comments
Closed

Undefined symbols for architecture x86_64: "_environ" #276

Schamschula opened this issue Jun 28, 2023 · 11 comments

Comments

@Schamschula
Copy link

After the update to sudo 1.9.14 the MacPorts build bots found the following build error for macOS 10.6 (i386 and x86_64) and 10.7:

libtool: link: /usr/bin/clang -dynamiclib  -o .libs/sudo_intercept.so  .libs/exec_preload.o .libs/sudo_intercept.o .libs/sudo_intercept_common.o .libs/intercept.pb-c.o   -Wl,-force_load,../lib/protobuf-c/.libs/libprotobuf-c.a  -L/opt/local/lib ../lib/util/.libs/libsudo_util.dylib /opt/local/lib/libintl.dylib -lcrypto -ldl  -Wl,-headerpad_max_install_names -arch x86_64 -fstack-protector-all   -install_name  /opt/local/libexec/sudo/sudo_intercept.so  -Wl,-single_module
Undefined symbols for architecture x86_64:
  "_environ", referenced from:
      _my_system in sudo_intercept.o
      _my_execv in sudo_intercept.o
      _my_execvp in sudo_intercept.o
      _exec_wrapper in sudo_intercept.o
      _execl_wrapper in sudo_intercept.o
      _sudo_interposer_init in sudo_intercept_common.o
ld: symbol(s) not found for architecture x86_64

I worked around this with

https://github.com/macports/macports-ports/blob/master/sysutils/sudo/files/patch-environ.diff

However, I couldn't find any change between 1.9.13p3 and 1.9.14 to cause this issue, as 1.9.13p3 built cleanly on this platforms.

See: https://ports.macports.org/port/sudo/builds/

@millert
Copy link
Collaborator

millert commented Jun 28, 2023

I don't know of any code changes that would have caused this but in 1.9.14 the -no-undefined libtool flag is used on darwin. Perhaps that is causing the problem.

@Schamschula
Copy link
Author

No such problem on newer versions of macOS, even with this flag.

@millert
Copy link
Collaborator

millert commented Jun 28, 2023

Can you try backing out ae12d18 to see if that makes a difference? I don't have access macOS versions that old.

@Schamschula
Copy link
Author

Just for the record. My patch is only for macOS. The header file doesn't exist for other Apple OSs, e.g. iOS.

See: https://bug-gnulib.gnu.narkive.com/3IFzYnBv/environ-on-macos-x

I personally don't have access to older versions of macOS. MacPorts GitHub CI only supports macOS 11 - 13.

@millert
Copy link
Collaborator

millert commented Jun 28, 2023

It turns out I had an old macOS 10.6.8 hackintosh in the closet. I was able to reproduce the problem and verified that backing out ae12d18 avoids the issue.

@Schamschula
Copy link
Author

In other words ae12d18 could be modified to only apply to darwin 12 and above.

@millert
Copy link
Collaborator

millert commented Jun 28, 2023

Yes, exactly.

@Schamschula
Copy link
Author

Schamschula commented Jun 28, 2023

Perhaps a form of my patch might be a better solution, as it defines _environ for older macOS versions.

@millert
Copy link
Collaborator

millert commented Jun 28, 2023

Yes, the patch is needed to be able to actually use intercept mode and log_subcmds. The -no-undefined turns a run-time error into a link-time error so that is working as intended.

millert added a commit that referenced this issue Jun 28, 2023
macOS does not support direct access to the environ pointer from a
shared object.  We need to redirect through _NSGetEnviron() instead.
Fixes GitHub issue #276.
@millert
Copy link
Collaborator

millert commented Jun 28, 2023

Fixed by a0b074c

@millert millert closed this as completed Jun 28, 2023
@Schamschula
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants