Make getInternalName const
diff --git a/src/passes/EncloseWorld.cpp b/src/passes/EncloseWorld.cpp
index 2061937..5ac9067 100644
--- a/src/passes/EncloseWorld.cpp
+++ b/src/passes/EncloseWorld.cpp
@@ -52,12 +52,11 @@
     std::vector<std::unique_ptr<Export>> newExports;
     for (auto& ex : module->exports) {
       if (ex->kind == ExternalKind::Function) {
-        auto* name = ex->getInternalName();
-        auto* func = module->getFunction(*name);
+        auto* func = module->getFunction(*ex->getInternalName());
         // If this opens up types, replace it with an enclosed stub.
         if (opensTypes(func)) {
           auto stubName = makeStubStubForExport(func, module);
-          *name = stubName;
+          ex->setInternalName(stubName);
         }
       }
     }
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp
index 4bb7491..e792195 100644
--- a/src/passes/LegalizeJSInterface.cpp
+++ b/src/passes/LegalizeJSInterface.cpp
@@ -71,12 +71,11 @@
     for (auto& ex : module->exports) {
       if (ex->kind == ExternalKind::Function) {
         // if it's an import, ignore it
-        auto* name = ex->getInternalName();
-        auto* func = module->getFunction(*name);
+        auto* func = module->getFunction(*ex->getInternalName());
         if (isIllegal(func)) {
           // Provide a legal function for the export.
           auto legalName = makeLegalStub(func, module);
-          *name = legalName;
+          ex->setInternalName(legalName);
           if (exportOriginals) {
             // Also export the original function, before legalization. This is
             // not normally useful for JS, except in cases like dynamic linking
diff --git a/src/passes/MultiMemoryLowering.cpp b/src/passes/MultiMemoryLowering.cpp
index ffc489d..816d641 100644
--- a/src/passes/MultiMemoryLowering.cpp
+++ b/src/passes/MultiMemoryLowering.cpp
@@ -716,7 +716,7 @@
         // We checked in prepCombinedMemory that any memory exports are for
         // the first memory, so setting the exports to the combinedMemory means
         // calling JS will not have to worry about offsets
-        *exp->getInternalName() = combinedMemory;
+        exp->setInternalName(combinedMemory);
       }
     }
   }
diff --git a/src/passes/PostEmscripten.cpp b/src/passes/PostEmscripten.cpp
index 533e525..febf3f9 100644
--- a/src/passes/PostEmscripten.cpp
+++ b/src/passes/PostEmscripten.cpp
@@ -133,7 +133,7 @@
   wasm.getDataSegment(segment)->data.resize(0);
 }
 
-static Address getExportedAddress(Module& wasm, Export* export_) {
+static Address getExportedAddress(const Module& wasm, const Export* export_) {
   Global* g = wasm.getGlobal((export_->kind == ExternalKind::Global)
                                ? *export_->getInternalName()
                                : Name());
@@ -145,8 +145,8 @@
                        const std::vector<Address>& segmentOffsets,
                        Name start_sym,
                        Name end_sym) {
-  Export* start = wasm.getExportOrNull(start_sym);
-  Export* end = wasm.getExportOrNull(end_sym);
+  const Export* start = wasm.getExportOrNull(start_sym);
+  const Export* end = wasm.getExportOrNull(end_sym);
   if (!start && !end) {
     BYN_TRACE("removeData: start/stop symbols not found (" << start_sym << ", "
                                                            << end_sym << ")\n");
diff --git a/src/passes/RemoveUnusedModuleElements.cpp b/src/passes/RemoveUnusedModuleElements.cpp
index ee2079b..cf917cc 100644
--- a/src/passes/RemoveUnusedModuleElements.cpp
+++ b/src/passes/RemoveUnusedModuleElements.cpp
@@ -1086,8 +1086,7 @@
         continue;
       }
 
-      auto* name = exp->getInternalName();
-      auto* func = module->getFunction(*name);
+      auto* func = module->getFunction(*exp->getInternalName());
       if (!func->body) {
         continue;
       }
@@ -1114,7 +1113,7 @@
         }
       }
       if (ok) {
-        *name = calledFunc->name;
+        exp->setInternalName(calledFunc->name);
       }
     }
   }
diff --git a/src/passes/opt-utils.h b/src/passes/opt-utils.h
index 2e25a6a..6e7d1dc 100644
--- a/src/passes/opt-utils.h
+++ b/src/passes/opt-utils.h
@@ -104,7 +104,10 @@
   // replace in exports
   for (auto& exp : module.exports) {
     if (exp->kind == ExternalKind::Function) {
-      maybeReplace(*exp->getInternalName());
+      auto iter = replacements.find(*exp->getInternalName());
+      if (iter != replacements.end()) {
+        exp->setInternalName(iter->second);
+      }
     }
   }
 }
diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp
index a948f25..37c39c0 100644
--- a/src/tools/wasm-ctor-eval.cpp
+++ b/src/tools/wasm-ctor-eval.cpp
@@ -1305,7 +1305,7 @@
          (localExprs.size() && func->getParams() != Type::none))) {
       auto originalFuncType = wasm.getFunction(funcName)->type;
       auto copyName = Names::getValidFunctionName(wasm, funcName);
-      *wasm.getExport(exportName)->getInternalName() = copyName;
+      wasm.getExport(exportName)->setInternalName(copyName);
 
       if (func->imported()) {
         // We must have return-called this imported function. Generate a new
@@ -1493,7 +1493,7 @@
           assert(copyFunc->body);
         }
         wasm.addFunction(std::move(copyFunc));
-        *wasm.getExport(exp->name)->getInternalName() = copyName;
+        wasm.getExport(exp->name)->setInternalName(copyName);
       }
     }
   } catch (FailToEvalException& fail) {
diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp
index 4c57f79..ea4d4fb 100644
--- a/src/tools/wasm-merge.cpp
+++ b/src/tools/wasm-merge.cpp
@@ -233,8 +233,10 @@
     void mapModuleFields(Module& wasm) {
       for (auto& curr : wasm.exports) {
         // skip type exports
-        if (auto* name = curr->getInternalName()) {
-          mapName(ModuleItemKind(curr->kind), *name);
+        if (auto* internalName = curr->getInternalName()) {
+          Name name = *internalName;
+          mapName(ModuleItemKind(curr->kind), name);
+          curr->setInternalName(name);
         }
       }
       for (auto& curr : wasm.elementSegments) {
diff --git a/src/wasm.h b/src/wasm.h
index 6574338..22a75ad 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -2607,7 +2607,7 @@
     : name(name), kind(kind), value(value) {
     assert(std::get_if<Name>(&value));
   }
-  Name* getInternalName() { return std::get_if<Name>(&value); }
+  const Name* getInternalName() const { return std::get_if<Name>(&value); }
   void setInternalName(Name name) {
     assert(std::holds_alternative<Name>(value));
     value = name;