[llvm] r322343 - [WebAssembly] Don't allow functions to be named twice
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 11 18:11:31 PST 2018
Author: sbc
Date: Thu Jan 11 18:11:31 2018
New Revision: 322343
URL: http://llvm.org/viewvc/llvm-project?rev=322343&view=rev
Log:
[WebAssembly] Don't allow functions to be named twice
The spec doesn't allow this.
Differential Revision: https://reviews.llvm.org/D41974
Added:
llvm/trunk/test/Object/wasm-duplicate-name.test
Modified:
llvm/trunk/lib/Object/WasmObjectFile.cpp
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=322343&r1=322342&r2=322343&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Thu Jan 11 18:11:31 2018
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
@@ -268,6 +269,8 @@ Error WasmObjectFile::parseSection(WasmS
}
Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) {
+ llvm::DenseSet<uint64_t> Seen;
+
while (Ptr < End) {
uint8_t Type = readVarint7(Ptr);
uint32_t Size = readVaruint32(Ptr);
@@ -277,6 +280,9 @@ Error WasmObjectFile::parseNameSection(c
uint32_t Count = readVaruint32(Ptr);
while (Count--) {
uint32_t Index = readVaruint32(Ptr);
+ if (!Seen.insert(Index).second)
+ return make_error<GenericBinaryError>("Function named more than once",
+ object_error::parse_failed);
StringRef Name = readString(Ptr);
if (!Name.empty())
Symbols.emplace_back(Name,
@@ -375,7 +381,6 @@ Error WasmObjectFile::parseLinkingSectio
uint32_t Count = readVaruint32(Ptr);
while (Count--) {
StringRef Symbol = readString(Ptr);
- DEBUG(dbgs() << "reading syminfo: " << Symbol << "\n");
uint32_t Flags = readVaruint32(Ptr);
auto iter = SymbolMap.find(Symbol);
if (iter == SymbolMap.end()) {
Added: llvm/trunk/test/Object/wasm-duplicate-name.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/wasm-duplicate-name.test?rev=322343&view=auto
==============================================================================
--- llvm/trunk/test/Object/wasm-duplicate-name.test (added)
+++ llvm/trunk/test/Object/wasm-duplicate-name.test Thu Jan 11 18:11:31 2018
@@ -0,0 +1,28 @@
+# RUN: yaml2obj %s | not llvm-objdump -h - 2>&1 | FileCheck %s
+
+--- !WASM
+FileHeader:
+ Version: 0x00000001
+Sections:
+ - Type: TYPE
+ Signatures:
+ - Index: 0
+ ReturnType: I32
+ ParamTypes:
+ - I32
+ - Type: IMPORT
+ Imports:
+ - Module: foo
+ Field: a
+ Kind: FUNCTION
+ SigIndex: 0
+ - Type: CUSTOM
+ Name: name
+ FunctionNames:
+ - Index: 0
+ Name: a
+ - Index: 0
+ Name: b
+...
+
+# CHECK: {{.*}}: Function named more than once
More information about the llvm-commits
mailing list