Bruno Haible [2025-10-26 22:13 +0100] wrote:

> Basil L. Contovounesios wrote:
>> > CC="clang -Wl,-rpath,$CLANG_INSTALLATION_DIR/lib -fsanitize=address"
>> 
>> Is it sufficient to specify the -rpath, without the need for the
>> LD_PRELOAD hack (see below)?
>
> That depends whether the library that you link with, which according
> to Collin's mail is libclang_rt.asan.so, depends on the library
> which you have in LD_PRELOAD, namely libclang_rt.asan-$(uname -m).so.
> If it has this dependency, you shouldn't need the LD_PRELOAD.

I'm not linking with (or depending on) the former directly; that error
message comes from passing -fsanitize=address -shared-libasan to Clang.

AFAICT, both of the libraries you mention should be one and the same,
namely Clang's run-time support for ASan (which needs to both be linked
with, and later preloaded for its interceptors to work).

>> > CFLAGS="-O0 -fno-omit-frame-pointer -ggdb"
>> 
>> [ Just to be clear, these CFLAGS should be needed only for debugging. ]
>
> These CFLAGS are also needed for reasonable stack traces in the log,
> AFAIU.

Yes, that's what I was (slightly tongue-in-cheek) referring to as
debugging.  IOW, my understanding of the docs is that these flags are
not essential for ASan to operate correctly (e.g. the docs also mention
-O1 or higher for better performance), only optional for more detailed
traces.

>> >    but instead playing with libclang_rt in undocumented ways,
>> 
>> It's a hack, but it's the only documented way to load an
>> instrumented shared object into an uninstrumented binary:
>> - https://github.com/google/sanitizers/wiki/AddressSanitizerAsDso
>
> Ho hmm. A wiki page for the predecessor of the LLVM analyzer (the
> Google analyzer), from 2015, which says "ASAN-DSO is not (yet?)
> officially supported. Use it at your own risk." To me, that counts
> as undocumented.

What's 10 years between friends ;).  FWIW, the same advice is repeated
by the LLVM maintainers in the bug reports.  My guess is that this is
about as documented (and officially supported) as I can hope for, at
least in the near future.

-- 
Basil

Reply via email to