Opened 7 months ago

Last modified 3 days ago

#73796 new defect

muniversal portgroup: Text file merging is broken on Tahoe

Reported by: TellowKrinkle Owned by:
Priority: Normal Milestone:
Component: ports Version: 2.12.4
Keywords: tahoe Cc: ryandesign (Ryan Carsten Schmidt), mascguy (Christopher Nielsen), johanmattssonm (Johan Mattsson), Dave-Allured (Dave Allured), MarcusCalhoun-Lopez (Marcus Calhoun-Lopez), bgilbert (Benjamin Gilbert), cooljeanius (Eric Gallager), fhgwright (Fred Wright), isolated-matrix, Iritscen
Port: muniversal, glib2

Description

muniversal relies on libtool failing when given non-macho objects: ​https://github.com/macports/macports-ports/blob/c4b129e884e2592023c601ac57de0cc5283bbf2e/_resources/port1.0/group/muniversal-1.1.tcl#L449

However starting with tahoe, that has been downgraded to a warning:

$ echo 0 > a.txt
$ echo 1 > b.txt
$ /usr/bin/libtool a.txt b.txt -o c.txt
libtool: warning: not a mach-o 'a.txt'
libtool: warning: not a mach-o 'b.txt'
$ file c.txt
c.txt: current ar archive random library

As a result, any port that tries to merge text files (e.g. glib2) ends up with empty ar archives in place of all their merged text files

Attachments (1)

MacX.log​ (84.4 KB) - added by fhgwright (Fred Wright) 6 days ago.
Log of destroot failure of libffi +universal on 10.5 i386

Download all attachments as: .zip

Change History (27)

comment:1 Changed 7 months ago by ryandesign (Ryan Carsten Schmidt)

That could explain some other open tickets.

comment:2 Changed 7 months ago by ryandesign (Ryan Carsten Schmidt)

Cc: ryandesign mascguy johanmattssonm added
Keywords: tahoe added
Port: glib2 added

Like #73776.

comment:3 Changed 7 months ago by ryandesign (Ryan Carsten Schmidt)

Perhaps instead of relying on program exit codes to guess if a file is a Mach-O binary, we should use file (or a simpler built-in check of the file's first bytes) to find out.

comment:4 Changed 7 months ago by TellowKrinkle

I'd recommend against file, its output can change between OS releases. The reason macOS 10.13's archive utility can't decompress .tar.xz files is actually because they internally used file to figure out if a file was a .tar.xz, and at some point the capitalization of file's description of .tar.xz files changed and archive utility stopped recognizing them.

comment:5 Changed 7 months ago by ryandesign (Ryan Carsten Schmidt)

I would too. I'd think comparing the file's MIME type would have been better than comparing descriptive text, but even MIME types can change. And I'd like to avoid the overhead of running the file executable for each file to be merged.

There's already a very simple file type detection in the muniversal portgroups to identify executable scripts ("test \"`head -c2 ${dir1}/${fl}`\" = '#!'") which could be extended into a slightly more advanced function that could distinguish between script, Mach-O, and other.

Identifying Mach-O is a little more complicated, since there are 5 possible values for the first four bytes:

  • 0xFEEDFACE (32-bit big-endian)
  • 0xCEFAEDFE (32-bit little-endian)
  • 0xFEEDFACF (64-bit big-endian)
  • 0xCFFAEDFE (64-bit little-endian)
  • 0xCAFEBABE (universal)

with the added complication that 0xCAFEBABE is also used by Java class files. Distinguishing between the two ​involves additionally checking the second set of four bytes: if less than 0x00000020, then it's Mach-O.

Alternately, MacPorts does install /opt/local/libexec/macports/lib/tcllib2.0/fumagic which provides fileutil::magic::filetype, a Tcl implementation of file; we might conceivably use that instead of writing our own.

Elsewhere in the muniversal portgroups we make decisions based on filename extensions, which could potentially be improved by using proper magic-number-based filetype identification.

comment:6 Changed 7 months ago by Dave-Allured (Dave Allured)

Cc: Dave-Allured added

comment:7 Changed 6 months ago by jmroot (Joshua Root)

Cc: MarcusCalhoun-Lopez added

Has duplicate #73933.

comment:8 Changed 6 months ago by jmroot (Joshua Root)

Summary: Text file merging is broken on Tahoe → muniversal portgroup: Text file merging is broken on Tahoe

comment:9 Changed 6 months ago by Dave-Allured (Dave Allured)

How about continuing to rely on libtool, but combine its exit code and interpreting its standard output?

$ /usr/bin/libtool a.txt b.txt -o c.txt
libtool: warning: not a mach-o 'a.txt'
libtool: warning: not a mach-o 'b.txt'

The assumption would be that libtool is as up-to-date at macho recognition, as any other tool or scheme that we might apply. Recognizing "warning: not a mach-o" should be trivial.

comment:10 Changed 6 months ago by ryandesign (Ryan Carsten Schmidt)

Parsing error messages can be fragile. We would need to check whether there were any variations in the wording over time, and keep up with any future changes. For example, on my macOS 12 system, I get:

% /usr/bin/libtool a.txt b.txt -o c.txt
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: a.txt is not an object file (not allowed in a library)
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: b.txt is not an object file (not allowed in a library)

As another example, we parse the config.log for indications of implicit function declarations and implicit int, but those messages have changed over time, so we had to go back and fix it, and probably are still only handling clang's wordings and not gcc's.

I favor the options I already presented.

comment:11 Changed 6 months ago by ryandesign (Ryan Carsten Schmidt)

I concede though that we'd only have to deal with messages from macOS 26 and later, if we keep the current handling which works for macOS before 26.

comment:12 Changed 5 months ago by bgilbert (Benjamin Gilbert)

Cc: bgilbert added

comment:13 Changed 4 months ago by jmroot (Joshua Root)

Has duplicate #74152.

comment:14 Changed 4 months ago by jmroot (Joshua Root)

Has duplicate #74234.

comment:15 Changed 3 months ago by cooljeanius (Eric Gallager)

Cc: cooljeanius added

comment:16 Changed 2 months ago by jrjsmrtn

Another affected port: libffi, and this one has a wider blast radius than a single broken header.

libffi @3.4.8_0+universal produces /opt/local/include/ffi.h as a 96-byte ar archive instead of a C header:

$ file /opt/local/include/ffi.h
/opt/local/include/ffi.h: current ar archive random library
$ head -3 /opt/local/include/ffi.h
!<arch>
#1/20           1788259576  0     0     100644  28        `
__.SYMDEF SORTED

Reproduced from a clean build on 2026-09-01, so it is not a stale artefact: sudo port clean --all libffi && sudo port -vs destroot libffi +universal.

The merge sequence in the build log matches the analysis in #73933 exactly. libffi generates a different ffi.h per architecture (config.status: creating include/ffi.h runs once per arch), so cmp fails, lipo fails, and libtool then "succeeds" by writing an empty archive:

Command failed: /usr/bin/cmp -s ".../destroot-arm64/opt/local/include/ffi.h" \
    ".../destroot-ppc-intel/opt/local/include/ffi.h" && /bin/cp -v ...

fatal error: lipo: can't figure out the architecture type of:
    .../destroot-arm64/opt/local/include/ffi.h
Command failed: /usr/bin/lipo -create ".../destroot-arm64/.../ffi.h" \
    ".../destroot-ppc-intel/.../ffi.h" -output ".../destroot/opt/local/include/ffi.h"

libtool: warning: not a mach-o '.../destroot-arm64/opt/local/include/ffi.h'

Why this one matters more than a single header. libffi is a library dependency of python313 and python314, so the corrupt ffi.h breaks both of them under +universal. Neither reaches the profile run; Modules/_ctypes fails to compile first, with every error cascading from ffi.h:1:1:

# python313 @3.13.15
/opt/local/include/ffi.h:1:1: error: expected identifier or '('
/opt/local/include/ffi.h:2:3: error: invalid filename for line marker directive
./Modules/_ctypes/callproc.c:799:17: error: use of undeclared identifier 'ffi_type_sint'
./Modules/_ctypes/ctypes.h:220:36: error: unknown type name 'ctypes_state'
make[2]: *** [Modules/_ctypes/callproc.o] Error 1
make[1]: *** [profile-gen-stamp] Error 2

# python314 @3.14.7
./Modules/_ctypes/stgdict.c:378:33: error: expected expression
make[2]: *** [Modules/_ctypes/cfield.o] Error 1
make[1]: *** [profile-gen-stamp] Error 2

configure compounds the confusion by reporting checking for libffi... yes and then failing every feature probe (ffi_prep_cif_var... no, ffi_prep_closure_loc... no, ffi_closure_alloc... no), because the header never parses.

The knock-on effect is that no port requiring a universal Python can build universal, since MacPorts upgrades the Python dependency to +universal and that build now fails. This surfaced while packaging a port whose only use of Python is a build-time script: depending on port:python3xx is correct practice, but it currently forfeits +universal for a reason unrelated to either port.

Environment: macOS 26.6.2 (25G83) arm64, Xcode 26.6, MacPorts with universal_archs at the default arm64 x86_64. libffi.dylib itself is fine — lipo -archs reports x86_64 arm64; only the header is corrupt, which makes this easy to misdiagnose as a Python bug.

comment:17 Changed 13 days ago by isolated-matrix

Is there any workaround yet? Not being able to update python314 is rather limiting my ability to update any of my other outdated ports...

comment:18 Changed 13 days ago by Dave-Allured (Dave Allured)

I think Ryan's original suggestion in comment 5 above is the best solution. This is a direct magic number test which will avoid the overhead of a general-purpose file utility in any form.

comment:19 Changed 11 days ago by Dave-Allured (Dave Allured)

comment:20 Changed 8 days ago by jmroot (Joshua Root)

comment:21 in reply to:  16 Changed 7 days ago by sitrucz1 (Curtis Matz)

Replying to jrjsmrtn:

Another affected port: libffi, and this one has a wider blast radius than a single broken header.

libffi @3.4.8_0+universal produces /opt/local/include/ffi.h as a 96-byte ar archive instead of a C header:

I ran into this with wine-devel and I worked around it by installing the non universal libffi then backed up the .h file then installed the universal libffi then overwrote the .h with the good c type .h file. I was eventually able to get wine-devel and python314 +univeral to install once I patched my system.

comment:22 Changed 6 days ago by jmroot (Joshua Root)

I wouldn't do that, as the header will only be correct for one architecture. Affected universal ports need to be rebuilt now that the portgroup is fixed.

comment:23 Changed 6 days ago by fhgwright (Fred Wright)

This fix broke libffi +universal in all <10.6 cases, as well as the Rosetta-targeted 10.6 case. It seems to be complaining that libraries built for different architectures aren't identical (duh!).

Changed 6 days ago by fhgwright (Fred Wright)

Attachment: MacX.log​ added

Log of destroot failure of libffi +universal on 10.5 i386

comment:24 Changed 6 days ago by fhgwright (Fred Wright)

Cc: fhgwright added

comment:25 Changed 6 days ago by isolated-matrix

Cc: isolated-matrix added

comment:26 Changed 3 days ago by Iritscen

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