summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2020-12-04 21:36:01 -0800
committerGitHub <noreply@github.com>2020-12-04 21:36:01 -0800
commit51dfeef750acacea8dd1331213aa87ae76423dea (patch)
tree8ce468d30222381d52d4544889d91f1c29dc2a69 /src
parentb501c243b0f0949438e98336c86e1942725fcbda (diff)
downloadbinaryen-51dfeef750acacea8dd1331213aa87ae76423dea.tar.gz
binaryen-51dfeef750acacea8dd1331213aa87ae76423dea.tar.bz2
binaryen-51dfeef750acacea8dd1331213aa87ae76423dea.zip
wasm-emscripten-finalize: Support PIC + threads (#3427)
With PIC + threads the offset of passive segments is not constant but relative to `__memory_base`. When trying to find passive segment offset based on the target of the `memory.init` instruction we need to consider this possibility as well as the regular constant one. For the llvm side of this that generates the calls to memory.init see: https://reviews.llvm.org/D92620
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 19498300f..f8dc16a32 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -85,9 +85,19 @@ std::vector<Address> getSegmentOffsets(Module& wasm) {
OffsetSearcher(std::unordered_map<unsigned, Address>& offsets)
: offsets(offsets) {}
void visitMemoryInit(MemoryInit* curr) {
+ // The desitination of the memory.init is either a constant
+ // or the result of an addition with __memory_base in the
+ // case of PIC code.
auto* dest = curr->dest->dynCast<Const>();
if (!dest) {
- return;
+ auto* add = curr->dest->dynCast<Binary>();
+ if (!add) {
+ return;
+ }
+ dest = add->left->dynCast<Const>();
+ if (!dest) {
+ return;
+ }
}
auto it = offsets.find(curr->segment);
if (it != offsets.end()) {
@@ -170,9 +180,7 @@ std::string codeForConstAddr(Module& wasm,
int32_t address) {
const char* str = stringAtAddr(wasm, segmentOffsets, address);
if (!str) {
- // If we can't find the segment corresponding with the address, then we
- // omitted the segment and the address points to an empty string.
- return escape("");
+ Fatal() << "unable to find data for ASM/EM_JS const at: " << address;
}
return escape(str);
}