Closed omoerbeek closed 2 years ago
Looked at the code, but saw no obvious mistake in ServerPolicy
. LuaWrapper code is too smart/esoteric for me to grasp.
The above backtrace is from an amd64 system, the issue does not seem to happen on arm64 (also using clang-13).
The crash does not happen on Debian bookwork using clang-13. A fellow OpenBSD dev pointed me at https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=259921 so I'm investigating that.
It does seem to be a code generation issue specific to OpenBSD/amd64. Both arch and debian do not exhibit the problem.
Workaround is to compile dnsdist-lua-bindings.cc
with -O1
for now.
I don't see anything wrong either, the ServerPolicy
object is properly passed with std::forward
all the way, the initial constructor does copy the strings and the default-generated move constructor should thus be allowed to move them to the new object.
It's a shot in the dark but perhaps explicitly defining the move constructor would help:
ServerPolicy(ServerPolicy&& rhs) = default;
?
There are at least two ways to get rid of the issue. Both 1 and 2 are sufficient on their own to make the problem go away. I suspect the moving of a temp object triggers a bug in optimizations related to copy elision.
ServerPolicy(const ServerPolicy&) = default;
Defining (only) a move constructor as suggested does not compile as it implicitly deletes the copy ct. Defining both a default copy and move ct does not work and results in the very same crash.diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc
index bc264ab67..c5b66c6d1 100644
--- a/pdns/dnsdist-lua-bindings.cc
+++ b/pdns/dnsdist-lua-bindings.cc
@@ -69,12 +69,18 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
luaCtx.registerFunction("toString", &ServerPolicy::toString);
luaCtx.registerFunction("__tostring", &ServerPolicy::toString);
- luaCtx.writeVariable("firstAvailable", ServerPolicy{"firstAvailable", firstAvailable, false});
- luaCtx.writeVariable("roundrobin", ServerPolicy{"roundrobin", roundrobin, false});
- luaCtx.writeVariable("wrandom", ServerPolicy{"wrandom", wrandom, false});
- luaCtx.writeVariable("whashed", ServerPolicy{"whashed", whashed, false});
- luaCtx.writeVariable("chashed", ServerPolicy{"chashed", chashed, false});
- luaCtx.writeVariable("leastOutstanding", ServerPolicy{"leastOutstanding", leastOutstanding, false});
+ ServerPolicy policies[] = {
+ ServerPolicy{"firstAvailable", firstAvailable, false},
+ ServerPolicy{"roundrobin", roundrobin, false},
+ ServerPolicy{"wrandom", wrandom, false},
+ ServerPolicy{"whashed", whashed, false},
+ ServerPolicy{"chashed", chashed, false},
+ ServerPolicy{"leastOutstanding", leastOutstanding, false}
+ };
+ for (auto& policy : policies) {
+ luaCtx.writeVariable(policy.d_name, policy);
+ }
+
#endif /* DISABLE_POLICIES_BINDINGS */
/* ServerPool */
The suggested patch looks good to me, I'd merge that :)
OpenBSD recently moved to clang13. I'm seeing:
Looks like a move or copy constructor is called on an object that does not like to be moved or copied. Will investigate later (if nobody beats me to it).
Short description
Environment