Bug #6576

shared library references _environ macosx Lion

Added by Daniel Kopetzky over 2 years ago. Updated over 2 years ago.

[ruby-core:45568]
Status:Closed
Priority:Normal
Assignee:Motohiro KOSAKI
ruby -v:ruby 2.0.0dev (2012-06-10) [x86_64-darwin11.4.0] Backport:

Description

The code in missing/setproctitle.c references the global variable environ.
The environ global variable isn't allowed in mac dylib shared libraries.
Code trying to use ruby-2 as a shared library will fail.

% nm libruby.dylib|grep _environ
U _environ

The code in hash.c has #ifdef APPLE sections that appear to access
the environment using Apple's suggested _NSGetEnviron() routine.

Associated revisions

Revision 36151
Added by Nobuyoshi Nakada over 2 years ago

setproctitle.c: _NSGetEnviron

  • missing/setproctitle.c (environ): use (*_NSGetEnviron()) instead of environ on Darwin for namespace cleanness, same as . [Bug #6576]

Revision 36151
Added by Nobuyoshi Nakada over 2 years ago

setproctitle.c: _NSGetEnviron

  • missing/setproctitle.c (environ): use (*_NSGetEnviron()) instead of environ on Darwin for namespace cleanness, same as . [Bug #6576]

History

#1 Updated by Motohiro KOSAKI over 2 years ago

  • Status changed from Open to Assigned
  • Assignee set to Motohiro KOSAKI

#2 Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Assigned to Feedback

=begin
Actually it doesn't fail.

$ uname -svr
Darwin 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr 9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64

$ otool -L /usr/local/bin/ruby
/usr/local/bin/ruby:
@executable_path/../lib/libruby.2.0.0.dylib (compatibility version 2.0.0, current version 2.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

$ /usr/local/bin/ruby -e '$0 = "x"*100; system("ps", $$.to_s)'
PID TT STAT TIME COMMAND
77027 s002 S+ 0:00.02 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Or do you talking about future versions?
=end

#3 Updated by Daniel Kopetzky over 2 years ago

I'll investigate further.
Had recently enabled ruby scripting in vim 7.3.548 and I got the following message

% /usr/local/bin/vim
dyld: Symbol not found: _environ
Referenced from: /usr/local/lib/libruby.2.0.0.dylib
Expected in: flat namespace
in /usr/local/lib/libruby.2.0.0.dylib
Trace/BPT trap

Thats when I went reading your code / reading apple documentation and saw how hash.c was avoiding
direct reference to environ but missing/setproctitle.c wasn't doing anything special.

% otool -L /usr/local/bin/vim
src/vim:
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/local/lib/libintl.8.dylib (compatibility version 10.0.0, current version 10.1.0)
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 17.0.0)
/usr/local/lib/libruby.2.0.0.dylib (compatibility version 2.0.0, current version 2.0.0)
/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 833.25.0)
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1138.47.0)

#4 Updated by Nobuyoshi Nakada over 2 years ago

Does /usr/local/bin/ruby fail too?
What does otool -L /usr/local/bin/ruby show?

#5 Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Feedback to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r36151.
Daniel, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


setproctitle.c: _NSGetEnviron

  • missing/setproctitle.c (environ): use (*_NSGetEnviron()) instead of environ on Darwin for namespace cleanness, same as . [Bug #6576]

Also available in: Atom PDF