Skip to content

EXPORTED_FUNCTIONS option will cause an error #6

Description

@xiaoqunSun

I build wasm use EXPORTED_FUNCTIONS option to reduce size

-s EXPORT_NAME=${APP_NAME}  -s MODULARIZE=1 -s EXPORTED_FUNCTIONS=[_get_version,_bezier_intersect,_free_pointer,_malloc,_free]

throw error at EmscriptenModule._fromJs

factory EmscriptenModule._fromJs(_EmscriptenModuleJs module) {
    Object? asm = module.asm;
    if (asm != null) {
      Map<int, WasmSymbol> knownAddresses = {};
      _Malloc? malloc;
      _Free? free;
      List<WasmSymbol> exports = [];
      List? entries = _entries(asm);
      if (entries != null) {
        for (dynamic entry in entries) {
          if (entry is List) {
            Object value = entry.last;
            //String type = value.runtimeType.t oString();
            //print(type);
            if (value is int) {
              Global g =
                  new Global(address: value, name: entry.first as String);
              if (knownAddresses.containsKey(value) &&
                  knownAddresses[value] is! Global) {
                throw new StateError(_adu(knownAddresses[value], g));
              }
              knownAddresses[value] = g;
              exports.add(g);
            } else if (value is Function) {
              FunctionDescription description =
                  _fromWasmFunction(entry.first as String, value);
              // It might happen that there are two different c functions that do nothing else than calling the same underlying c function
              // In this case, a compiler might substitute both functions with the underlying c function
              // So we got two functions with different names at the same table index
              // So it is actually ok if there are two things at the same address, as long as they are both functions
              if (knownAddresses.containsKey(description.tableIndex) &&
                  knownAddresses[description.tableIndex]
                      is! FunctionDescription) {
                throw new StateError(
                    _adu(knownAddresses[description.tableIndex], description));
              }
              knownAddresses[description.tableIndex] = description;
              exports.add(description);
              if (description.name == 'malloc') {
                malloc = description.function as _Malloc;
              } else if (description.name == 'free') {
                free = description.function as _Free;
              }
            } else {
              // throw new StateError(
              //     'Unexpected value in entry list! Entry is $entry, value is $value (of type ${value.runtimeType})');
            }
          } else {
            throw new StateError(
                'Unexpected entry in entries(Module[\'asm\'])!');
          }
        }
        if (malloc != null) {
          if (free != null) {
            return new EmscriptenModule._(module, exports, malloc, free);
          } else {
            throw new StateError('Module does not export the free function!');
          }
        } else {
          throw new StateError('Module does not export the malloc function!');
        }
      } else {
        throw new StateError(
            'JavaScript error: Could not access entries of Module[\'asm\']!');
      }
    } else {
      throw new StateError(
          'Could not access Module[\'asm\'], are your sure your module was compiled using emscripten?');
    }

because asm object contains WebAssembly.Memory,WebAssembly.Table which is neither int nor Functio
algorithm.zip
n

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions