I have zero experience with Ruby, but if it is any similar to Python then my recommendation is to build Ruby with AddressSanitizer. If the build breaks with an LSAN report, just disable LSAN during the build (ASAN_OPTIONS=detect_leaks=0)
--kcc On Fri, May 18, 2018 at 3:15 AM MK <[email protected]> wrote: > Hi all, > > I am trying to compile Address Sanitizer in nokogiri Ruby gem. > > Compiled libxml2 and libxslt with Address Sanitizer like this: > > ./configure CFLAGS="-fsanitize=address,undefined -Wformat > -Werror=format-security -Werror=array-bounds -g" > CXXFLAGS="-fsanitize=address,undefined -Wformat -Werror=format-security > -Werror=array-bounds -g" LDFLAGS="-fsanitize=address,undefined" CC="clang" > CXX="clang++" > > > And installed gem like this: > > sudo gem install nokogiri --version 1.8.0 -- --use-system-libraries > --with-xml2-include=/home/user/Downloads/libxml2-2.9.3/include/ > --with-xml2-lib=/usr/local/lib/ --with-cflags=\"-fsanitize=address\" > --with-ldflags=\"-fsanitize=address -lasan -lubsan\" > --with-xslt-include=/home/user/Downloads/libxslt-1.1.28/ > > > However when I run sample Ruby script using Nokogiri > > script.rb > #!/usr/bin/ruby > require 'nokogiri' > doc = File.open("sample.xml") { |f| Nokogiri::XML(f) } > > > I get this message: > > ./script.rb ==30473==ASan runtime does not come first in initial library > list; you should either link runtime to your application or manually > preload it with LD_PRELOAD. > > > When I do the preload: > > > LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.2 ./script.rb > /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in > `require': > /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri/nokogiri.so: undefined > symbol: __asan_init - > /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri/nokogiri.so (LoadError) > from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in > `require' > from /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri.rb:32:in > `rescue in <top (required)>' > from /var/lib/gems/2.3.0/gems/nokogiri-1.8.0/lib/nokogiri.rb:28:in > `<top (required)>' > from > /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `require' > from > /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in > require' > from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in > `require' > from ./script.rb:2:in `<main>' > > ================================================================= > ==30485==ERROR: LeakSanitizer: detected memory leaks > > Direct leak of 319176 byte(s) in 4259 object(s) allocated from: > #0 0x7fce9ea4579a in __interceptor_calloc > (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9879a) > #1 0x7fce9e5b4383 in ruby_xcalloc > (/usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3+0x85383) > > . > . > . > Do I have to build Ruby also with Address Sanitizer? Which unfortunately > fails ... > > cd ruby-2.3.0 > ./configure --disable-shared CFLAGS="-fsanitize=address -ggdb" > CXXFLAGS="-fsanitize=address -ggdb" > make > Breaks upon compilation, showing Memory Leak :/ > > How do I correctly enable Address Sanitizer in Ruby, on Ruby Gem? > > Thanks, > > > > -- > You received this message because you are subscribed to the Google Groups > "address-sanitizer" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "address-sanitizer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
