Skip to content
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

please add support for darwin-xtools linkers on macOS #10805

Closed
grobian opened this issue Sep 11, 2022 · 12 comments · Fixed by #12747
Closed

please add support for darwin-xtools linkers on macOS #10805

grobian opened this issue Sep 11, 2022 · 12 comments · Fixed by #12747
Labels
compilers OS:macos Issues specific to Apple Operating Systems like MacOS and iOS

Comments

@grobian
Copy link
Contributor

grobian commented Sep 11, 2022

Describe the bug
meson fails immediately when darwin-xtools is in use, see https://github.com/iains/darwin-xtools and derivatives.

To Reproduce
https://bugs.gentoo.org/show_bug.cgi?id=868516

Expected behavior
Detect xtools as an ld64-based linker

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?
    native
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
    macOS
  • what Python version are you using e.g. 3.8.0
    3.10
  • what meson --version
    0.63.2
  • what ninja --version if it's a Ninja build
    1.11.1
@grobian
Copy link
Contributor Author

grobian commented Sep 11, 2022

possible patch could be:

--- a/mesonbuild/linkers/detect.py
+++ b/mesonbuild/linkers/detect.py
@@ -188,6 +188,11 @@
             v = search_version(o)

         linker = LLVMDynamicLinker(compiler, for_machine, comp_class.          LINKER_PREFIX, override, version=v)
+    # detect xtools first, bug #868516
+    elif 'xtools-' in o.split('\n')[0]:
+        xtools = o.split(' ')[0]
+        v = xtools.split('-')[1]
+        linker = AppleDynamicLinker(compiler, for_machine, comp_class.         LINKER_PREFIX, override, version=v)
     # first might be apple clang, second is for real gcc, the third is icc
     elif e.endswith('(use -v to see invocation)\n') or 'macosx_version' in e   or 'ld: unknown option:' in e:
         if isinstance(comp_class.LINKER_PREFIX, str):

@tristan957
Copy link
Contributor

tristan957 commented Sep 12, 2022

Is xtools a patch AppleDynamicLinker? I think it would make sense for it to be its own class. If you want support for it, you will probably need to put in the leg work yourself. There aren't many Apple users among the contributors and judging by the development pace in the xtools repo, there are even fewer xtools users!

@grobian
Copy link
Contributor Author

grobian commented Sep 13, 2022

xtools is meant to be compatible, it doesn't require changes to the compilers.

@thesamesam
Copy link
Contributor

Could you submit this as a proper PR please? The patch doesn't apply to 1.2.0_rc1 and it's going to bitrot otherwise

@dcbaker dcbaker added compilers OS:macos Issues specific to Apple Operating Systems like MacOS and iOS labels Jun 29, 2023
@tristan957
Copy link
Contributor

@thesamesam it would probably be a pretty simple rebase if you're interested in authoring a PR.

grobian added a commit to grobian/darwin-xtools that referenced this issue Jul 9, 2023
Some tools like (or just?) meson explicitly query the version string and
pattern to establish what kind of linker they are dealing with.  So
return a compatible string, such that those tools believe this is just
an Apple linker, which is for most intents and purposes exactly what we
want.

This is an alternative to getting meson to recognise xtools.
mesonbuild/meson#10805

See for the original problem:
https://bugs.gentoo.org/868516

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
@grobian
Copy link
Contributor Author

grobian commented Jul 9, 2023

I decided to fix the problem from out custom version of xtools's end.

@grobian grobian closed this as completed Jul 9, 2023
@grobian
Copy link
Contributor Author

grobian commented Jan 17, 2024

fixing xtools is not possible without changing its API/contract, so that's not really a preferred solution

@grobian grobian reopened this Jan 17, 2024
@eli-schwartz
Copy link
Member

Is xtools a patch AppleDynamicLinker? I think it would make sense for it to be its own class.

xtools is meant to be compatible, it doesn't require changes to the compilers.

If it's a drop-in compatible replacement and users aren't meant to distinguish between ld64 and xtools ld64, e.g. by using the meson code:

cc = meson.get_compiler('c')
linker_name = cc.get_linker_id()

if linker_name == 'ld64'
    ...
elif linker_name == 'xtools'
    ...
endif

then we don't need a distinct class for it.

@grobian
Copy link
Contributor Author

grobian commented Jan 17, 2024

I can confirm that I don't see anything at this point which would make it necessary to make that distinction between ld64 and xtools.

@eli-schwartz
Copy link
Member

eli-schwartz commented Jan 17, 2024

fixing xtools is not possible without changing its API/contract, so that's not really a preferred solution

For context, as discussed on bugs.gentoo.org, the reason for this seems to be:

indeed xtools is just an ld64 "fork" if you want, but it (for reasoning which are GNU) accepts --version. GCC knows very well how to operate with xtools (because it's like ld64).

And in meson, we handle Apple ld64 like this:

o, e = run_compiler_with('-Wl,--version')

elif e.endswith('(use -v to see invocation)\n') or 'macosx_version' in e or 'ld: unknown option' in e:

which means we cannot e.g. have xtools match Apple's output with:

if 'PROJECT:ld' in line or 'PROJECT:dyld' in line:

because we never re-run with -Wl,-v to accommodate Apple's peculiarity and get the "real" linker information -- and we cannot do so unless we stop supporting --version, which is silly.

@eli-schwartz
Copy link
Member

@grobian can you open a PR with the proposed fix

@grobian
Copy link
Contributor Author

grobian commented Jan 17, 2024

done in PR #12747

@eli-schwartz eli-schwartz linked a pull request Jan 18, 2024 that will close this issue
sthagen pushed a commit to sthagen/mesonbuild-meson that referenced this issue Jan 18, 2024
xtools is in use on Gentoo Prefix x86_64 and ppc based Darwin installs.
Pick it up as a valid linker.

Since xtools is answering with a version to --version, as opposed to
ld64, detection of xtools in the ld64 handling block is not possible,
since --version already succeeded.

Bug: https://bugs.gentoo.org/868516
Bug: mesonbuild#10805
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
nirbheek pushed a commit that referenced this issue Feb 6, 2024
xtools is in use on Gentoo Prefix x86_64 and ppc based Darwin installs.
Pick it up as a valid linker.

Since xtools is answering with a version to --version, as opposed to
ld64, detection of xtools in the ld64 handling block is not possible,
since --version already succeeded.

Bug: https://bugs.gentoo.org/868516
Bug: #10805
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilers OS:macos Issues specific to Apple Operating Systems like MacOS and iOS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants