Bug 75315

Summary: libglapi build failure with gcc -fsanitize=address
Product: Mesa Reporter: Fabio Pedretti <pedretti.fabio>
Component: OtherAssignee: mesa-dev
Status: RESOLVED NOTOURBUG QA Contact:
Severity: enhancement    
Priority: lowest    
Version: git   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description Fabio Pedretti 2014-02-21 11:12:44 UTC
When trying to build mesa with gcc -fsanitize=address it fails with a lot of errors like:

/build/buildd/mesa-10.2~git1402181516.20d14e~gd~t/build/dri/src/gallium/auxiliary/../../../../../src/gallium/auxiliary/pipebuffer/pb_buffer_fenced.c:501: undefined reference to `__asan_report_load4'

Full build log (huge, I suggest to download it with wget) is here:
https://launchpadlibrarian.net/166644905/buildlog_ubuntu-trusty-i386.mesa_10.2~git1402181516.20d14e~gd~t_FAILEDTOBUILD.txt.gz

Possibly something in mesa build system prevents the proper build.
Comment 2 Fabio Pedretti 2014-08-23 18:33:35 UTC
Same problem now with gcc 4.9.1:
https://launchpadlibrarian.net/183028664/buildlog_ubuntu-utopic-i386.mesa_10.4~git1408232026.c2867f%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz

It's probably an issue for libglapi only, since, for example, libmesautil links properly.
Comment 3 Emil Velikov 2014-08-23 22:30:45 UTC
I'm willing to blame the compiler for that one, but just in case can you
run a verbose build in one of the failing directories - cd .... ; make V=1
Comment 4 Fabio Pedretti 2014-08-24 06:22:51 UTC
Here is a log with a verbose build:
https://launchpadlibrarian.net/183055341/buildlog_ubuntu-utopic-i386.mesa_10.4~git1408240813.8d8a5e%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz

Note I get the same error with both i386 and amd64 builds.
Comment 5 nobled 2014-08-24 06:51:31 UTC
http://clang.llvm.org/docs/AddressSanitizer.html#usage
> -Wl,-z,defs may cause link errors (don’t use it with AddressSanitizer). 

mesa links libglapi with -Wl,--no-undefined, which is the same thing as -Wl,-z,defs, and thus incompatible with asan, apparently?
Comment 6 Fabio Pedretti 2014-08-24 07:04:53 UTC
Probably, however according to this:
http://llvm.org/bugs/show_bug.cgi?id=19162
it's an issue for clang only, while I a building with gcc.
Comment 7 Emil Velikov 2014-08-24 09:08:59 UTC
(In reply to comment #6)
> Probably, however according to this:
> http://llvm.org/bugs/show_bug.cgi?id=19162
> it's an issue for clang only, while I a building with gcc.

Have you tried adding "-fsanitize=address" to the linker flags as mentioned here [1] ?

[1] http://blog.qt.digia.com/blog/2013/04/17/using-gccs-4-8-0-address-sanitizer-with-qt/
Comment 8 Fabio Pedretti 2014-08-24 10:21:07 UTC
I added it to LDFLAGS (see the LDFLAGS while calling configure), but libglapi still links without it:
https://launchpadlibrarian.net/183064138/buildlog_ubuntu-utopic-i386.mesa_10.4~git1408241158.8d8a5e%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz
Comment 9 Emil Velikov 2014-08-24 10:34:13 UTC
(In reply to comment #8)
> I added it to LDFLAGS (see the LDFLAGS while calling configure), but
> libglapi still links without it:
> https://launchpadlibrarian.net/183064138/buildlog_ubuntu-utopic-i386.mesa_10.
> 4~git1408241158.8d8a5e%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz

It should to be prefixed by "-Wl," otherwise libtool strips it out.
LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-fsanitize=address"
Comment 10 Fabio Pedretti 2014-08-24 11:01:38 UTC
It is LDFLAGS="-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-fsanitize=address"

But it doesn't work:
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/build/buildd/mesa-10.4~git1408241235.8d8a5e+gallium/build/dri':
configure: error: C compiler cannot create executables

https://launchpadlibrarian.net/183065372/buildlog_ubuntu-utopic-amd64.mesa_10.4~git1408241235.8d8a5e%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz
Comment 11 Emil Velikov 2014-08-24 14:04:28 UTC
Indeed it does - it seems that it should be fed to gcc in link mode rather than the actual linker :\

I see a few of routes
 1. append " -fsanitize=address" to your CC/CXX variable prior to executing configure, or
 2. add a configure option and handle this internally in mesa (oh god not another configure switch) by adding "-Wc,-fsanitize=address" in all Makefiles, or
 3. raise a bug with the libtool people so that they do not strip the it - i.e. extend the following switch statement. 

-64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \
-t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \
-O*|-flto*|-fwhopr*|-fuse-linker-plugin

I would recommend #3, and use #1 as a workaround until it's resolved :)
Marking this as NOTOURBUG for now as it seems to be a libtool issue.

[1] http://www.gnu.org/software/libtool/manual/libtool.html#Stripped-link-flags
Comment 12 Fabio Pedretti 2014-08-26 13:29:18 UTC
I tried the workaround in 1., adding " -fsanitize=address" to CC and CXX, now it links with it, however for some reason it still fails with the same error:
https://launchpadlibrarian.net/183204096/buildlog_ubuntu-utopic-i386.mesa_10.4~git1408261422.018875%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz
Comment 13 Emil Velikov 2014-08-26 15:44:23 UTC
(In reply to comment #12)
> I tried the workaround in 1., adding " -fsanitize=address" to CC and CXX,
> now it links with it, however for some reason it still fails with the same
> error:
> https://launchpadlibrarian.net/183204096/buildlog_ubuntu-utopic-i386.mesa_10.
> 4~git1408261422.018875%2Bgallium-nine~gd~u_FAILEDTOBUILD.txt.gz

Strange... from the above three suggestions 1 and 2 work like a charm on my Archlinux. If I have to speculate I would call it a gcc bug, yet it seem that we both have the same version - 4.9.1.

Can you track it down if it's not a gcc/distro specific ?

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.