|
From: Matthew F. <mat...@gm...> - 2020-12-28 16:48:16
|
On Mon, Dec 28, 2020 at 11:11 AM Chris Cannam <ca...@al...> wrote: > > On Mon, 28 Dec 2020, at 14:52, Matthew Fluet wrote: > > > With some script tweaks [...] > > > > It would help to see these patches as well. > > The first of these is just a hack to try to force matters, but the platform bit seemed sensible to me: > > diff --git a/bin/mlton-script b/bin/mlton-script > index 2e9f0d78d..e239d5456 100644 > --- a/bin/mlton-script > +++ b/bin/mlton-script > @@ -82,6 +82,8 @@ doit "$lib" \ > -cc-opt '-O1 -fno-strict-aliasing' \ > -cc-opt '-foptimize-sibling-calls' \ > -cc-opt '-w' \ > + -cc-opt '-arch arm64' \ > + -link-opt '-arch arm64' \ > -cc-opt-quote "-I$lib/include" \ > $gmpCCOpts $gmpLinkOpts \ > -llvm-llc-opt '-O2' \ > diff --git a/bin/platform b/bin/platform > index fed549259..999be668b 100755 > --- a/bin/platform > +++ b/bin/platform > @@ -88,12 +88,15 @@ i?86_64) > amd64) > HOST_ARCH=amd64 > ;; > -arm*) > - HOST_ARCH=arm > +arm64) > + HOST_ARCH=arm64 > ;; > aarch64) > HOST_ARCH=arm64 > ;; > +arm*) > + HOST_ARCH=arm > +;; > parisc*) > HOST_ARCH=hppa > ;; > > > How is the macOS C compiler distinguishing between targeting amd64 and arm64? > > Various ways. One is the -arch option. "cc -arch x86_64" targets amd64, "cc -arch arm64" targets arm64, and "cc -arch x86_64 -arch arm64" creates a fat binary containing both architectures. > > If you don't give an -arch option, then it targets the same architecture as the process that invoked cc - which is not necessarily the native machine architecture. That means, I believe, that a compiler exec'd directly by an amd64 MLton will target amd64 even on an ARM Mac unless you specify otherwise. This seems logical but can be a bit confusing, especially since many programs that exec compilers (e.g. the system-supplied make) are fat binaries, so the compiler will default to whichever slice was in use for the parent process, something that is not necessarily externally obvious. > > There's also a command called "arch" that selects a specific slice from a fat binary. So if you run e.g. "arch -x86_64 make" you will run make in amd64 mode, and any cc it forks will default to amd64. Or you can "arch -arm64 cc" to get a cc that, I believe, both runs in and targets by default arm64, although it can still target the other architecture if you ask it to (e.g. "arch -arm64 cc -arch x86_64" produces an amd64-only binary). > > If you run cc directly from the shell without any of the above going on then it targets the native architecture, though I assume this is just a special case of following the parent process, since login shells are native. Given what you say here, I'm hopeful that you won't need any changes to `bin/mlton-script`, because at the end of the bootstrap, you will have an arm64 MLton, which, when invoking cc, will automatically generate arm64 executables. -Matthew -- To unsubscribe from this group and stop receiving emails from it, send an email to mlt...@ml.... |