terralang / terra

Terra is a low-level system programming language that is embedded in and meta-programmed by the Lua programming language.
terralang.org
Other
2.72k stars 201 forks source link

Segmentation fault when calling any terra function after disassembling code with missing library #450

Open aiverson opened 4 years ago

aiverson commented 4 years ago

If a piece of terra code requires a shared library that hasn't been loaded using terralib.linklibrary, and the method :disas() is called on the function, calling a terra function afterwards will segfault even though it doesn't use any missing functions. The other terra function can still be compiled, disassembled, saved to files, etc.

Minimal reproducer:

local terra foo(a: int) return a + 2 end
terralib.saveobj("libfoo.so", {foo = foo})

foo = terralib.externfunction("foo", int -> int)

local terra bar() return foo(5) end

terralib.linklibrary("./libfoo.so") -- line A

bar:disas() -- line B

print()
local terra baz() return 5 end
print("should print 5:", baz()) -- line C

If line A is commented and lines B and C are uncommented, this code segfaults. In all other combinations, it runs as expected with no error messages, diagnostics, or warnings.