Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: src/wasm/module-decoder.cc

Issue 2065043002: [wasm] Check for duplicate export names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix for empty exports table Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/wasm/module-decoder.h" 5 #include "src/wasm/module-decoder.h"
6 6
7 #include "src/base/functional.h" 7 #include "src/base/functional.h"
8 #include "src/base/platform/platform.h" 8 #include "src/base/platform/platform.h"
9 #include "src/macro-assembler.h" 9 #include "src/macro-assembler.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 351
352 module->export_table.push_back({0, // func_index 352 module->export_table.push_back({0, // func_index
353 0, // name_offset 353 0, // name_offset
354 0}); // name_length 354 0}); // name_length
355 WasmExport* exp = &module->export_table.back(); 355 WasmExport* exp = &module->export_table.back();
356 356
357 WasmFunction* func; 357 WasmFunction* func;
358 exp->func_index = consume_func_index(module, &func); 358 exp->func_index = consume_func_index(module, &func);
359 exp->name_offset = consume_string(&exp->name_length, true); 359 exp->name_offset = consume_string(&exp->name_length, true);
360 } 360 }
361 // Check for duplicate exports.
362 if (ok() && module->export_table.size() > 1) {
363 std::vector<WasmExport> sorted_exports(module->export_table);
titzer 2016/06/14 22:52:06 Can't we just do that when creating the exports ob
Clemens Hammacher 2016/06/15 07:48:09 We cannot report a validation error at that stage,
rossberg 2016/06/15 08:37:16 Yes, validation is required to flag it. You cannot
364 const byte* base = start_;
365 auto cmp = [base](const WasmExport& a, const WasmExport& b) {
366 // Return true if a < b.
367 uint32_t len = a.name_length;
368 if (len != b.name_length) return len < b.name_length;
369 return memcmp(base + a.name_offset, base + b.name_offset, len) <
370 0;
371 };
372 std::stable_sort(sorted_exports.begin(), sorted_exports.end(), cmp);
rossberg 2016/06/15 08:53:58 Instead of sorting the whole thing, would it be fa
Clemens Hammacher 2016/06/15 09:20:29 AFAIK sorting and scanning is the fastest way to c
373 auto it = sorted_exports.begin();
374 WasmExport* last = &*it++;
375 for (auto end = sorted_exports.end(); it != end;
376 last = &*it, ++it) {
rossberg 2016/06/15 08:53:58 Nit: superfluous newline?
Clemens Hammacher 2016/06/15 09:20:29 Nope, does not fit :) But I will change it to "las
377 DCHECK(!cmp(*it, *last));
378 if (!cmp(*last, *it)) {
379 const byte* pc = start_ + it->name_offset;
380 error(pc, pc,
381 "Duplicate export name '%.*s' for functions %d and %d",
382 it->name_length, pc, last->func_index, it->func_index);
383 break;
384 }
385 }
386 }
361 break; 387 break;
362 } 388 }
363 case WasmSection::Code::Max: 389 case WasmSection::Code::Max:
364 // Skip unknown sections. 390 // Skip unknown sections.
365 TRACE("Unknown section: '"); 391 TRACE("Unknown section: '");
366 for (uint32_t i = 0; i != string_length; ++i) { 392 for (uint32_t i = 0; i != string_length; ++i) {
367 TRACE("%c", *(section_name_start + i)); 393 TRACE("%c", *(section_name_start + i));
368 } 394 }
369 TRACE("'\n"); 395 TRACE("'\n");
370 consume_bytes(section_length); 396 consume_bytes(section_length);
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 return FunctionError("size > maximum function size"); 784 return FunctionError("size > maximum function size");
759 isolate->counters()->wasm_function_size_bytes()->AddSample( 785 isolate->counters()->wasm_function_size_bytes()->AddSample(
760 static_cast<int>(size)); 786 static_cast<int>(size));
761 WasmFunction* function = new WasmFunction(); 787 WasmFunction* function = new WasmFunction();
762 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); 788 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin);
763 return decoder.DecodeSingleFunction(module_env, function); 789 return decoder.DecodeSingleFunction(module_env, function);
764 } 790 }
765 } // namespace wasm 791 } // namespace wasm
766 } // namespace internal 792 } // namespace internal
767 } // namespace v8 793 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/wasm/export-table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698