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

Fix compilation on current MacOS #108

Closed
wants to merge 1 commit into from
Closed

Conversation

bemoody
Copy link

@bemoody bemoody commented Jul 26, 2024

The "-force_cpusubtype_ALL" flag, which configure adds unconditionally when building for Darwin, is apparently not supported by current Apple compilers.

I don't use MacOS, so I have no way to test this myself.

However, it appears that in GitHub workflows targetting "macos-12", the flag is supported, whereas in GitHub workflows targetting "macos-13" or "macos-14" the flag is not supported, and results in the error

ld: unknown options: -force_cpusubtype_ALL

The patch that introduced this flag doesn't provide any details: https://lists.xiph.org/pipermail/vorbis-dev/2001-January/002993.html

(Fixes issue #107)

The "-force_cpusubtype_ALL" flag is not supported by current Apple
compilers.  It's not clear to me why that flag was used to begin with.
@sezero
Copy link
Contributor

sezero commented Jul 28, 2024

-force_cpusubtype_ALL used to be meant mostly for ppc target with Apple gcc.

Here is the entry from Apple's newest ld man page:

-force_cpusubtype_ALL
 The is only applicable with -arch ppc.  It tells the linker
 to ignore the PowerPC cpu requirements (e.g. G3, G4 or G5)
 encoded in the object files and mark the resulting binary as
 runnable on any PowerPC cpu.

Here are excerpts from Apple's old gcc man page:

The subtype of the file created (like ppc7400 or ppc970 or i686) is
determined by the flags that specify the ISA that GCC is targetting,
like -mcpu or -march.  The -force_cpusubtype_ALL option can be used to
override this.
[....]
-force_cpusubtype_ALL
 This causes GCC's output file to have the ALL subtype, instead of
 one controlled by the -mcpu or -march option.

And here is the entry from Apple's as man page:

-force_cpusubtype_ALL
 By default, the assembler will produce the CPU subtype  ALL  for
 the  object file it is assembling if it finds no implementation-
 specific instructions.  Also  by  default,  the  assembler  will
 allow  implementation-specific instructions and will combine the
 CPU subtype for those specific implementations.   The  combining
 of  specific  implementations is architecture-dependent; if some
 combination of instructions is not allowed, an error  is  gener-
 ated.    With   the  optional  -force_cpusubtype_ALL  flag,  all
 instructions are allowed and the object file's CPU subtype  will
 be  the  ALL subtype.  If the target architecture specified is a
 machine-specific  implementation  (e.g.,  -arch  ppc603,   -arch
 i486),  the  assembler will flag as errors instructions that are
 not supported on that  architecture,  and  it  will  produce  an
 object  file  with the CPU subtype for that specific implementa-
 tion (even if no implementation-specific instructions are used).
 The  -force_cpusubtype_ALL  flag  is the default for all x86 and
 x86_64 architectures.

The I guess the best course of action would be limiting that flag
to powerpc builds, only. Like:

diff --git a/configure.ac b/configure.ac
index 14a267f..3d62bc9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -201,10 +201,14 @@ else
 		DEBUG="-g -Wall -Wextra -D__NO_MATH_INLINES -fsigned-char $sparc_cpu"
 		CFLAGS="-O3 -Wall -Wextra -ffast-math -D__NO_MATH_INLINES -fsigned-char $sparc_cpu"
 		PROFILE="-pg -g -O3 -D__NO_MATH_INLINES -fsigned-char $sparc_cpu" ;;
-	*-*-darwin*)
+	powerpc-*-darwin*)
 		DEBUG="-DDARWIN -fno-common -force_cpusubtype_ALL -Wall -g -O0 -fsigned-char"
 		CFLAGS="-DDARWIN -fno-common -force_cpusubtype_ALL -Wall -g -O3 -ffast-math -fsigned-char"
 		PROFILE="-DDARWIN -fno-common -force_cpusubtype_ALL -Wall -g -pg -O3 -ffast-math -fsigned-char";;
+	*-*-darwin*)
+		DEBUG="-DDARWIN -fno-common -Wall -g -O0 -fsigned-char"
+		CFLAGS="-DDARWIN -fno-common -Wall -g -O3 -ffast-math -fsigned-char"
+		PROFILE="-DDARWIN -fno-common -Wall -g -pg -O3 -ffast-math -fsigned-char";;
 	*-*-os2*)
 		# Use -W instead of -Wextra because gcc on OS/2 is an old version.
 		DEBUG="-g -Wall -W -D_REENTRANT -D__NO_MATH_INLINES -fsigned-char"

@bemoody
Copy link
Author

bemoody commented Jul 29, 2024

Thanks for the detailed references.

It seems to me that if somebody wants to build binaries compatible with a particular CPU model, then they should use -mcpu=G3 or whatever. I don't think you should tell the linker to ignore the compiler's requirements without having a really good reason.

But, if you think it's better not to fix what ain't broken, and keep the flag enabled for powerpc-*-darwin*, that seems fine too.

@sezero
Copy link
Contributor

sezero commented Jul 29, 2024

better not to fix what ain't broken, and keep the flag enabled for powerpc-*-darwin*, that seems fine too.

Yes, I think that's best

@sezero
Copy link
Contributor

sezero commented Jul 30, 2024

Created #109

sezero added a commit to sezero/vorbis that referenced this pull request Jul 30, 2024
@bemoody
Copy link
Author

bemoody commented Jul 30, 2024

Sounds good to me. Closing this pull in favor of #109.

@bemoody bemoody closed this Jul 30, 2024
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