Skip to content

finalize: strip segments that contain only EM_ASM/EM_JS data - #3557

Merged
sbc100 merged 1 commit into
mainfrom
remove_em_js_section
Feb 12, 2021
Merged

sbc100 merged 1 commit into
mainfrom
remove_em_js_section

Conversation

@sbc100

@sbc100 sbc100 commented Feb 8, 2021 •

Copy link
Copy Markdown
Member

If we find a data segment whose entire contents is EM_JS or EM_ASM
strings then strip it from the binary.

This change also introduces a new way to exact EM_ASM strings based
on the _start and stop sections symbols. This code will no be active
until the emscripten-side change lands.

See: emscripten-core/emscripten#13443

@sbc100
sbc100 requested a review from tlively February 8, 2021 23:07
@sbc100
sbc100 force-pushed the remove_em_js_section branch 5 times, most recently from 5afa64c to 52441fb Compare February 8, 2021 23:27
An error occurred while trying to automatically change base from refactor_string_tracking to main February 8, 2021 23:27
@sbc100 sbc100 changed the title finalize: Strip segments that contains only EM_ASM/EM_JS data finalize: strip segments that contain only EM_ASM/EM_JS data Feb 8, 2021
@sbc100

sbc100 commented Feb 9, 2021

Copy link
Copy Markdown
Member Author

Hmm.. how come the UI is saying I can merge this without a review? Does binaryen not require an lgtm?

@sbc100
sbc100 force-pushed the remove_em_js_section branch from 52441fb to 01b115a Compare February 9, 2021 03:50
@sbc100
sbc100 changed the base branch from refactor_string_tracking to main February 9, 2021 03:52
@tlively

tlively commented Feb 9, 2021

Copy link
Copy Markdown
Member

That's weird, it should require an LGTM

@sbc100

sbc100 commented Feb 9, 2021

Copy link
Copy Markdown
Member Author

Ah.. its because I wasn't targeting main. Fixed.

@sbc100
sbc100 force-pushed the remove_em_js_section branch from 01b115a to 64b8741 Compare February 9, 2021 03:57
Comment thread src/wasm/wasm-emscripten.cpp Resolved
Comment thread src/wasm/wasm-emscripten.cpp Resolved
@sbc100
sbc100 force-pushed the remove_em_js_section branch 3 times, most recently from ec8fddd to 91f5cb5 Compare February 11, 2021 01:56
@sbc100

sbc100 commented Feb 11, 2021

Copy link
Copy Markdown
Member Author

This change now handle EM_ASM strings too.

@sbc100
sbc100 requested a review from tlively February 11, 2021 19:03
@sbc100
sbc100 force-pushed the remove_em_js_section branch from 91f5cb5 to 5e78ba6 Compare February 11, 2021 19:05
Comment on lines +352 to +359
// Older versions of emscripten don't export these symbols. Instead
// we run AsmConstWalker in an attempt to derive the string addresses
// from the code.
if (!start || !end) {
AsmConstWalker walker(wasm, minimizeWasmChanges);
walker.process();
return walker.asmConsts;
}

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.

Are planning to remove this fallback code in the future? What is stopping us from removing it now?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. Mostly its a transition thing. I can't land the emscripten-side change first because it actually changes the way that arg0 gets passed the em_asm functions. llvm ends up storing that address of the string in memory and then loading it back (at least in -O0) which is not currently supported by the AsmConstWalker. So if I land the emscripten side first it would break this pass.

Comment on lines +15 to +16
;; CHECK: (data (i32.const 1024) "some JS string data\00xxx")
;; CHECK: (data (i32.const 2048) "more JS string data\00yyy")

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.

Why aren't the JS strings zeroed out?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've only done the zeroing out thing for the em_asm path so far. The reason is that I don't currently use the start/end symbols for the em_js path at all. I think we can do that a followup perhaps, and maybe even completely remove the current 1-export-per-em-js thing.

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.

Gotcha. The difference between EM_JS and EM_ASM still confuses me, but that's ok.

@sbc100
sbc100 enabled auto-merge (squash) February 11, 2021 19:48
If we find a data segment whose entire contents is EM_JS or EM_ASM
strings then strip it from the binary.

See: emscripten-core/emscripten#13443
@sbc100
sbc100 force-pushed the remove_em_js_section branch from 3da8d22 to 00ecb51 Compare February 12, 2021 00:28
@sbc100
sbc100 merged commit 8369064 into main Feb 12, 2021
@sbc100
sbc100 deleted the remove_em_js_section branch February 12, 2021 00:53
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