Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 556664 - dev-libs/glib-2.44.1 didn't link with LDFLAGS="-fsanitize"
Summary: dev-libs/glib-2.44.1 didn't link with LDFLAGS="-fsanitize"
Status: RESOLVED TEST-REQUEST
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: Gentoo Linux Gnome Desktop Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-04 14:49 UTC by comicfans44
Modified: 2016-03-12 05:27 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description comicfans44 2015-08-04 14:49:28 UTC
seems that LDFLAGS didn't take effect when build glib-2.44.1

I've configured 
CFLAGS="-fsanitize"
CXXFLAGS="-fsanitize"
LDFLAGS="-fsanitize"

to test memory errors, but discover libglib-2.0.so didn't built with LDFLAGS
which leads __asan_* symbol undefined.

seems that glib build script will link a test executable gtester,
but it has LDFLAGS variable so it can not detect libglib-2.0.so link error.



the link flags of glib-2.0 seems like 
x86_64-pc-linux-gnu-gcc -shared  -fPIC -DPIC  .libs/libglib_2_0_la-gallocator.o .libs/libglib_2_0_la-gcache.o .libs/libglib_2_0_la-gcompletion.o .libs/libglib_2_0_la-grel.o .libs/libglib_2_0_la-gthread-deprecated.o .libs/libglib_2_0_la-garray.o .libs/libglib_2_0_la-gasyncqueue.o .libs/libglib_2_0_la-gatomic.o .libs/libglib_2_0_la-gbacktrace.o .libs/libglib_2_0_la-gbase64.o .libs/libglib_2_0_la-gbitlock.o .libs/libglib_2_0_la-gbookmarkfile.o .libs/libglib_2_0_la-gbytes.o .libs/libglib_2_0_la-gcharset.o .libs/libglib_2_0_la-gchecksum.o .libs/libglib_2_0_la-gconvert.o .libs/libglib_2_0_la-gdataset.o .libs/libglib_2_0_la-gdate.o .libs/libglib_2_0_la-gdatetime.o .libs/libglib_2_0_la-gdir.o .libs/libglib_2_0_la-genviron.o .libs/libglib_2_0_la-gerror.o .libs/libglib_2_0_la-gfileutils.o .libs/libglib_2_0_la-ggettext.o .libs/libglib_2_0_la-ghash.o .libs/libglib_2_0_la-ghmac.o .libs/libglib_2_0_la-ghook.o .libs/libglib_2_0_la-ghostutils.o .libs/libglib_2_0_la-giochannel.o .libs/libglib_2_0_la-gkeyfile.o .libs/libglib_2_0_la-glib-init.o .libs/libglib_2_0_la-glib-private.o .libs/libglib_2_0_la-glist.o .libs/libglib_2_0_la-gmain.o .libs/libglib_2_0_la-gmappedfile.o .libs/libglib_2_0_la-gmarkup.o .libs/libglib_2_0_la-gmem.o .libs/libglib_2_0_la-gmessages.o .libs/libglib_2_0_la-gnode.o .libs/libglib_2_0_la-goption.o .libs/libglib_2_0_la-gpattern.o .libs/libglib_2_0_la-gpoll.o .libs/libglib_2_0_la-gprimes.o .libs/libglib_2_0_la-gqsort.o .libs/libglib_2_0_la-gquark.o .libs/libglib_2_0_la-gqueue.o .libs/libglib_2_0_la-grand.o .libs/libglib_2_0_la-gregex.o .libs/libglib_2_0_la-gscanner.o .libs/libglib_2_0_la-gsequence.o .libs/libglib_2_0_la-gshell.o .libs/libglib_2_0_la-gslice.o .libs/libglib_2_0_la-gslist.o .libs/libglib_2_0_la-gstdio.o .libs/libglib_2_0_la-gstrfuncs.o .libs/libglib_2_0_la-gstring.o .libs/libglib_2_0_la-gstringchunk.o .libs/libglib_2_0_la-gtestutils.o .libs/libglib_2_0_la-gthread.o .libs/libglib_2_0_la-gthreadpool.o .libs/libglib_2_0_la-gtimer.o .libs/libglib_2_0_la-gtimezone.o .libs/libglib_2_0_la-gtranslit.o .libs/libglib_2_0_la-gtrashstack.o .libs/libglib_2_0_la-gtree.o .libs/libglib_2_0_la-guniprop.o .libs/libglib_2_0_la-gutf8.o .libs/libglib_2_0_la-gunibreak.o .libs/libglib_2_0_la-gunicollate.o .libs/libglib_2_0_la-gunidecomp.o .libs/libglib_2_0_la-gurifuncs.o .libs/libglib_2_0_la-gutils.o .libs/libglib_2_0_la-gvariant.o .libs/libglib_2_0_la-gvariant-core.o .libs/libglib_2_0_la-gvariant-parser.o .libs/libglib_2_0_la-gvariant-serialiser.o .libs/libglib_2_0_la-gvarianttypeinfo.o .libs/libglib_2_0_la-gvarianttype.o .libs/libglib_2_0_la-gversion.o .libs/libglib_2_0_la-gwakeup.o .libs/libglib_2_0_la-gprintf.o .libs/libglib_2_0_la-glib-unix.o .libs/libglib_2_0_la-gthread-posix.o .libs/giounix.o .libs/gspawn.o  -Wl,--whole-archive libcharset/.libs/libcharset.a pcre/.libs/libpcre.a -Wl,--no-whole-archive  -lpthread  -O2 -g -Wl,-Bsymbolic-functions   -Wl,-soname -Wl,libglib-2.0.so.0 -o .libs/libglib-2.0.so.0.4400.1


without my LDFLAGS 

Reproducible: Always

Steps to Reproduce:
1. config /etc/portage/env/asan.conf with 
   CFLAGS="-fsanitize"
   CXXFLAGS="-fsanitize"
   LDFLAGS="-fsanitize"
2. config /etc/portage/package.env with 
   dev-libs/glib asan.conf
3. emerge glib

Actual Results:  
ldd -r /usr/lib64/libglib-2.0.so
	linux-vdso.so.1 (0x00007ffd14577000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f7f2be0f000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f7f2ba77000)
	/lib64/ld-linux-x86-64.so.2 (0x0000556fbbca1000)
undefined symbol: __asan_option_detect_stack_use_after_return	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_store_n	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_load8	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_load2	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_load4	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_8	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_2	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_unregister_globals	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_4	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_free_7	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_free_5	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_register_globals	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_store16	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_store2	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_store4	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_store8	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_handle_no_return	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_load1	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_5	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_3	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_free_8	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_7	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_load_n	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_load16	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_init_v3	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_stack_malloc_1	(/usr/lib64/libglib-2.0.so)
undefined symbol: __asan_report_store1	(/usr/lib64/libglib-2.0.so)

Expected Results:  
ldd -r /usr/lib64/libglib-2.0.so
	linux-vdso.so.1 (0x00007ffd5e35f000)
	libasan.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libasan.so.1 (0x00007f6551a4c000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f6551830000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f6551498000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f6551294000)
	libstdc++.so.6 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libstdc++.so.6 (0x00007f6550f84000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f6550c83000)
	/lib64/ld-linux-x86-64.so.2 (0x00005649fdea6000)
	libgcc_s.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/libgcc_s.so.1 (0x00007f6550a6c000)


manual add -fsanitize=address flag to libglib-2.0.so link command fix it
Comment 1 Alexandre Rostovtsev (RETIRED) gentoo-dev 2015-08-04 17:07:15 UTC
First of all, "-fsanitize" is not a valid linker flag as far as I know.

See https://sourceware.org/binutils/docs-2.25/ld/Options.html#Options for the list of flags supported by the GNU linker (and remember that you will need to prefix each flag by "-Wl," when putting it in LDFLAGS - for example, LDFLAGS="-Wl,--as-needed")

As for the compiler flag, you should say what exactly you are sanitizing. Probably CFLAGS="-fsanitize=address" or CFLAGS="-fsanitize=undefined". Note that some types of sanitization are not supported in 32-bit code - so that can cause trouble if you are building a multilib glib.

See https://gcc.gnu.org/onlinedocs/gcc-5.2.0/gcc/Debugging-Options.html#Debugging-Options for the list of flags supported by gcc-5.2 (older gcc versions may not support some of these flags).


So please fix your asan.conf and see if glib builds.
Comment 2 Alexandre Rostovtsev (RETIRED) gentoo-dev 2015-08-04 17:15:09 UTC
Sorry, I think I was wrong about sanitization in LDFLAGS - a flag is probably needed there so it's passed to gcc when gcc is being used for linking. But still, you need to specify which sanitization you are using.

So please try:

CFLAGS="-fsanitize=address"
CXXFLAGS="-fsanitize=address"
LDFLAGS="-fsanitize=address"

and see if glib builds.
Comment 3 comicfans44 2015-08-04 23:45:21 UTC
(In reply to Alexandre Rostovtsev from comment #2)
> So please try:
> 
> CFLAGS="-fsanitize=address"
> CXXFLAGS="-fsanitize=address"
> LDFLAGS="-fsanitize=address"
> 
> and see if glib builds.

sorry I missed the "-fsanitize=address" in this report. I did use  
CFLAGS="-fsanitize=address"
CXXFLAGS="-fsanitize=address"
LDFLAGS="-fsanitize=address"

in my asan.conf 
and successfully build some packages (such as zsh) ,and confirm it correctly linked (ldd shows linked to libasan.so.1).


glib can build and install with these flags ,but the finally built libglib-2.0.so didn't link with libasan.so.1  (LDFLAGS didn't take effects) ,leads installed so file not work. if executable (which depends on libglib-2.0.so) or other lib (of the executable ) already links with asan ,no problem,  if not ,executable will fail due to missed symbols.  for example pkg-config (without asan) depends on glib(with asan) , can not execute.
Comment 4 Pacho Ramos gentoo-dev 2016-02-28 11:55:58 UTC
is this still an issue with glib-2.46? In that case, please report this directly to upstream as I don't think we will be able to solve it downstream -> bugzilla.gnome.org
Comment 5 comicfans44 2016-03-12 05:27:32 UTC
(In reply to Pacho Ramos from comment #4)
> is this still an issue with glib-2.46? In that case, please report this
> directly to upstream as I don't think we will be able to solve it downstream
> -> bugzilla.gnome.org

I can confirm glib-2.46.2-r2 links correctly (linked with libasan).