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

emscripten: Upgrade emsdk to 3.1.68 #3962

Merged
merged 5 commits into from
Nov 14, 2024

Conversation

kleisauke
Copy link
Contributor

@kleisauke kleisauke commented Oct 11, 2024

In line with commit rust-lang/rust@2c38ecf.

Resolves: #3306.
Supersedes: #3569.
Cherry-picks a couple of changes from: #3307.

@rustbot
Copy link
Collaborator

rustbot commented Oct 11, 2024

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@hoodmane
Copy link
Contributor

Thanks @kleisauke it would be nice to see time_t finally get fixed...

@juntyr
Copy link

juntyr commented Oct 11, 2024

Could/should this PR keep the emcc version check to give a nice error at build time if a now-no-longer supported Emscripten is used?

@hoodmane
Copy link
Contributor

I wouldn't want rust to generate an error when building with Emscripten 3.1.58 since that is the version that Pyodide is using with Python 3.12 and it would prevent us from upgrading. Though I suppose that it would just require us to use a patched rust/libc and we are already doing that, it would be nice to avoid additional patches.

@hoodmane
Copy link
Contributor

But having a version check would be fine as long as there is an override.

@juntyr
Copy link

juntyr commented Oct 11, 2024

I was thinking about the previous check for 3.1.42 when the ABI change happened, which previous libc versions still supported (now there would be an ABI break in the opposite direction).

I definitely agree that other than that pretty much any emcc version has to be allowed since there is no current indicator which versions are ABI compatible and which aren’t

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Oct 13, 2024
@tgross35
Copy link
Contributor

How backwards compatible is emsdk? I think putting this on the 0.2 stable branch should be okay, but would like to know if there is any expected breakage here.

@kleisauke kleisauke force-pushed the update-emscripten-version branch 2 times, most recently from 63bbd45 to 839239d Compare October 15, 2024 10:22
@kleisauke kleisauke changed the title Draft: emscripten: Use the latest emsdk 3.1.68 emscripten: Upgrade emsdk to 3.1.68 Oct 15, 2024
@kleisauke
Copy link
Contributor Author

Updated now that PR rust-lang/rust#131533 was landed. This is ready for review.

How backwards compatible is emsdk?

AFAIK, there were no ABI-breaking changes after Emscripten 3.1.42 (released at 2023/06/23), which was addressed in libc by commit 63b0d67 (but only when building with -Zbuild-std).

@kleisauke kleisauke marked this pull request as ready for review October 15, 2024 10:23
@kleisauke
Copy link
Contributor Author

Could/should this PR keep the emcc version check to give a nice error at build time if a now-no-longer supported Emscripten is used?

I could address this within a follow-up PR, but perhaps its severity should be a warning instead? Simple programs that don't use filesystem operations will likely still work with Emscripten versions prior to 3.1.42. On the other hand, Emscripten 3.1.42 is already more than a year old.

@hoodmane
Copy link
Contributor

AFAIK, there were no ABI-breaking changes after Emscripten 3.1.42

@kleisauke it would be really great if we could make some sort of tool to do ABI compatibility checks. For a static test, we could compare the contents of emscripten/src/struct_info_generated.json. Perhaps we could use emscripten/tools/maint/gen_struct_info.py to generate info about the layout of more standard library structs than just the ones that are in the default struct_info. For a dynamic test, maybe take the unistd test suite and build the tests as side modules with one emcc version then load them and call into them with a second emcc version.

This probably wouldn't be perfect, but it would be a lot better than the current method where we don't really know anything.

@kleisauke
Copy link
Contributor Author

it would be really great if we could make some sort of tool to do ABI compatibility checks.

Agreed, we need to improve this. Note that a similar tool for this already exists in the repo. For example, when reverting the change in src/unix/linux_like/emscripten/align.rs within this PR locally, I see:

$ TARGET=wasm32-unknown-emscripten sh ./ci/install-rust.sh
$ ./ci/run-docker.sh wasm32-unknown-emscripten
[...]
bad max_align_t size: rust: 32 (0x20) != c 24 (0x18)
bad max_align_t align: rust: 16 (0x10) != c 8 (0x8)
size of max_align_t is 24 in C and 32 in Rust
thread 'main' panicked at /checkout/target/wasm32-unknown-emscripten/debug/build/libc-test-3c1238c857576107/out/main.rs:12:21:
some tests failed

However, that would only cover the types/functions/structs defined in src/unix/linux_like/emscripten/* and only works when EMSDK_VERSION is regularly updated.

Thinking about this further, how about changing EMSDK_VERSION to tot? This would ensure the tip-of-tree builds of Emscripten are tested in the CI, making it easier to identify potential ABI-breaking issues.

but it would be a lot better than the current method where we don't really know anything.

Note that wasm-vips regularly updates Rust and Emscripten to the latest versions, which is why the underlying issue in commit 63b0d67 and 7c952dc was resolved quickly. Based on that, I assumed there were no ABI-breaking changes after Emscripten 3.1.42, but I could be wrong.

@bors
Copy link
Contributor

bors commented Oct 24, 2024

☔ The latest upstream changes (presumably #3993) made this pull request unmergeable. Please resolve the merge conflicts.

@kleisauke kleisauke force-pushed the update-emscripten-version branch from 839239d to 073dbdf Compare October 24, 2024 12:29
@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2024

I don't have any major concerns here but I'll defer to @hoodmane's review (I'll merge once you give it the checkmark)

@kleisauke kleisauke force-pushed the update-emscripten-version branch from 073dbdf to a35f212 Compare November 7, 2024 10:03
Copy link
Contributor

@hoodmane hoodmane left a comment

Choose a reason for hiding this comment

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

Thanks @kleisauke generally looks good to me.

build.rs Outdated
Comment on lines 215 to 235
fn emcc_version_code() -> Option<u64> {
let output = std::process::Command::new("emcc")
.arg("-dumpversion")
.output()
.ok()?;
if !output.status.success() {
return None;
}

let version = String::from_utf8(output.stdout).ok()?;

// Some Emscripten versions come with `-git` attached, so split the
// version string also on the `-` char.
let mut pieces = version.trim().split(['.', '-']);

let major = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
let minor = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);
let patch = pieces.next().and_then(|x| x.parse().ok()).unwrap_or(0);

Some(major * 10000 + minor * 100 + patch)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to drop this entirely? Maybe we could adjust this to fail if Emscripten is below the minimum supported version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change was made based on the assumption that Rust requires Emscripten 3.1.42 or later. However, upon review, it appears that the compatibility note in rust-lang/rust#131689 indicates that versions prior 3.1.42 are still supported.

Let me drop commit a35f212 for now.

libc-test/build.rs Show resolved Hide resolved
#[allow(missing_debug_implementations)]
#[repr(align(16))]
#[repr(align(8))]
Copy link
Contributor

Choose a reason for hiding this comment

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

(Irrelevant remark.) The stack still has to be aligned to 16 bytes when you call a function even though maxalign is only 8. Discovering this wasted a lot of my time.

Comment on lines 2923 to 2934
// FIXME: https://github.com/emscripten-core/emscripten/pull/14883
"SIG_IGN" => true,
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this FIXME mean? Did that PR break this test? Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That PR did break the libc test, see e.g.:

RUNNING ALL TESTS
bad SIG_IGN value at byte 0: rust: 1 (0x1) != c 254 (0xfe)
bad SIG_IGN value at byte 1: rust: 0 (0x0) != c 255 (0xff)
bad SIG_IGN value at byte 2: rust: 0 (0x0) != c 255 (0xff)
bad SIG_IGN value at byte 3: rust: 0 (0x0) != c 255 (0xff)
thread 'main' panicked at /checkout/target/wasm32-unknown-emscripten/debug/build/libc-test-890b1e2d4768b06a/out/main.rs:12:21:
some tests failed

However, this FIXME can probably not fixed according to
https://github.com/emscripten-core/emscripten/pull/14883/files#r892912370.

I'll change this to:

Suggested change
// FIXME: https://github.com/emscripten-core/emscripten/pull/14883
"SIG_IGN" => true,
// `SIG_IGN` has been changed to -2 since 1 is a valid function address
// https://github.com/emscripten-core/emscripten/pull/14883
"SIG_IGN" => true,

Note that other implementations have a similar issue, see e.g:

"SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness

Copy link
Contributor

@hoodmane hoodmane Nov 7, 2024

Choose a reason for hiding this comment

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

Maybe there should be a constant somewhere that indicates what the value of SIG_IGN is on the platform... But that would be best dealt with in a followup.

@kleisauke kleisauke force-pushed the update-emscripten-version branch from a35f212 to b6a957f Compare November 7, 2024 11:10
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Just a couple small nits before merge. Thanks @hoodmane for taking a look.

Comment on lines 40 to 41
// Lowered from 16 to 8 bytes in
// https://github.com/llvm/llvm-project/commit/d1a96e906cc03a95cfd41a1f22bdda92651250c7
Copy link
Contributor

Choose a reason for hiding this comment

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

This can just go in the commit message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 780 to 751
pub const S_IEXEC: mode_t = 0o0100;
pub const S_IWRITE: mode_t = 0o0200;
pub const S_IREAD: mode_t = 0o0400;
pub const S_IEXEC: mode_t = 64;
pub const S_IWRITE: mode_t = 128;
pub const S_IREAD: mode_t = 256;
Copy link
Contributor

@tgross35 tgross35 Nov 13, 2024

Choose a reason for hiding this comment

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

These look like they are octal in the C source, could they stay that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted this part, I can't remember why I did this in the first place.

@tgross35 tgross35 enabled auto-merge November 14, 2024 00:34
@tgross35 tgross35 removed the O-wasm label Nov 14, 2024
@tgross35 tgross35 added this pull request to the merge queue Nov 14, 2024
Merged via the queue into rust-lang:main with commit 71e623d Nov 14, 2024
43 checks passed
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 15, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 15, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 15, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 15, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Nov 15, 2024
In line with commit rust-lang/rust@2c38ecf.

Notable changes:
- `time_t` changed to 64-bit.
  emscripten-core/emscripten@c8857a6

(backport <rust-lang#3962>)
(cherry picked from commit 3e82531)
@tgross35 tgross35 mentioned this pull request Nov 15, 2024
@tgross35 tgross35 added stable-applied This PR has been cherry-picked to libc's stable release branch and removed stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix S-waiting-on-review stable-applied This PR has been cherry-picked to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

emscripten time_t has wrong size
7 participants