Skip to content

Conversation

@kadler
Copy link
Contributor

@kadler kadler commented Feb 28, 2019

Makefiles for PHP extensions generated by phpize expect the PHP_MODULES to contain a list of libtool .la files so that it can read the $dlname variable from them by sourcing them in to a shell. On AIX, the code was setting PHP_MODULES to a list of .so files, which meant the dlname was blank, preventing the tests from being able to run.

Change the AIX code path in the PHP_SHARED_MODULE macro to match the output on other platforms, using libtool .la files.

@kadler kadler changed the title Fix shared module generation on AIX bug #77676 Fix #77676: shared module generation on AIX bug Feb 28, 2019
Makefiles for PHP extensions generated by phpize expect the PHP_MODULES
to contain a list of libtool .la files so that it can read the $dlname
variable from them by sourcing them in to a shell. On AIX, the code was
setting PHP_MODULES to a list of .so files, which meant the dlname was
blank, preventing the tests from being able to run.

Change the AIX code path in the PHP_SHARED_MODULE macro to match the
output on other platforms, using libtool .la files.
@nikic
Copy link
Member

nikic commented Feb 28, 2019

Apparently this code was originally introduced in 2005 by 8de3367.

I don't have any familiarity with AIX, so I'll just assume that this change is the right thing to do... @petk Do you have any input here?

@kadler
Copy link
Contributor Author

kadler commented Feb 28, 2019

In d4fd9a5, Makefile.global was change to read the extension name by reading in the $dlname field from the libtool .la file in PHP_MODULES make variable. This worked on all platforms but aix, darwin, and netware since those platforms did not have suffix=la in the PHP_SHARED_MODULE macro:

php-src/acinclude.m4

Lines 853 to 863 in d4fd9a5

*aix*[)]
suffix=so
link_cmd='$(LIBTOOL) --mode=link ifelse($4,,[$(CC)],[$(CXX)]) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) -Wl,-G -o '$3'/$1.la -export-dynamic -avoid-version -prefer-pic -module -rpath $(phplibdir) $(EXTRA_LDFLAGS) $($2) $(translit($1,a-z_-,A-Z__)_SHARED_LIBADD) && mv -f '$3'/.libs/$1.so '$3'/$1.so'
;;
*darwin*[)]
suffix=so
link_cmd='ifelse($4,,[$(CC)],[$(CXX)]) -dynamic -flat_namespace -bundle -undefined suppress $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) -o [$]@ $(EXTRA_LDFLAGS) $($2) $(translit($1,a-z_-,A-Z__)_SHARED_LIBADD)'
;;
*netware*[)]
suffix=nlm
link_cmd='$(LIBTOOL) --mode=link ifelse($4,,[$(CC)],[$(CXX)]) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) -o [$]@ -shared -export-dynamic -avoid-version -prefer-pic -module -rpath $(phplibdir) $(EXTRA_LDFLAGS) $($2) $(translit($1,a-z_-,A-Z__)_SHARED_LIBADD)'

It's likely that this was broken on these platforms before, because this line only works when the extension is .la:

'extension='`basename $(PHP_MODULES) .la`'.so'

This same issue was fixed for macOS in e46cd60 bug report and netware was never fixed, but rather support was removed in 2104bea.

@petk petk added the Bug label Feb 28, 2019
@petk
Copy link
Member

petk commented Feb 28, 2019

Hello, thanks for the patch. I think it sounds good to go. The .la files for libtool contain such info, yes so the .so files are wrong from how I understand that this should work. Probably no one has noticed this until now is because it fails only on the make test step. The .so files are binary files without things like dlname in them. Moving the shared objects at the end is from my understanding not needed, because these files get copied to such places elsewhere, so the fix is ok.

The '$3'/$1.la part is the same as [$]@ for all other systems (maybe we can sync that also here for AIX).

So, in the end, the only thing special and different for AIX systems is that -Wl,-G linker option. Probably it's needed for AIX systems.

@kadler
Copy link
Contributor Author

kadler commented Feb 28, 2019

The '$3'/$1.la part is the same as [$]@ for all other systems (maybe we can sync that also here for AIX).

I kind of figured that would work, but I was not sure (not a Makefile wizard). Due to the -Wl,-G option difference the two cases couldn't easily be combined, so I didn't bother checking.

So, in the end, the only thing special and different for AIX systems is that -Wl,-G linker option. Probably it's needed for AIX systems.

Yes, the -G enables a bunch of AIX ld features related to run-time linking.

Do you think it would be worthwhile to attempt to merge these two cases in some way since they only differ by that one flag? Perhaps we could just append the -Wl,-G to the end of the string instead of in the middle. This would prevent users from overriding the settings in $(EXTRA_LDFLAGS). I'm not sure that's a good or bad thing, though.

@petk
Copy link
Member

petk commented Mar 1, 2019

Yes, we can simplify that switch. Maybe something like this should work ok:

  case $host_alias in
    *aix*[)]
      additionalFlags="-Wl,-G"
      ;;
  esac

  link_cmd='$(LIBTOOL) --mode=link ifelse($4,,[$(CC)],[$(CXX)]) $(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) '$additionalFlags' -o [$]@ -export-dynamic -avoid-version -prefer-pic -module -rpath $(phplibdir) $(EXTRA_LDFLAGS) $($2) $(translit($1,a-z_-,A-Z__)_SHARED_LIBADD)'

@petk
Copy link
Member

petk commented Mar 2, 2019

Thank you @kadler, applied via 700f876 to PHP-7.2 and up.

@petk petk closed this Mar 2, 2019
@kadler kadler deleted the aix-shared-module branch March 6, 2019 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants