') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); std: Apple Silicon: no fstat$INODE64 symbol found by kubkon · Pull Request #6842 · ziglang/zig · GitHub
Skip to content

std: Apple Silicon: no fstat$INODE64 symbol found - #6842

Merged
kubkon merged 2 commits into
ziglang:masterfrom
kubkon:aarch64-macos-fix
Oct 28, 2020
Merged

std: Apple Silicon: no fstat$INODE64 symbol found#6842
kubkon merged 2 commits into
ziglang:masterfrom
kubkon:aarch64-macos-fix

Conversation

@kubkon

Copy link
Copy Markdown
Member

It seems that Apple has finally got rid of the 32bit versions of
fstat and fstatat, and instead, only 64bit versions are available
on BigSur and Apple Silicon.

The tweak in this commit is required to make Zig stage1 compile on
BigSur + aarch64.

@kubkonkubkon changed the title stage1: Apple Silicon: no fstat$INODE64 symbol foundstd: Apple Silicon: no fstat$INODE64 symbol foundOct 27, 2020
@kubkonkubkon added standard library This issue involves writing Zig code for the standard library. os-macos macOS arch-aarch64 64-bit Arm labels Oct 27, 2020
It seems that Apple has finally got rid of the 32bit versions of
`fstat` and `fstatat`, and instead, only 64bit versions are available
on BigSur and Apple Silicon.
The tweak in this commit is required to make Zig stage1 compile on
BigSur + aarch64.

@andrewrkandrewrk 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.

Exciting stuff.

Comment threadlib/std/c.zig Outdated
Comment on lines +127 to +134
pub usingnamespace switch (builtin.arch) {
.aarch64 => struct {
pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
},
else => struct {
pub const fstatat = @"fstatat$INODE64";
},
};

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.

Would it maybe be cleaner to simply list both functions and rely on lazy evaluation?

pubconstfstatat=switch (builtin.arch) {
.aarch64=>fstatat,
else=> @"fstatat$INODE64",
};

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Excellent suggestion!

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Hmm, any ideas if there's a way to avoid overriding the previous definition, i.e., fstatat has already been defined by pub extern "c" fn fstatat...?

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.

Take a step back and reorganize things. Is the previous definition correct already? Can just use that. If not, sounds like fstatat needs to become one of the functions that moves from the common file to OS-specific files.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's try to keep all the os-related conditional definitions/renames in the switch below.

Hmm, any ideas if there's a way to avoid overriding the previous definition, i.e., fstatat has already been defined by pub extern "c" fn fstatat...?

You can handle it the same way fstat is handled below: define fstatat in c/darwin.zig together with its weird cousin fstatat$INODE64 (and add a comment explaining why it's defined there) and then export the correct fstat symbol below. Other platforms get the usual pub extern "c" fn fstatat(..) ..., it's a bit repetitive but I couldn't figure out a nicer looking way to handle this symbol mess.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Addressed in 4f50958. Have a look and lemme know if that's what you had in mind.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.
Perhaps it's time to think of moving all the c definitions in a separate file for each os.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Sounds like a good idea!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Orrr... we could resurrect Andrew's idea of an @extern suggested in #3971 and augment it with a way to specify a comptime string as symbol name. This way we finally get the weak-symbol mechanism and gain a cleaner way to deal with those nasty renames.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Hmm, after a quick browse I think I'm partial to the second solution of weak-symbol mechanism. This would indeed make a lot of things cleaner and more elegant.

@jedisct1

Copy link
Copy Markdown
Contributor

Looks good. Thanks a lot for bringing Zig to Apple Silicon!

@LemonBoy

Copy link
Copy Markdown
Contributor

Don't forget to update mem.page_size, Apple Silicon has 16k pages (Time to address #2564 too?)

@kubkon

Copy link
Copy Markdown
MemberAuthor

Don't forget to update mem.page_size, Apple Silicon has 16k pages (Time to address #2564 too?)

Yep, but I'll make it the subject of a subsequent PR.

@kubkon
kubkon merged commit 1a171a1 into ziglang:masterOct 28, 2020
@kubkon
kubkon deleted the aarch64-macos-fix branch October 28, 2020 10:38
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-aarch6464-bit Armos-macosmacOSstandard libraryThis issue involves writing Zig code for the standard library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@kubkon@jedisct1@LemonBoy@andrewrk