|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48318 CLI doesn't build and embed SAPI doesn't load on OS X
Submitted: 2009-05-18 18:34 UTC Modified: 2013-02-18 00:33 UTC
Avg. Score:4.7 ± 0.7
Reproduced:19 of 19 (100.0%)
Same Version:16 (84.2%)
Same OS:19 (100.0%)
From: valeriy dot zamarayev at gmail dot com Assigned:
Status: No Feedback Package: Compile Failure
PHP Version: 5.*, 6CVS (2009-07-09) OS: Mac OSX
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: valeriy dot zamarayev at gmail dot com
New email:
PHP Version: OS:


 [2009-05-18 18:34 UTC] valeriy dot zamarayev at gmail dot com
Attempting to configure and build PHP with ./configure --enable-
maintainer-ztc --enable-debug --enable-embed
1) fails to build CLI
2) the resulting cannot be loaded in Darwin due to missing 
'environ' global variable.

Reproduce code:
Try to build on OS X 10.5.6 using

# ./buildconf
# ./configure --enable-maintainer-ztc --enable-debug --enable-embed
# make

Expected result:
The CLI binary is built successfully.
The library can be loaded using dlopen().

Actual result:
At the library link stage, multiple symbols are in conflict which
have to be declared 'extern' in their '*.h' files. Unlike ELF, with 
Darwin's Mach-O format, common symbols are not allowed by default. So 
ELF is forgiving but Mach-O is not with regard to missing 'extern' 
specifier on global variables. This happens in multiple places in PHP 

At the CLI link stage, an attempt is made to link .o files using CC, 
though during the compilation libtool is used, so the .o files are 
hidden in .libs subdirectires, and .lo files should be used.

If I correct this and do link successfully, the resulting CLI is fine, 
but the cannot be loaded on darwin because the symbol 
environ doesn't exist. (There is a function _NSGetEnviron() which 
returns it).

See the patch below for more details:

RCS file: /repository/php-src/,v
retrieving revision 1.579.
diff -u -u -r1.579.
---        6 May 2009 18:57:45 -0000       
+++        18 May 2009 18:21:14 -0000
@@ -464,7 +464,8 @@
 sys/utsname.h \
 sys/ipc.h \
 dlfcn.h \
+assert.h \
 #include <sys/param.h>
Index: ext/spl/spl_dllist.h
RCS file: /repository/php-src/ext/spl/spl_dllist.h,v
retrieving revision
diff -u -u -r1.1.2.4 spl_dllist.h
--- ext/spl/spl_dllist.h        31 Dec 2008 11:15:43 -0000
+++ ext/spl/spl_dllist.h        18 May 2009 18:21:15 -0000
@@ -24,9 +24,9 @@
 #include "php.h"
 #include "php_spl.h"
-PHPAPI zend_class_entry *spl_ce_SplDoublyLinkedList;
-PHPAPI zend_class_entry *spl_ce_SplQueue;
-PHPAPI zend_class_entry *spl_ce_SplStack;
+extern PHPAPI zend_class_entry *spl_ce_SplDoublyLinkedList;
+extern PHPAPI zend_class_entry *spl_ce_SplQueue;
+extern PHPAPI zend_class_entry *spl_ce_SplStack;
Index: ext/spl/spl_fixedarray.h
RCS file: /repository/php-src/ext/spl/spl_fixedarray.h,v
retrieving revision
diff -u -u -r1.1.2.3 spl_fixedarray.h
--- ext/spl/spl_fixedarray.h    31 Dec 2008 11:15:43 -0000
+++ ext/spl/spl_fixedarray.h    18 May 2009 18:21:15 -0000
@@ -22,7 +22,7 @@
-PHPAPI zend_class_entry *spl_ce_SplFixedArray;
+extern PHPAPI zend_class_entry *spl_ce_SplFixedArray;
Index: ext/spl/spl_heap.h
RCS file: /repository/php-src/ext/spl/spl_heap.h,v
retrieving revision
diff -u -u -r1.1.2.3 spl_heap.h
--- ext/spl/spl_heap.h  31 Dec 2008 11:15:44 -0000
+++ ext/spl/spl_heap.h  18 May 2009 18:21:15 -0000
@@ -24,11 +24,11 @@
 #include "php.h"
 #include "php_spl.h"
-PHPAPI zend_class_entry *spl_ce_SplHeap;
-PHPAPI zend_class_entry *spl_ce_SplMinHeap;
-PHPAPI zend_class_entry *spl_ce_SplMaxHeap;
+extern PHPAPI zend_class_entry *spl_ce_SplHeap;
+extern PHPAPI zend_class_entry *spl_ce_SplMinHeap;
+extern PHPAPI zend_class_entry *spl_ce_SplMaxHeap;
-PHPAPI zend_class_entry *spl_ce_SplPriorityQueue;
+extern PHPAPI zend_class_entry *spl_ce_SplPriorityQueue;
Index: main/php.h
RCS file: /repository/php-src/main/php.h,v
retrieving revision
diff -u -u -r1. php.h
--- main/php.h  31 Dec 2008 11:15:47 -0000
+++ main/php.h  18 May 2009 18:21:16 -0000
@@ -263,7 +263,13 @@
 #if !defined(PHP_WIN32)
 #define php_sleep sleep
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
 extern char **environ;
 #endif /* !defined(PHP_WIN32) */
 #ifdef PHP_PWRITE_64
Index: main/php_getopt.h
RCS file: /repository/php-src/main/php_getopt.h,v
retrieving revision
diff -u -u -r1.1.2.4 php_getopt.h
--- main/php_getopt.h   31 Dec 2008 11:15:47 -0000
+++ main/php_getopt.h   18 May 2009 18:21:16 -0000
@@ -41,7 +41,7 @@
 /* holds the index of the latest fetched element from the opts array 
-PHPAPI int php_optidx;
+extern PHPAPI int php_optidx;
 PHPAPI int php_getopt(int argc, char* const *argv, const opt_struct 
opts[], char **optarg, int *optind, int show_err, int arg_start);
Index: sapi/cli/config.m4
RCS file: /repository/php-src/sapi/cli/config.m4,v
retrieving revision
diff -u -u -r1. config.m4
--- sapi/cli/config.m4  1 Sep 2008 13:15:31 -0000
+++ sapi/cli/config.m4  18 May 2009 18:21:16 -0000
@@ -20,9 +20,6 @@
       BUILD_CLI="echo '\#! .' > php.sym && echo >>php.sym && nm -BCpg 
\`echo \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) | sed 's/\([A-Za-z0-
9_]*\)\.lo/\1.o/g'\` | \$(AWK) '{ if (((\$\$2 == \"T\") || (\$\$2 == 
\"D\") || (\$\$2 == \"B\")) && (substr(\$\$3,1,1) != \".\")) { print 
\$\$3 } }' | sort -u >> php.sym && \$(LIBTOOL) --mode=link \$(CC) -
export-dynamic \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) 
\$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) -Wl,-brtl -Wl,-bE:php.sym 
-  *darwin*)
-    ;;
     BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic 
\$(ZEND_EXTRA_LIBS) -Lnetware -lphp5lib -o \$(SAPI_CLI_PATH)"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-18 18:47 UTC]
Does this happen with PHP 5.2.9 ? That patch looks really awful. 
Something I'd never would want to commit since this all works absolutely 
fine on every other platform..
 [2009-05-18 20:05 UTC] valeriy dot zamarayev at gmail dot com
The patch fixes three problems:

1. Missing 'extern's (the only change which will be noticeable on platforms other than 
Darwin, and looking at the code I think they were just forgotten, most variables have 
it, but these few ones don't. Just to make sure it doesn't break anything with ELF I 
tried this on Centos 5.2 - all ok).

2. Some 'special' configuration for darwin, which prevented it from using GNU libtool 
(no effect on other platforms)

3. 'environ' variable. (no effect on other platforms either, as it only works if 
crt_externs.h is present - the fix taken from GCC source)

Maybe I should have submitted them all separately, so they don't look that awful to 
you? Anyway the patch is intended to show exact locations of the problems and 
suggested fixes, for the interested in OS X support in the upcoming 5.3, probably not 
for an immediate commit. Please treat it as an enhanced problem description.

As for 5.2.9, I stumbled across the unresolved #44462 issue, among the others, so I 
moved to 5.3, and I didn't try to load the .so but basically the environ issue is 
there anyway, as is the 'special' darwin build case, which breaks linking (looks like 
it was made long ago to avoid accidentally using the Darwin specific 'libtool' 
 [2010-06-08 15:40 UTC]
-Status: Open +Status: Feedback
 [2010-06-08 15:40 UTC]
Please try using this snapshot:
For Windows:

 [2010-06-29 14:13 UTC] alexk at commandprompt dot com
No, the original problem is still there, no matter what version
of PHP I test against (current 5.3.2, the snapshot from June 8th
or most recent PHP5.3.3RC1). I still can build with --disable-cli
passed at configure time, however the result is a bundle instead
of a shared library. On Mac OS X there are difference between the
two, in particular, it's impossible to link with -lphp5 against a
bundle. The error message is:

ld: in /usr/local/php5.3RC1//lib/, can't link with
bundle (MH_BUNDLE) only dylibs (MH_DYLIB).

For more information, please, see this thread on stackoverflow;

Both PHC (php compiler) and PL/PHP (PHP stored procedures for
PostgreSQL) seem to be affected by this on OS X.

Is there a reason why embed is built as a bundle ? Can it be
changed to the shared library (MH_DYNALIB) instead?
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 02:01:31 2023 UTC