Opened 10 years ago

Last modified 13 months ago

#47776 new enhancement

ld64 @2 Add wrapper script to select compatible linker

Reported by: steve+macports@… Owned by: jeremyhu (Jeremy Huddleston Sequoia)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: larryv (Lawrence Velázquez), cooljeanius (Eric Gallager)
Port: ld64

Description

Introduction

It could be useful to add a wrapper script to switch between ld64 versions depending on the supplied arguments.

In particular, ld64-127 or ld64-97 are required for ppc but in general it is preferable to use a more recent version.

Since ld64 already supports multiple architectures, it isn't especially subversive to wrap it in a script that extends that support to legacy architectures.

I'm attaching a script that calls ld-97 for ppc on 10.4 and earlier, ld-127 for ppc on 10.5 and ld-latest otherwise. It inserts the list of supported ppc architectures on stderr when called as ld -v.

I haven't integrated the script with MacPorts yet, but I imagine it is possible to add as an additional subport and/or variant of ld64, with dependencies on existing subports.

Analysis

This isn't such a big deal for gcc since each architecture has a separate toolchain, into which the correct ld can be symlinked.

There are also mechanisms in clang for choosing which ld will be used:

  1. Create a separate toolchain in a similar way to what gcc does, eg under /usr/local/powerpc-apple-darwin10-llvm-3.6. If ld exists in the same directory as clang, it will be found.
  2. Use COMPILER_PATH or -B to specify a path to search for ld.
  3. Call clang -target powerpc-apple-macosx10.4 instead of clang -arch ppc -mmacosx-version-min=10.4 and symlink powerpc-apple-macosx10.4-ld to ld-97.

Unfortunately none of these solutions works seamlessly when you want to build a universal binary - in each case it would be necessary to build a ppc binary separately and then call lipo yourself instead of letting clang do it for you (the -B and -target options cannot be set per-arch with -Xarch_ppc etc).

One possible workaround for universal builds is to choose the linker based on the minimum supported version, rather than the supported archs - ie to support 10.4+ use ld-97, for 10.5+ use ld-127 etc. This approach is compatible with COMPILER_PATH or -B, it's just necessary to create a directory for each linker version so it can be symlinked as simply ld.

Attachments (2)

ld-hybrid.2 (1.1 KB) - added by steve+macports@… 10 years ago.
ld-hybrid (1.1 KB) - added by steve+macports@… 10 years ago.

Download all attachments as: .zip

Change History (6)

Changed 10 years ago by steve+macports@…

Attachment: ld-hybrid.2 added

comment:1 Changed 10 years ago by larryv (Lawrence Velázquez)

Cc: larryv@… added

Cc Me!

comment:2 Changed 10 years ago by mf2k (Frank Schima)

Owner: changed from macports-tickets@… to jeremyhu@…
Version: 2.3.3

In the future, please Cc the port maintainers (port info --maintainers ld64), if any.

comment:3 Changed 10 years ago by steve+macports@…

Attaching an updated script that uses process substitution as a simpler way of filtering stderr.

In the future, please Cc the port maintainers (port info --maintainers ld64), if any.

Ok, will do. Also sorry about posting two copies of my script initially - must have somehow managed to double-click the submit button.

Changed 10 years ago by steve+macports@…

Attachment: ld-hybrid added

comment:4 Changed 13 months ago by cooljeanius (Eric Gallager)

Cc: cooljeanius added
Note: See TracTickets for help on using tickets.