Skip to content

Conversation

sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Sep 16, 2025

These tags have also historically be weakly defined in each object file by llvm (at least for non-PIC object files) but I hope to remove those definitions going forward and instead rely on the toolchain/compiler-rt to define them.

This will remove one of the distinctions between PIC and non-PIC generated code.

This change can land here on the emscripten side before the corresponding llvm changes since the strong definition I'm adding here will always take precedence over any weak definitions in object files.

See llvm/llvm-project#159143

@sbc100 sbc100 requested a review from dschuff September 16, 2025 01:06
@sbc100 sbc100 requested a review from aheejin September 16, 2025 01:08
@sbc100 sbc100 enabled auto-merge (squash) September 16, 2025 01:12
@aheejin
Copy link
Member

aheejin commented Sep 16, 2025

I think this was necessary to make dynamic linking work... What changed? Where do we define these now?

@sbc100
Copy link
Collaborator Author

sbc100 commented Sep 16, 2025

I think this was necessary to make dynamic linking work... What changed? Where do we define these now?

Today we have two different modes:

  1. Dynamic linking (PIC). In this mode each object file declares these tags as imports and expects them to be provided by the runtime. In this case we define them in JS.
  2. Static linking (non-PIC). Each object file contains its own weak definition and the linker just chooses one.

One the of the reasons for this change is to unify these two modes into one mode that just works everywhere. In the new mode:

  • tags are expected to be defined by compiler-rt or libc (or anyone really) at link time.
  • tags are never defined automatically in object files
  • shared libraries don't define tags but import them from the main module (libc/runtime module) which contains the single definition.

@sbc100
Copy link
Collaborator Author

sbc100 commented Sep 16, 2025

This change can land here on the emscripten side before the corresponding llvm changes since the strong definition I'm adding here will always take precedence over any weak definitions in object files.

@sbc100 sbc100 changed the title Unconditionally define wasm-eh tags in native code. NFC Define wasm-eh tags in native code. NFC Sep 16, 2025
@sbc100 sbc100 disabled auto-merge September 16, 2025 18:21
@@ -0,0 +1,26 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

I think it maybe makes more sense to define __cpp_exception in libc++abi. IIRC that's where we define the functions that the compiler emits calls to such as __cxa_throw.
Slightly annoying that we'd be separating __cpp_exception from __c_longjmp but I think its' the right layering.
Speaking of which, where does __c_longjmp belong? Do we define longjmp in compiler-rt or libc?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Is the latter file in compiler-rt because setThrew is shared between EH and SJLJ?

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, setThrew is also used in Emscripten SjLj. Yeah I think that's the reason.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I move the definitions into their own files. And I moved __cpp_exception to libcxxabi

Copy link
Member

@aheejin aheejin Sep 17, 2025

Choose a reason for hiding this comment

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

Where are we putting tag symbols, libcxxabi or compiler-rt? llvm/llvm-project#159143 puts both in compiler-rt but this puts __cpp_exceptions in libc++abi, so..

Personally I think putting both in compiler-rt is fine, given that these are things we never get to upstream to the upstream libc++abi anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree we should match llvm/llvm-project#159143 once it lands.

@sbc100 sbc100 force-pushed the tags branch 2 times, most recently from c26d130 to d1b38cd Compare September 17, 2025 19:59
This tags are sometimes also weakly defined in each object file by llvm
but I hope to remove those definitions going forward and instead rely
on the toolchain/compiler-rt to define them.
@sbc100 sbc100 enabled auto-merge (squash) September 17, 2025 20:36
@sbc100 sbc100 disabled auto-merge September 17, 2025 21:44
@sbc100 sbc100 merged commit 85036b7 into emscripten-core:main Sep 17, 2025
29 of 31 checks passed
@sbc100 sbc100 deleted the tags branch September 17, 2025 21:44
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.

3 participants