Re: How to use gcc with sanitizers in Void Linux?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Nan,

on 2019/12/27 上午11:23, Nan Xiao wrote:
> Hi Kewen,
> 
> Thanks very much for your time and kind explanation!
> 
> I am very sorry for making a big mistake yesterday. What I said work
> was actually following command:
> 
> $ gcc -std=c11 -static-libasan test.c
> 
> I forgot to add "-fsanitize=address", after adding
> "-fsanitize=address", it reported following error:
> 
> $ gcc -std=c11 -fsanitize=address -static-libasan test.c
> gcc: fatal error: cannot read spec file 'libsanitizer.spec': No such
> file or directory
> compilation terminated.
> 

Ah, no problem, it makes more sense now.

> I installed gcc from Void Linux's official package. So it means this
> gcc doesn't support ASAN?

Your gcc supports ASAN feature but it isn't shipped with ASAN libs.
I'm afraid you have to install ASAN related libs by yourself.

xbps query and install something like libasan*.


BR,
Kewen

> 
> But from "gcc -v" output, I can't see "--disable-libsanitizer".
> 
> Thanks very much again for your time!
> 
> Best Regards
> Nan Xiao
> 
> On Fri, Dec 27, 2019 at 10:27 AM Kewen.Lin <linkw@xxxxxxxxxxxxx> wrote:
>>
>> Hi Nan,
>>
>> on 2019/12/26 下午6:16, Nan Xiao wrote:
>>> Hi Kewen,
>>>
>>> Thanks very much for your quick response!
>>>
>>> Yes, after adding "-static-libasan", the compilation is successful!
>>>
>>
>> Good to know that, but it's a bit weird that DSO way doesn't work.
>> I noticed that w/ and w/o -static-libasan both need object file libasan_preinit.o.
>> But the compilation w/o -static-libasan complains no file "libasan_preinit.o".
>> Could you append option "-v" to both compilation commands w/ and w/o -static-libasan,
>> and check the location which holds static libasan whether have the shared version?
>>
>> If your gcc was installed by packages instead of building from scratch by yourself,
>> is it possible due to that current env only installs static libasan but not shared.
>> Try to install the shared version libasan additionally if yes?
>>
>> Sorry, I can't mimic this symptom in local env exactly, just guess.  HTH.
>>
>> BR,
>> Kewen
>>
>>> But I checked the output of "gcc -v", there is no "--disable-libsanitizer":
>>>
>>> $ gcc -v
>>> Using built-in specs.
>>> COLLECT_GCC=gcc
>>> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/9.2.0/lto-wrapper
>>> Target: x86_64-unknown-linux-gnu
>>> Configured with: /builddir/gcc-9.2.0/configure
>>> --build=x86_64-unknown-linux-gnu --enable-fast-character
>>> --enable-vtable-verify --prefix=/usr --mandir=/usr/share/man
>>> --infodir=/usr/share/info --libexecdir=/usr/lib --libdir=/usr/lib
>>> --enable-threads=posix --enable-__cxa_atexit --disable-multilib
>>> --with-system-zlib --enable-shared --enable-lto --enable-plugins
>>> --enable-linker-build-id --disable-werror --disable-nls
>>> --enable-default-pie --enable-default-ssp --enable-checking=release
>>> --disable-libstdcxx-pch --with-isl --with-linker-hash-style=gnu
>>> --disable-libunwind-exceptions --disable-target-libiberty
>>> --enable-serial-configure
>>> --enable-languages=c,c++,objc,obj-c++,fortran,lto,go,ada
>>> Thread model: posix
>>> gcc version 9.2.0 (GCC)
>>>
>>> Thanks!
>>>
>>> Best Regards
>>> Nan Xiao
>>>
>>> On Thu, Dec 26, 2019 at 6:01 PM Kewen.Lin <linkw@xxxxxxxxxxxxx> wrote:
>>>>
>>>> Hi Nan,
>>>>
>>>> on 2019/12/26 下午4:48, Nan Xiao wrote:
>>>>> Hi gcc community,
>>>>>
>>>>> Greetings from me!
>>>>>
>>>>> I am using Void Linux, and want to use sanitizers. Using clang to
>>>>> compile code, it is OK:
>>>>>
>>>>> $ clang -std=c11 -fsanitize=address test.c
>>>>> $
>>>>>
>>>>> While gcc reports following errors:
>>>>>
>>>>> $ gcc -std=c11 -fsanitize=address test.c
>>>>> /usr/bin/ld: cannot find libasan_preinit.o: No such file or directory
>>>>> /usr/bin/ld: cannot find -lasan
>>>>> collect2: error: ld returned 1 exit status
>>>>>
>>>>
>>>> May I suggest you checking your gcc whether disabled libsanitizer support?
>>>> GCC configuration allows you to build one gcc without libsanitizer support
>>>> with --disable-libsanitizer.  "gcc -v" can show the configuration options.
>>>>
>>>>
>>>>> I check the program compiled with clang:
>>>>>
>>>>> $ ldd a.out
>>>>> linux-vdso.so.1 (0x00007fffd858a000)
>>>>> libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007fc1659b8000)
>>>>> librt.so.1 => /usr/lib/librt.so.1 (0x00007fc1659ad000)
>>>>> libm.so.6 => /usr/lib/libm.so.6 (0x00007fc165868000)
>>>>> libdl.so.2 => /usr/lib/libdl.so.2 (0x00007fc165863000)
>>>>> libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007fc165849000)
>>>>> libc.so.6 => /usr/lib/libc.so.6 (0x00007fc165686000)
>>>>> /lib64/ld-linux-x86-64.so.2 => /lib/ld-linux-x86-64.so.2 (0x00007fc1659e0000)
>>>>>
>>>>
>>>> See https://github.com/google/sanitizers/wiki/AddressSanitizerAsDso
>>>> I guess your clang was configured as static asan library by default.
>>>> So it's linked with static library, you can't find libasan.so with ldd.
>>>>
>>>>> No asan library is required.
>>>>>
>>>>
>>>> It requires static library. By the way, for gcc you can link with static library
>>>> via gcc option -static-libasan.
>>>>
>>>>
>>>> BR,
>>>> Kewen
>>>>
>>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux