Skip to content

hints/darwin.sh: skip ldflags in lddlflags #23227

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

Open
wants to merge 4 commits into
base: blead
Choose a base branch
from

Conversation

sevan
Copy link
Contributor

@sevan sevan commented Apr 27, 2025

It has not effect.
"adopting flags from ldflags is supposed to happen in Configure, not in hints." - leont

Configuring a build of perl with -Aappend:ldflags=" -L/var/empty" and checking the output of 'perl -V:ldflags -V:lddlflags' shows

ldflags=' -L/var/empty';
lddlflags='-bundle -undefined dynamic_lookup -L/var/empty';

Found when analysing issue #9437
Tested on OS X 10.4 aka Darwin 8.

It has not effect.
"adopting flags from ldflags is supposed to happen in Configure, not in
hints." - leont

Configuring a build of perl with -Aappend:ldflags=" -L/var/empty"
and checking the output of 'perl -V:ldflags -V:lddlflags' shows

ldflags=' -L/var/empty';
lddlflags='-bundle -undefined dynamic_lookup -L/var/empty';

Found when analysing issue Perl#9437
Tested on OS X 10.4 aka Darwin 8.
@tonycoz
Copy link
Contributor

tonycoz commented Apr 28, 2025

Introduces a bunch of link warnings, from github builds:

ld: warning: object file (/Users/runner/work/perl5/perl5/cpan/Compress-Raw-Bzip2/Bzip2.o) was built for newer 'macOS' version (14.7) than being linked (14.0)
ld: warning: object file (/Users/runner/work/perl5/perl5/cpan/Compress-Raw-Bzip2/blocksort.o) was built for newer 'macOS' version (14.7) than being linked (14.0)

locally:

ld: warning: object file (/Users/tony/dev/perl/git/perl/dist/PathTools/Cwd.o) was built for newer 'macOS' version (15.4) than being linked (15.0)
ld: warning: object file (/Users/tony/dev/perl/git/perl/ext/B/B.o) was built for newer 'macOS' version (15.4) than being linked (15.0)

@sevan
Copy link
Contributor Author

sevan commented Apr 28, 2025

Just as a test, can you try the following patch locally?

--- a/hints/darwin.sh
+++ b/hints/darwin.sh
@@ -304,6 +304,7 @@ case "$osvers" in  # Note: osvers is the kernel version, not the 10.x
     [1-9][0-9].*)
       add_macosx_version_min ccflags $MACOSX_DEPLOYMENT_TARGET
       add_macosx_version_min ldflags $MACOSX_DEPLOYMENT_TARGET
+      add_macosx_version_min lddlflags $MACOSX_DEPLOYMENT_TARGET
       ;;
     '')
       # Empty MACOSX_DEPLOYMENT_TARGET is okay.

@tonycoz
Copy link
Contributor

tonycoz commented Apr 28, 2025

That didn't improve matters, nor did adding it further down as well:

diff --git a/hints/darwin.sh b/hints/darwin.sh
index e889824b7c..b766548e55 100644
--- a/hints/darwin.sh
+++ b/hints/darwin.sh
@@ -304,6 +304,7 @@ case "$osvers" in  # Note: osvers is the kernel version, not the 10.x
     [1-9][0-9].*)
       add_macosx_version_min ccflags $MACOSX_DEPLOYMENT_TARGET
       add_macosx_version_min ldflags $MACOSX_DEPLOYMENT_TARGET
+      add_macosx_version_min lddlflags $MACOSX_DEPLOYMENT_TARGET
       ;;
     '')
       # Empty MACOSX_DEPLOYMENT_TARGET is okay.
@@ -330,6 +331,7 @@ EOM
     [1-9][0-9].*)
       add_macosx_version_min ccflags $prodvers
       add_macosx_version_min ldflags $prodvers
+      add_macosx_version_min lddlflags $prodvers
       ;;
     *)
       cat <<EOM >&4

Configure reported it added it:

Which of these apply, if any? [darwin]  
Adding -mmacosx-version-min=15.4 to ccflags
Adding -mmacosx-version-min=15.4 to ldflags
Adding -mmacosx-version-min=15.4 to lddlflags
Operating system name? [darwin]  

but it didn't end up in config.sh:

tony@hermes perl % grep lddlflags config.sh 
lddlflags='-bundle -undefined dynamic_lookup -fstack-protector-strong'
tony@hermes perl % uname -a
Darwin hermes.local 24.4.0 Darwin Kernel Version 24.4.0: Wed Mar 19 21:17:25 PDT 2025; root:xnu-11417.101.15~1/RELEASE_ARM64_T6020 arm64
...
"../../miniperl" "-I../../lib" "../../lib/ExtUtils/xsubpp"  -typemap '/Users/tony/dev/perl/git/perl/dist/PathTools/../../lib/ExtUtils/typemap'  Cwd.xs > Cwd.xsc
mv Cwd.xsc Cwd.c
/Users/tony/dev/perl/git/perl/dist/PathTools/../../miniperl "-I../../lib" -MExtUtils::Command::MM -e 'cp_nonempty' -- Cwd.bs ../../lib/auto/Cwd/Cwd.bs 644
cc -c   -fno-common -DPERL_DARWIN -mmacosx-version-min=15.4 -DNO_THREAD_SAFE_QUERYLOCALE -DNO_POSIX_2008_LOCALE -DHAS_BROKEN_LANGINFO_CODESET -DNO_LOCALE_COLLATE -fno-strict-aliasing -pipe -fstack-protector-strong -Wall -Werror=pointer-arith -Werror=vla -Wextra -Wno-long-long -Wno-declaration-after-statement -Wc++-compat -Wwrite-strings -Wno-error=implicit-function-declaration -O3   -DVERSION=\"3.94\" -DXS_VERSION=\"3.94\"  "-I../.."  -DDOUBLE_SLASHES_SPECIAL=0 Cwd.c
rm -f ../../lib/auto/Cwd/Cwd.bundle
cc  -bundle -undefined dynamic_lookup -fstack-protector-strong  Cwd.o  -o ../../lib/auto/Cwd/Cwd.bundle  \
              \

ld: warning: object file (/Users/tony/dev/perl/git/perl/dist/PathTools/Cwd.o) was built for newer 'macOS' version (15.4) than being linked (15.0)
chmod 755 ../../lib/auto/Cwd/Cwd.bundle

Tested with after git clean -dxfq

@sevan
Copy link
Contributor Author

sevan commented Apr 29, 2025

Thanks for checking. I'll dig a bit more over the next couple of days & report back.

sevan added 3 commits April 29, 2025 15:11
So it can be appended, otherwise it just hardcodes lddlflags="-bundle -undefined dynamic_lookup"
Make sure MACOSX_DEPLOYMENT_TARGET is added to $lddlflags.
Need to be explicit with OS' for macOS 11 and up here. Otherwise:
Unexpected MACOSX_DEPLOYMENT_TARGET=11
Unless MACOSX_DEPLOYMENT_TARGET is passed into the build, just ride
the defaults of the OS' toolchain.
This code assumes OS X versioning (10.15.x ) and tries to drop the patch version
from the product version so that you're targetting macOS 10.15, rather
than 10.15.1. Unfortunately with macOS 11 and up, it ends up targetting
the patch version and since we're no longer appending $ld to $lddlflags
we end up with the core targetting the major version and the modules
targetting the patch version. Resulting in warnings
ld: warning: object file (/Users/runner/work/perl5/perl5/cpan/Compress-Raw-Bzip2/Bzip2.o) was built for newer 'macOS' version (14.7) than being linked (14.0)
@sevan
Copy link
Contributor Author

sevan commented Apr 29, 2025

I think we're good now. The only warning from the linker is ld: warning: -force_flat_namespace is no longer supported, using -flat_namespace instead now in the latest build logs from the github runner.
I don't think this is related to my changes since it's added in via Makefile.SH, which I haven't touched.

I looked into into and it looks like the warning was added sometime after macOS 10.15 (macOS 11?) but I don't have anything running macOS 11 to 13 in order to point to the specific version.

@sevan
Copy link
Contributor Author

sevan commented Apr 29, 2025

Built with ./Configure -des -Dusethreads -Duseshrplib -Dusedevel -DDEBUGGING -Dprefix=somepath && make && make test

Tested this patch on OS X 10.4/i386 shouldn't have affected anything there since MACOSX_DEPLOYMENT_TARGET is set to 10.3 explicitly, but just in case. Built successfully & test passed. No warnings from linker.
Tested on OS X 10.5/i386 where this change does have an impact. Built successfully & test passed. No warnings from linker.
Unable to build on 10.5 & target 10.4 due to a longstanding issue (described here) unrelated to the changes here but suffice to say trying to target 10.4 when building on 10.5 failed due to
ld: -rpath can only be used when targetting Mac OS X 10.5 or later

Tested on macOS 10.15/x86_64. Built successfully & test passed. No warnings from linker.
otool -l perl shows among the output:

Load command 10
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform MACOS
    minos 10.15
      sdk 10.15.6
   ntools 1
     tool LD
  version 609.8

Tested on macOS 10.15 with MACOSX_DEPLOYMENT_TARGET set to 10.14. Built successfully & test passed, but there are a couple of warnings during the test suite run.

env MACOSX_DEPLOYMENT_TARGET=10.14 ./Configure -des -Dusethreads -Duseshrplib -Dusedevel -Dprefix=somepath && make && make test

During the configure stage, Configure reports

Adding -mmacosx-version-min=10.14 to ccflags
Adding -mmacosx-version-min=10.14 to ldflags
Adding -mmacosx-version-min=10.14 to lddlflags

otools -l perl reported

Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 10.14
      sdk 10.15.6
   ntools 1
     tool 3
  version 609.8

When running the test suite

dist/ExtUtils-CBuilder/t/03-cplusplus ............................ ld: warning: object file (compilet-dd7tK.o) was built for newer macOS version (10.15) than being linked (10.14)
ld: warning: object file (t/cplust.o) was built for newer macOS version (10.15) than being linked (10.14)
cpan/ExtUtils-MakeMaker/t/04-xs-rpath-darwin ..................... Warning: -L./mylib changed to -L/somepath/perl5/cpan/ExtUtils-MakeMaker/t/fmd4vh32U0/./mylib
ld: warning: dylib (/somepath/perl5/cpan/ExtUtils-MakeMaker/t/fmd4vh32U0/mylib/libmylib.dylib) was built for newer macOS version (10.15) than being linked (10.14)

I suspect these are bugs in the tests, which this change has brought to light, rather than fallout due to the change.

@tonycoz
Copy link
Contributor

tonycoz commented Apr 30, 2025

longstanding issue (described here) unrelated to the changes

Is there an open ticket for this?

Copy link
Contributor

@tonycoz tonycoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look reasonable to me:

  • it builds fine on current versions of macos (the most common case)
  • you've tested it on some older macos, and built successfully

I wouldn't mind some second opinions though

@sevan
Copy link
Contributor Author

sevan commented Apr 30, 2025

longstanding issue (described here) unrelated to the changes

Is there an open ticket for this?

There's mattn/p5-Devel-CheckLib#40

@sevan
Copy link
Contributor Author

sevan commented Apr 30, 2025

But ExtUtils::MakeMaker needs a bug report too. It's not just Devel::CheckLib which creates breaks targeting 10.4 and older.

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

Successfully merging this pull request may close these issues.

2 participants