4

Right in the docs for the address sanitizer (https://releases.llvm.org/7.0.0/tools/clang/docs/AddressSanitizer.html), it states that:

When linking shared libraries, the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link errors

That appears to be true not only for ASAN, but UBSAN as well. This turns out to be particularly inconvenient with UBSAN, since the vptr sanitizer can introduce new typeinfo dependencies between libraries (lots of details in https://jira.mongodb.org/browse/SERVER-49798).

I'd really prefer to build with -Wl,-z,defs for our UBSAN builds. And I can actually make that work with a ubsan build so far as the compile goes, by manually injecting things like -lclang_rt.ubsan_standalone-x86_64 into the link lines for the shared libraries.

But that leaves me with a nagging question: why doesn't the clang link driver do this automatically when linking shared libraries, per the explicit documentation? It clearly could do it, since it already does it for programs which get the runtime automatically. The fact that it explicitly doesn't leads me to wonder if doing so is somehow problematic.

  • Is forcing the ubsan runtime library onto the link line for all shared libraries a bad idea for some reason?
  • Does it undermine the effectiveness of the sanitizer somehow?
  • Is there some other horrible downside I'm not seeing?
acm
  • 12,183
  • 5
  • 39
  • 68
  • I used `-fsanitize=undefined,null,address,bounds,bool,enum` and I don't have to do anything special. – Eljay Mar 17 '21 at 23:35
  • @Eljay - Are you also linking shared libraries with `-Wl,-z,defs`? The question is explicitly about linking shared libraries when using the sanitizers, and why when building such libraries they don't include the runtime automatically, which makes use of `-Wl,-z,defs` impossible. – acm Mar 18 '21 at 00:40
  • Sorry acm, outside of my experience. – Eljay Mar 18 '21 at 00:59

0 Answers0