1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

[WebAssembly] Don't allow functions to be named twice

The spec doesn't allow this.

Differential Revision: https://reviews.llvm.org/D41974

llvm-svn: 322343
This commit is contained in:
Sam Clegg 2018-01-12 02:11:31 +00:00
parent 03fe6a20b4
commit f220eca523
2 changed files with 34 additions and 1 deletions

View File

@ -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(WasmSection &Sec) {
}
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(const uint8_t *Ptr, const uint8_t *End) {
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::parseLinkingSection(const uint8_t *Ptr,
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()) {

View File

@ -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