summaryrefslogtreecommitdiff
path: root/src/wasm-linker.h
diff options
context:
space:
mode:
authorDominic Chen <d.c.ddcc@gmail.com>2016-08-02 18:01:26 -0700
committerDerek Schuff <dschuff@chromium.org>2016-08-02 18:01:26 -0700
commit959bc7638aebb27fcdf7079daf0d0cafe845f56a (patch)
treeb828306bed585ccda4102219c187fd8dbbe08eaf /src/wasm-linker.h
parent4268555dfd7887ff1110fb02717807f42616125e (diff)
downloadbinaryen-959bc7638aebb27fcdf7079daf0d0cafe845f56a.tar.gz
binaryen-959bc7638aebb27fcdf7079daf0d0cafe845f56a.tar.bz2
binaryen-959bc7638aebb27fcdf7079daf0d0cafe845f56a.zip
support pre-assigning indexes for functions that are called indirectly (#616)
This patch adds support for an ".indidx" primitive that pre-assigns table indexes for functions that are called indirectly. It is used by the upstream LLVM WebAssembly backend to support fine-grained control-flow integrity for indirect function calls by emitting instrumentation at each indirect call site to check that the destination index is within certain ranges that correspond to disjoint equivalence classes of indirect call targets. The reason that this primitive is necessary is because the layout of the table section isn't determined until the WebAssembly linker is executed, but indirect function to table index mappings need to be known when opt is executed to generate the correct range checking in the LLVM IR.
Diffstat (limited to 'src/wasm-linker.h')
-rw-r--r--src/wasm-linker.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wasm-linker.h b/src/wasm-linker.h
index 535b5dc55..701585190 100644
--- a/src/wasm-linker.h
+++ b/src/wasm-linker.h
@@ -141,6 +141,11 @@ class LinkerObject {
return f->second;
}
+ void addIndirectIndex(Name name, Address index) {
+ assert(!indirectIndexes.count(name));
+ indirectIndexes[name] = index;
+ }
+
bool isEmpty() {
return wasm.functions.empty();
}
@@ -173,6 +178,9 @@ class LinkerObject {
std::map<Name, Address> segments; // name => segment index (in wasm module)
+ // preassigned indexes for functions called indirectly
+ std::map<Name, Address> indirectIndexes;
+
std::vector<Name> initializerFunctions;
LinkerObject(const LinkerObject&) = delete;
@@ -309,8 +317,8 @@ class Linker {
std::unordered_map<cashew::IString, int32_t> staticAddresses; // name => address
std::unordered_map<Address, Address> segmentsByAddress; // address => segment index
- std::unordered_map<cashew::IString, size_t> functionIndexes;
-
+ std::unordered_map<cashew::IString, Address> functionIndexes;
+ std::map<Address, cashew::IString> functionNames;
};