Skip to content

Ported build system and source to macOS arm64#10

Open
peturingi wants to merge 1 commit into
openwall:mainfrom
peturingi:main
Open

Ported build system and source to macOS arm64#10
peturingi wants to merge 1 commit into
openwall:mainfrom
peturingi:main

Conversation

@peturingi

Copy link
Copy Markdown

Ported to macOS by solving the following problems:

Makefile assumed Linux (GCC, -lrt, -fopenmp). Modified to detects macOS (Darwin kernel) via uname -s then set compiler/linker flags accordingly. Linux flags are unchanged.

sched_setscheduler() does not exist on macOS. Guarded with #ifndef __APPLE__ since it is only a non-essential SCHED_RR optimization for benchmarking as root.

Apple Clang has three issues that prevent compilation:

  • -fopenmp is not supported by Apple Clang. Used -Xpreprocessor -fopenmp with Homebrew libomp headers and library instead.
  • -lrt does not exist on macOS. librt provides clock_gettime() and POSIX timers on Linux; macOS includes these in libSystem.
  • -s (strip at link time) is obsolete on macOS ld.

Should you choose to accept this PR, please mind documenting the dependency on libomp for those who want to build on macOS.

  The upstream Makefile assumes Linux (GCC, -lrt, -fopenmp). On macOS
  with Apple Clang, three issues prevent compilation:

  1. -fopenmp is not supported by Apple Clang. Use -Xpreprocessor -fopenmp
     with Homebrew libomp headers and library instead.

  2. -lrt does not exist on macOS. librt provides clock_gettime() and
     POSIX timers on Linux; macOS includes these in libSystem.

  3. -s (strip at link time) is obsolete on macOS ld.

  The Makefile now detects Darwin via uname -s and sets compiler/linker
  flags accordingly. Linux flags are unchanged.

  Additionally, userom.c calls sched_setscheduler() which does not exist
  on macOS. Guarded with #ifndef __APPLE__ since it is only a non-essential
  SCHED_RR optimization for benchmarking as root.
Copilot AI review requested due to automatic review settings March 23, 2026 16:03
Comment thread Makefile
# SUCH DAMAGE.

CC = gcc
CC = cc

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: I did not guard this. Problem?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specific flags we use assume GCC on Linux and apparently clang on macOS? If so, I guess you need to move the CC = line to inside the ifeq/else, and the LD line to after endif.

Also, e.g. on Solaris cc may be Sun's compiler, which does not recognize gcc options, yet I fixed this Makefile to work for Solaris just recently... except that I also broke it on SPARC later by adding -march=native, which gcc for that arch does not recognize.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ports the build and benchmarking utilities to support macOS (Darwin) on arm64 by adjusting compiler/linker flags and guarding Linux-only scheduling optimizations.

Changes:

  • Add a macOS-specific Makefile branch that uses Homebrew libomp for OpenMP and removes Linux-only linker flags.
  • Guard the sched_setscheduler() SCHED_RR benchmarking optimization to avoid building/calling it on Apple platforms.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
Makefile Adds Darwin detection and uses Homebrew libomp OpenMP flags; updates default compiler selection.
userom.c Wraps sched_setscheduler() usage with #ifndef __APPLE__ to compile on macOS.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile
Comment thread Makefile
Comment thread Makefile
@peturingi

Copy link
Copy Markdown
Author

Issues?

@solardiz

solardiz commented May 1, 2026

Copy link
Copy Markdown
Member

@peturingi I'm sorry I'm in a bad lack of time lately. I do appreciate your contribution and your persistence. Thank you! I do intend to review this properly.

Note that we also have similar codebase in https://github.com/openwall/yespower so we could want to keep them in sync.

Comment thread userom.c

unsigned long long count1 = count, count_restart = 0;

#ifndef __APPLE__

@solardiz solardiz May 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try #ifdef SCHED_RR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll get #ifdef SCHED_RR via #11 now, and will then need to revisit the rest of changes in this PR.

@solardiz solardiz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I requested some changes, but I also note that this requires GNU make, whereas before these changes the default make on Solaris could handle this Makefile as well. Not a big deal, because it's so common to have GNU make installed on Solaris as gmake and be using that. Still, this isn't strictly a portability improvement - it also hurts portability.

Comment thread Makefile
# SUCH DAMAGE.

CC = gcc
CC = cc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specific flags we use assume GCC on Linux and apparently clang on macOS? If so, I guess you need to move the CC = line to inside the ifeq/else, and the LD line to after endif.

Also, e.g. on Solaris cc may be Sun's compiler, which does not recognize gcc options, yet I fixed this Makefile to work for Solaris just recently... except that I also broke it on SPARC later by adding -march=native, which gcc for that arch does not recognize.

@solardiz

solardiz commented May 2, 2026

Copy link
Copy Markdown
Member

Note that the current build system here is just for testing and benchmarking, not for building production code.

Separately from this PR, we could want to implement a proper build system that would build a library and tools and test suite for the library and the tools. For doing so, we could want to consider how passwdqc is built and decide whether we want to be similar or different here. Just thinking out loud, not a request.

@Leont

Leont commented May 17, 2026

Copy link
Copy Markdown

-lrt does not exist on macOS. librt provides clock_gettime() and POSIX timers on Linux; macOS includes these in libSystem.

Since glibc 2.34 librt has been merged into libc so it's not necessary anymore on modern Linux (at least when using glibc), it still exists but as an empty library.

@solardiz

solardiz commented Jun 15, 2026

Copy link
Copy Markdown
Member

Now that #11 is merged, what further changes do we want to make related to this PR? cc: @quadcpu

Regarding -s -lrt, I think we should drop -s, but I am unsure about dropping -lrt as glibc 2.34+ means RHEL 9+ and such, whereas 8 and even 7 are still in use (8 still maintained upstream, 7 is in "extended support" by RH and several downstreams).

@quadcpu

quadcpu commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@solardiz I know very little about macos or clang but gcc is ln'ed with cc which is clang compiler, and currently clang compiler works with something like

make check \
            CFLAGS="-Wall -O2 -fomit-frame-pointer -DSKIP_MEMZERO" \
            OMPFLAGS_MAYBE="" LDFLAGS=""

on https://github.com/openwall/yescrypt/actions/runs/27568978084/job/81500253260 though.

for -lrt got something like

  On -lrt: rather than deciding "drop vs. keep" globally, I'd make it conditional on the platform so we don't have to pick between old RHEL and macOS. Detect Darwin via uname -s and adjust the flags there,
  leaving the Linux path exactly as-is:

  LDFLAGS = -s $(OMPFLAGS_MAYBE)
  ifeq ($(shell uname -s),Darwin)
  # clock_gettime() is in libSystem; ld's -s is obsolete
  LDFLAGS = $(OMPFLAGS_MAYBE)
  else
  # -lrt is for userom's use of clock_gettime() (folded into libc in glibc 2.34+,
  # but still needed on pre-2.34 systems like RHEL 7/8)
  LDFLAGS += -lrt
  endif

  That keeps -lrt for RHEL 7/8 (and anything pre-glibc-2.34) while not breaking Darwin, and avoids a behavior change for existing Linux users. As @Leont noted, glibc 2.34+ keeps an empty librt around anyway,
  so -lrt stays harmless on RHEL 9+.

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.

5 participants