Bug #48318 [Fbk->NoF]: CLI doesn't build and embed SAPI doesn't load on OS X
| From: | php-bugs at lists dot php dot net | Date: | Mon, 18 Feb 2013 00:33:57 +0000 |
| Subject: | Bug #48318 [Fbk->NoF]: CLI doesn't build and embed SAPI doesn't load on OS X | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176741@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=48318&edit=1
ID: 48318
Updated by: php-bugs@lists.php.net
Reported by: valeriy dot zamarayev at gmail dot com
Summary: CLI doesn't build and embed SAPI doesn't load on OS X
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Compile Failure
Operating System: Mac OSX
PHP Version: 5.*, 6CVS (2009-07-09)
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-06-29 14:13:25] 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/libphp5.so, can't link with
bundle (MH_BUNDLE) only dylibs (MH_DYLIB).
For more information, please, see this thread on stackoverflow;
http://bit.ly/av8Oie
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?
------------------------------------------------------------------------
[2010-06-08 15:40:58] tony2001@php.net
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2009-05-18 20:05:57] 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'
program.
------------------------------------------------------------------------
[2009-05-18 18:47:37] jani@php.net
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 18:34:42] valeriy dot zamarayev at gmail dot com
Description:
------------
Attempting to configure and build PHP with ./configure --enable-
maintainer-ztc --enable-debug --enable-embed
1) fails to build CLI
2) the resulting libphp.so 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 libphp5.so 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
code.
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 libphp5.so 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:
Index: configure.in
===================================================================
RCS file: /repository/php-src/configure.in,v
retrieving revision 1.579.2.52.2.77.2.51
diff -u -u -r1.579.2.52.2.77.2.51 configure.in
--- configure.in 6 May 2009 18:57:45 -0000
1.579.2.52.2.77.2.51
+++ configure.in 18 May 2009 18:21:14 -0000
@@ -464,7 +464,8 @@
sys/utsname.h \
sys/ipc.h \
dlfcn.h \
-assert.h
+assert.h \
+crt_externs.h
],[],[],[
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
Index: ext/spl/spl_dllist.h
===================================================================
RCS file: /repository/php-src/ext/spl/spl_dllist.h,v
retrieving revision 1.1.2.4
diff -u -u -r1.1.2.4 spl_dllist.h
--- ext/spl/spl_dllist.h 31 Dec 2008 11:15:43 -0000
1.1.2.4
+++ 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;
PHP_MINIT_FUNCTION(spl_dllist);
Index: ext/spl/spl_fixedarray.h
===================================================================
RCS file: /repository/php-src/ext/spl/spl_fixedarray.h,v
retrieving revision 1.1.2.3
diff -u -u -r1.1.2.3 spl_fixedarray.h
--- ext/spl/spl_fixedarray.h 31 Dec 2008 11:15:43 -0000
1.1.2.3
+++ ext/spl/spl_fixedarray.h 18 May 2009 18:21:15 -0000
@@ -22,7 +22,7 @@
#ifndef SPL_FIXEDARRAY_H
#define SPL_FIXEDARRAY_H
-PHPAPI zend_class_entry *spl_ce_SplFixedArray;
+extern PHPAPI zend_class_entry *spl_ce_SplFixedArray;
PHP_MINIT_FUNCTION(spl_fixedarray);
Index: ext/spl/spl_heap.h
===================================================================
RCS file: /repository/php-src/ext/spl/spl_heap.h,v
retrieving revision 1.1.2.3
diff -u -u -r1.1.2.3 spl_heap.h
--- ext/spl/spl_heap.h 31 Dec 2008 11:15:44 -0000 1.1.2.3
+++ 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;
PHP_MINIT_FUNCTION(spl_heap);
Index: main/php.h
===================================================================
RCS file: /repository/php-src/main/php.h,v
retrieving revision 1.221.2.4.2.8.2.12
diff -u -u -r1.221.2.4.2.8.2.12 php.h
--- main/php.h 31 Dec 2008 11:15:47 -0000 1.221.2.4.2.8.2.12
+++ main/php.h 18 May 2009 18:21:16 -0000
@@ -263,7 +263,13 @@
#if !defined(PHP_WIN32)
#define PHP_SLEEP_NON_VOID
#define php_sleep sleep
+
+#if HAVE_CRT_EXTERNS_H
+#include <crt_externs.h>
+#define environ (*_NSGetEnviron())
+#else
extern char **environ;
+#endif
#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 1.1.2.4
diff -u -u -r1.1.2.4 php_getopt.h
--- main/php_getopt.h 31 Dec 2008 11:15:47 -0000 1.1.2.4
+++ main/php_getopt.h 18 May 2009 18:21:16 -0000
@@ -41,7 +41,7 @@
BEGIN_EXTERN_C()
/* 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);
END_EXTERN_C()
Index: sapi/cli/config.m4
===================================================================
RCS file: /repository/php-src/sapi/cli/config.m4,v
retrieving revision 1.22.2.1.2.1.2.1
diff -u -u -r1.22.2.1.2.1.2.1 config.m4
--- sapi/cli/config.m4 1 Sep 2008 13:15:31 -0000
1.22.2.1.2.1.2.1
+++ 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
\$(PHP_RPATHS) \$(PHP_GLOBAL_OBJS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS)
\$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
fi
;;
- *darwin*)
- BUILD_CLI="\$(CC) \$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS)
\$(EXTRA_LDFLAGS_PROGRAM) \$(LDFLAGS) \$(NATIVE_RPATHS)
\$(PHP_GLOBAL_OBJS:.lo=.o) \$(PHP_CLI_OBJS:.lo=.o) \$(PHP_FRAMEWORKS)
\$(EXTRA_LIBS) \$(ZEND_EXTRA_LIBS) -o \$(SAPI_CLI_PATH)"
- ;;
*netware*)
BUILD_CLI="\$(LIBTOOL) --mode=link \$(CC) -export-dynamic
\$(CFLAGS_CLEAN) \$(EXTRA_CFLAGS) \$(EXTRA_LDFLAGS_PROGRAM)
\$(LDFLAGS) \$(PHP_RPATHS) \$(PHP_CLI_OBJS) \$(EXTRA_LIBS)
\$(ZEND_EXTRA_LIBS) -Lnetware -lphp5lib -o \$(SAPI_CLI_PATH)"
;;
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48318&edit=1