Skip to content

Commit 132daae

Browse files
authored
Revert "Reland "Fix renaming in FixInvokeFunctionNamesWalker (#2513)" (#2542)" (#2576)
This reverts commit f62e171.
1 parent e8f9d20 commit 132daae

File tree

8 files changed

+72
-462
lines changed

8 files changed

+72
-462
lines changed

scripts/test/generate_lld_tests.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def files_with_extensions(path, extensions):
3030
yield file, ext
3131

3232

33-
def generate_wat_files(llvm_bin, emscripten_root):
34-
print('\n[ building wat files from C sources... ]\n')
33+
def generate_wast_files(llvm_bin, emscripten_root):
34+
print('\n[ building wast files from C sources... ]\n')
3535

3636
lld_path = os.path.join(shared.options.binaryen_test, 'lld')
3737
for src_file, ext in files_with_extensions(lld_path, ['.c', '.cpp']):
@@ -42,11 +42,11 @@ def generate_wat_files(llvm_bin, emscripten_root):
4242
obj_path = os.path.join(lld_path, obj_file)
4343

4444
wasm_file = src_file.replace(ext, '.wasm')
45-
wat_file = src_file.replace(ext, '.wat')
45+
wast_file = src_file.replace(ext, '.wast')
4646

4747
obj_path = os.path.join(lld_path, obj_file)
4848
wasm_path = os.path.join(lld_path, wasm_file)
49-
wat_path = os.path.join(lld_path, wat_file)
49+
wast_path = os.path.join(lld_path, wast_file)
5050
is_shared = 'shared' in src_file
5151

5252
compile_cmd = [
@@ -70,10 +70,6 @@ def generate_wat_files(llvm_bin, emscripten_root):
7070
'--export', '__data_end',
7171
'--global-base=568',
7272
]
73-
# We had a regression where this test only worked if debug names
74-
# were included.
75-
if 'longjmp' in src_file:
76-
link_cmd.append('--strip-debug')
7773
if is_shared:
7874
compile_cmd.append('-fPIC')
7975
compile_cmd.append('-fvisibility=default')
@@ -84,7 +80,7 @@ def generate_wat_files(llvm_bin, emscripten_root):
8480
try:
8581
support.run_command(compile_cmd)
8682
support.run_command(link_cmd)
87-
support.run_command(shared.WASM_DIS + [wasm_path, '-o', wat_path])
83+
support.run_command(shared.WASM_DIS + [wasm_path, '-o', wast_path])
8884
finally:
8985
# Don't need the .o or .wasm files, don't leave them around
9086
shared.delete_from_orbit(obj_path)
@@ -95,4 +91,4 @@ def generate_wat_files(llvm_bin, emscripten_root):
9591
if len(shared.options.positional_args) != 2:
9692
print('Usage: generate_lld_tests.py [llvm/bin/dir] [path/to/emscripten]')
9793
sys.exit(1)
98-
generate_wat_files(*shared.options.positional_args)
94+
generate_wast_files(*shared.options.positional_args)

scripts/test/shared.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def parse_args(args):
8787

8888
options = parse_args(sys.argv[1:])
8989
requested = options.positional_args
90-
script_dir = os.path.dirname(os.path.abspath(__file__))
9190

9291
num_failures = 0
9392
warnings = []
@@ -124,7 +123,8 @@ def warn(text):
124123

125124
# Locate Binaryen source directory if not specified.
126125
if not options.binaryen_root:
127-
options.binaryen_root = os.path.dirname(os.path.dirname(script_dir))
126+
path_parts = os.path.abspath(__file__).split(os.path.sep)
127+
options.binaryen_root = os.path.sep.join(path_parts[:-3])
128128

129129
options.binaryen_test = os.path.join(options.binaryen_root, 'test')
130130

@@ -205,7 +205,8 @@ def wrap_with_valgrind(cmd):
205205

206206

207207
def in_binaryen(*args):
208-
return os.path.join(options.binaryen_root, *args)
208+
__rootpath__ = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
209+
return os.path.join(__rootpath__, *args)
209210

210211

211212
os.environ['BINARYEN'] = in_binaryen()

src/wasm/wasm-emscripten.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,11 @@ struct FixInvokeFunctionNamesWalker
994994
: public PostWalker<FixInvokeFunctionNamesWalker> {
995995
Module& wasm;
996996
std::map<Name, Name> importRenames;
997-
std::map<Name, Name> functionReplace;
997+
std::vector<Name> toRemove;
998+
std::set<Name> newImports;
998999
std::set<Signature> invokeSigs;
999-
ImportInfo imports;
10001000

1001-
FixInvokeFunctionNamesWalker(Module& _wasm) : wasm(_wasm), imports(wasm) {}
1001+
FixInvokeFunctionNamesWalker(Module& _wasm) : wasm(_wasm) {}
10021002

10031003
// Converts invoke wrapper names generated by LLVM backend to real invoke
10041004
// wrapper names that are expected by JavaScript glue code.
@@ -1053,38 +1053,27 @@ struct FixInvokeFunctionNamesWalker
10531053
return;
10541054
}
10551055

1056-
BYN_TRACE("renaming import: " << curr->module << "." << curr->base << " ("
1057-
<< curr->name << ") -> " << newname << "\n");
1058-
assert(importRenames.count(curr->base) == 0);
1059-
importRenames[curr->base] = newname;
1060-
// Either rename the import, or replace it with an existing one
1061-
Function* existingFunc = imports.getImportedFunction(curr->module, newname);
1062-
if (existingFunc) {
1063-
BYN_TRACE("replacing with an existing import: " << existingFunc->name
1064-
<< "\n");
1065-
functionReplace[curr->name] = existingFunc->name;
1056+
assert(importRenames.count(curr->name) == 0);
1057+
BYN_TRACE("renaming: " << curr->name << " -> " << newname << "\n");
1058+
importRenames[curr->name] = newname;
1059+
// Either rename or remove the existing import
1060+
if (wasm.getFunctionOrNull(newname) || !newImports.insert(newname).second) {
1061+
toRemove.push_back(curr->name);
10661062
} else {
1067-
BYN_TRACE("renaming the import in place\n");
10681063
curr->base = newname;
1064+
curr->name = newname;
10691065
}
10701066
}
10711067

10721068
void visitModule(Module* curr) {
1073-
// For each replaced function first remove the function itself then
1074-
// rename all uses to the point to the new function.
1075-
for (auto& pair : functionReplace) {
1076-
BYN_TRACE("removeFunction " << pair.first << "\n");
1077-
wasm.removeFunction(pair.first);
1069+
for (auto importName : toRemove) {
1070+
wasm.removeFunction(importName);
10781071
}
1079-
// Rename all uses of the removed functions
1080-
ModuleUtils::renameFunctions(wasm, functionReplace);
1081-
1082-
// For imports that for renamed, update any associated GOT.func imports.
1072+
ModuleUtils::renameFunctions(wasm, importRenames);
1073+
ImportInfo imports(wasm);
10831074
for (auto& pair : importRenames) {
1084-
BYN_TRACE("looking for: GOT.func." << pair.first << "\n");
1075+
// Update any associated GOT.func import.
10851076
if (auto g = imports.getImportedGlobal("GOT.func", pair.first)) {
1086-
BYN_TRACE("renaming corresponding GOT entry: " << g->base << " -> "
1087-
<< pair.second << "\n");
10881077
g->base = pair.second;
10891078
}
10901079
}

test/lld/longjmp.c

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/lld/longjmp.wat

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)