Skip to content

[build] Update cross tools build process to work on MacOS 26/Tahoe - #227

Merged
Mellvik merged 3 commits into
masterfrom
build
Feb 12, 2026
Merged

Mellvik merged 3 commits into
masterfrom
build

Conversation

@Mellvik

@Mellvik Mellvik commented Feb 10, 2026 •

Copy link
Copy Markdown
Owner

Building the TLVC toolchain on MacOS on ARM architecture systems has always been a challenge. Since MacOS 26/Tahoe, building has been an impossibility on all Macs. The TLVC/ELKS IA16 cross toolchain is created for gcc, not for clang, and doesn't even try to recognize the Darwin/arm64 combination. And while the changes needed to get a build on the previous macOS v version and early M1-3 systems, it has now become a big deal.

While some of the problems are easily fixed locally in the TLVC build scripts or Makefiles, most of them are inherent to the toolchain and must be fixed there, outside the direct reach from TLVC. Getting such changes prioritized may be a long shot though - and instead of waiting, this PR makes changes to the build process that automatically fix the problems. Changes are restricted to two TLVC files, tools/build.sh and tools/Makefile. Mere's a summary of the problems and how they are fixed:

  • The configure/build process finds fdopen on the MacOS platform as it should but in the zlib directory forgets about it, and '#defines' fdopen as a NULL macro. This eventually creates a compilation error. Without even trying to find the root cause, the simple trick is to awk the actual file, binutils-src/zlib/zutil.h to comment out the #define line. There are two occurrences of this - zlib exists in both the binutils chain and the gcc chain. sed would be a more natural choice, but awk turned out to be simpler since we want to restrict the edit to one single occurrence.
  • There are many occurrences of variables that are set but not used in the binutils code. Normally not a problem - the compiler will emit a warning and continue. It becomes a problem in this context because the build by default is in development mode: The compiler is told to treat warnings as errors. This is set in the file cross/build/binutils-src/bfd/development.sh where development=true. The top level Makefile changes this to false via a simple sed command.
  • Possibly the weirdest of the problems is that when compiling gcc, we get lots of compilation errors from the options processing code (options.h), where macros like OPT_O etc. are continuously being redefined. The solution is as weird as the problem: Make sure the locale-variable LC_COLLATE is set to "C". This problem will IOW hit only if your system is set up with a locale different from C (or possibly 'en_US'). The fix is to set this environment variable in the tools/build.sh script.
  • Also in gcc, the fibonacci heap code (gcc-src/gcc/fibonacci_heap.h) has syntax errors which interestingly are accepted by gcc but not by clang. Again a sed command fixes is, changing if (heapb->min->compare (heapa->min) < 0)to if (heapb->m_min->compare (heapa->m_min) < 0).
  • As mentioned above, there is no recognition of the Darwin/ARM combination. Unsurprisingly then, problems arise when the so-called host-hooks are built. They are simply missing for the ARM architecture and must be added. The simple way of doing this is to take the hooks from the i386 architecture code - there are no differences between the architecture for these hooks - and put them in the generic Darwin-hooks file. Doing this means adding 3 lines of code to the gcc/config/host-darwin.c file, which turned out to be really hard with sed inside a Makefile, so awkward was used instead.
  • Finally - and this should have been done a long time ago - the building of emu86 tools in the top level Makefile must be made conditional to ensure it's not even attempted when running on a Mac.

Using sed's in-place editing capability would be simpler than the (old fashioned) save-and-copy method, but the -i sed-option turns out to be incompatible across platforms.

The fixes have been added in such a way so as to not get in the way if the fixes have already been made or if running on other platforms. Tested on

  • macOS Tahoe 26.2 Intel 64
  • macOS Tahoe 26.2 M4
  • macOS BigSur (11.7.10), Intel 64 - fails, seemingly a locale problem, not investigated
  • macOS Mojave (10.14.6), Intel 64
  • Ubuntu 18.04.6 LTS, Intel 64

Ideally most of these fixes should be applied to the toolchain itself, and that may happen at some time. For now this will do, and the changes should not be in the way whenever the toolchain gets updated.

@ghaerr

ghaerr commented Feb 10, 2026

Copy link
Copy Markdown

Wow, @Mellvik, this is some fantastic investigative and repair work you have accomplished, thank you!! You must be running on a very fast system to have the time and patience to have figured all this out, considering the build times and gcc complexities involved.

I haven't had time to delve in to trying these (and don't have an ARM mac laptop yet) but thought to comment. There's an ELKS user with the fdopen problem I'll send over who will appreciate this major fix for Darwin users.

Make sure the locale-variable LC_COLLATE is set to "C".

Amazing. How did you figure this one out?

Also in gcc, the fibonacci heap code (gcc-src/gcc/fibonacci_heap.h) has syntax errors which interestingly are accepted by gcc but not by clang.

Is GCC accepting a member of an alternate struct with min vs m_min? I happen to be investigating an early K&R compiler where this kind of thing was allowed... curious as to this situation and how this could be allowed to compile. Or is this a case of a shell script that continues on regardless of compilation errors?

problems arise when the so-called host-hooks are built.

I think this problem was fixed by tkchia before he left GitHub in tkchia/gcc-ia16@a4c99e2. Are you using his latest git HEAD, or something prior? Because of all the problems of macOS compilation(s), I have held off with upgrading tools/Makefile to techie's latest, and am curious which commit you started with. Here's his last commits before leaving the platform. ELKS is using the build from Jan 18, 2023 and has not included the proposed host-hooks fix.

Given that tkchia has left GitHub, do you think having a bug-fixed fork with these kinds of fixes are worthwhile? Our projects are dependent on the Github repo remaining, while most other repos were deleted just before the move to GitLab. I check over there occasionally, and don't see much action.

Thank you for tackling this time-consuming set of problems, much appreciated!!

@Mellvik

Mellvik commented Feb 11, 2026

Copy link
Copy Markdown
Owner Author

Wow, @Mellvik, this is some fantastic investigative and repair work you have accomplished, thank you!! You must be running on a very fast system to have the time and patience to have figured all this out, considering the build times and gcc complexities involved.

Being stubborn is sometimes a trait, other times a curse. This time - on day 3 - it felt like the latter ... Getting the toolchain to work on my M1 was the first thing I did after forking ELKS 3 years ago. It took a few of hours - including writing the build instructions. I've been using those binaries since (I'm now in a M4 mini). The arrival of slightly 'hotter' M4 in the house (I convinced/coerced my wife to upgrade) prompted me to do a clean install of TLVC, a 'reference installation' if you like. And while expecting trouble with the cross tools build, I certainly didn't expect what I got. Yes, the M4s are indeed incredibly fast.

Make sure the locale-variable LC_COLLATE is set to "C".

Amazing. How did you figure this one out?

Not understanding how this could possibly be bad in one setting and good in another, I sent the entire error message to Google, and eventually found a German dude who had the exact same problem in a different context, and had more or less accidentally found the solution...

Also in gcc, the fibonacci heap code (gcc-src/gcc/fibonacci_heap.h) has syntax errors which interestingly are accepted by gcc but not by clang.

Is GCC accepting a member of an alternate struct with min vs m_min? I happen to be investigating an early K&R compiler where this kind of thing was allowed... curious as to this situation and how this could be allowed to compile. Or is this a case of a shell script that continues on regardless of compilation errors?

This is C++ code. I'm no good at that, so I ended up sending the problem to Claude, who (I hesitate to say 'who' about a machine ...) explained it and provided a fix. There is actually a logic to the fact that gcc is forgiving about the error. And that clang is going the more pedantic route. I can share the full response from Claude with you if you're interested. The short version is this: "Ah, I see the issue now! On line 481, the code is trying to access min as if it's a member variable, but min() is actually a member function (defined on line 197)."

problems arise when the so-called host-hooks are built.

I think this problem was fixed by tkchia before he left GitHub in tkchia/gcc-ia16@a4c99e2. Are you using his latest git HEAD, or something prior? Because of all the problems of macOS compilation(s), I have held off with upgrading tools/Makefile to techie's latest, and am curious which commit you started with. Here's his last commits before leaving the platform. ELKS is using the build from Jan 18, 2023 and has not included the proposed host-hooks fix.

I'm using the unmodified scripts from ELKS, the fork happened about that time. I need to look into this, there may be fixes no longer required here. Thanks!

Given that tkchia has left GitHub, do you think having a bug-fixed fork with these kinds of fixes are worthwhile? Our projects are dependent on the Github repo remaining, while most other repos were deleted just before the move to GitLab. I check over there occasionally, and don't see much action.

I had forgotten about @tkchia's exit. Yes, I think that would be worthwhile. Our systems are completely dependent on these tools, and being able to fix bugs instead of patching around them (like I've done here) is the right way. I'm not a potential owner of such a project, but I could easily see myself as a contributor.

Thanks.

@Mellvik

Mellvik commented Feb 11, 2026

Copy link
Copy Markdown
Owner Author

@ghaerr, I just tested the tool-versions from ELKS: they work fine, but don't fix the host_hooks issue.

I'm pushing a final version of the new Makefile with the new(er) version numbers before merging. Thanks for the hint.

@ghaerr

ghaerr commented Feb 11, 2026

Copy link
Copy Markdown

I just tested the tool-versions from ELKS: they work fine, but don't fix the host_hooks issue.

Thanks for the testing. My plan is to move GCC_VER to the final Github version of ia16-elf-gcc (18 Feb 2024), which does include a host_hooks fix (from 4 Jul 2023), possibly in two commits: the first to fix all the issues above, and the second to increment the GCC_VER number greater than what ELKS has been fully tested with. There are a couple of commits that might change the gcc code generated, which I may want to test before jumping into.

The good news is that the current host_hooks fix can likely be just "left in" tools/Makefile even when GCC_VER is incremented past tkchia's host_hooks fix without causing any problems.

I will make a final decision on the GCC_VER increment after looking more closely at the actually GCC compiler modifications.

Comment thread tools/Makefile Outdated
mv $(TMPFILE) binutils-src/zlib/zutil.h
# make sure we don't terminate on warnings
cd $(BUILDDIR)/binutils-src/bfd; \
sed 's/development=.*/deveopment=false/' development.sh > $(TMPFILE); \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note: development=false is misspelled above, but seems to work because development=true isn't set.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Oops, good catch, thanks. And you're right, it doesn't matter, but still wrong.

@Mellvik
Mellvik merged commit b6565bc into master Feb 12, 2026
@Mellvik
Mellvik deleted the build branch February 12, 2026 13:21
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