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

Pass emscripten linker options only when linking. #12233

Merged
merged 1 commit into from
Nov 4, 2021
Merged

Conversation

ekpyron
Copy link
Member

@ekpyron ekpyron commented Nov 4, 2021

In preparation of #11689

Emscripten 2.0.32 will raise warnings on this which are treated as error by us (see https://github.com/emscripten-core/emscripten/blob/main/ChangeLog.md):

  • Emscripten will now warn when linker-only flags are specified in compile-only (-c) mode. Just like with clang itself, this warning can be disabled using the flag: -Wno-unused-command-line-argument.

Will need to look at the soljson.js CI artifact to confirm that the options are correctly honoured and work using CMAKE_EXE_LINKER_FLAGS.

@ekpyron ekpyron force-pushed the emscriptenCMake branch 3 times, most recently from 22888b8 to ef4453a Compare November 4, 2021 10:48
@ethereum ethereum deleted a comment from stackenbotten Nov 4, 2021
@ekpyron ekpyron marked this pull request as ready for review November 4, 2021 10:48
@ekpyron
Copy link
Member Author

ekpyron commented Nov 4, 2021

The resulting soljson.js does contain base64-encoded wasm, which means the options do get through correctly.

@ekpyron ekpyron requested a review from axic November 4, 2021 10:49
@ekpyron
Copy link
Member Author

ekpyron commented Nov 4, 2021

As for the set of options: those are exactly the options that a build with emscripten 2.0.33 complained about.

axic
axic previously approved these changes Nov 4, 2021
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

Looks good to me, but more approvals should be sought.

# Abort if linking results in any undefined symbols
# Note: this is on by default in the CMake Emscripten module which we aren't using
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ERROR_ON_UNDEFINED_SYMBOLS=1")
# Disallow deprecated emscripten build options.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s STRICT=1")
Copy link
Member

Choose a reason for hiding this comment

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

Actually how about this one?

chriseth
chriseth previously approved these changes Nov 4, 2021
@@ -111,39 +111,39 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
# http://stackoverflow.com/questions/21617158/how-to-silence-unused-command-line-argument-error-with-clang-without-disabling-i
add_compile_options(-Qunused-arguments)
elseif(EMSCRIPTEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --memory-init-file 0")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --memory-init-file 0")
# Leave only exported symbols as public and aggressively remove others
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -fvisibility=hidden")
# Optimisation level
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
# Re-enable exception catching (optimisations above -O1 disable it)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s DISABLE_EXCEPTION_CATCHING=0")
Copy link
Member

Choose a reason for hiding this comment

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

And this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently CMAKE_CXX_FLAGS are still passed to the linker as well by emscripten - but I added this and -s STRICT to both now, just to be sure.

@ekpyron ekpyron dismissed stale reviews from chriseth and axic via 9ecfceb November 4, 2021 14:12
@ekpyron ekpyron requested review from axic and chriseth November 4, 2021 14:14
@ekpyron ekpyron enabled auto-merge November 4, 2021 14:14
@ekpyron
Copy link
Member Author

ekpyron commented Nov 4, 2021

For the record: the options are documented in https://github.com/emscripten-core/emscripten/blob/main/src/settings.js

chriseth
chriseth previously approved these changes Nov 4, 2021
axic
axic previously approved these changes Nov 4, 2021
cameel
cameel previously approved these changes Nov 4, 2021
Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

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

Looks fine as far as I can tell. Options seem fine at a glance, though if there are any subtleties involved, I probably would not spot them without digging into the docs.

I checked the build log and there are no warnings. I also downloaded the binary and tried to use it locally with solc-js and it works so at least it's not broken in an obvious way.

@ekpyron ekpyron dismissed stale reviews from cameel, axic, and chriseth via e7deedb November 4, 2021 14:32
@ekpyron
Copy link
Member Author

ekpyron commented Nov 4, 2021

Damn it, now I had to rebase due to a Changelog conflict due to the entry in #12236 (which was probably superfluous anyways) :-)... Can I trouble you guys for one more re-approval :-)?

@ekpyron ekpyron merged commit 386a5a5 into develop Nov 4, 2021
@ekpyron ekpyron deleted the emscriptenCMake branch November 4, 2021 15:20
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.

4 participants