Bug 87892 - [9 Regression]: libsanitizer fails to build on CentOS 5.11 (glibc 2.5)
Summary: [9 Regression]: libsanitizer fails to build on CentOS 5.11 (glibc 2.5)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 9.0
Assignee: Martin Liška
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2018-11-06 07:19 UTC by Uroš Bizjak
Modified: 2018-11-09 14:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-11-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uroš Bizjak 2018-11-06 07:19:16 UTC
Building libsanitizer with old glibc (2.5) fails with:

libtool: compile:  /home/uros/gcc-build/./gcc/xgcc -shared-libgcc -B/home/uros/gcc-build/./gcc -nostdinc++ -L/home/uros/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/src -L/home/uros/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/home/uros/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -B/home/uros/local/x86_64-pc-linux-gnu/bin/ -B/home/uros/local/x86_64-pc-linux-gnu/lib/ -isystem /home/uros/local/x86_64-pc-linux-gnu/include -isystem /home/uros/local/x86_64-pc-linux-gnu/sys-include -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DHAVE_RPC_XDR_H=1 -DHAVE_TIRPC_RPC_XDR_H=0 -I. -I../../../../git/gcc/libsanitizer/sanitizer_common -I.. -I ../../../../git/gcc/libsanitizer/include -isystem ../../../../git/gcc/libsanitizer/include/system -Wall -W -Wno-unused-parameter -Wwrite-strings -pedantic -Wno-long-long -fPIC -fno-builtin -fno-exceptions -fno-rtti -fomit-frame-pointer -funwind-tables -fvisibility=hidden -Wno-variadic-macros -I../../libstdc++-v3/include -I../../libstdc++-v3/include/x86_64-pc-linux-gnu -I../../../../git/gcc/libsanitizer/../libstdc++-v3/libsupc++ -std=gnu++11 -DSANITIZER_LIBBACKTRACE -DSANITIZER_CP_DEMANGLE -I ../../../../git/gcc/libsanitizer/../libbacktrace -I ../libbacktrace -I ../../../../git/gcc/libsanitizer/../include -include ../../../../git/gcc/libsanitizer/libbacktrace/backtrace-rename.h -g -O2 -D_GNU_SOURCE -MT sanitizer_linux_libcdep.lo -MD -MP -MF .deps/sanitizer_linux_libcdep.Tpo -c ../../../../git/gcc/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc  -fPIC -DPIC -o .libs/sanitizer_linux_libcdep.o
../../../../git/gcc/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc: In function ‘__sanitizer::u32 __sanitizer::GetNumberOfCPUs()’:
../../../../git/gcc/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc:699:10: error: ‘CPU_COUNT’ was not declared in this scope
  699 |   return CPU_COUNT(&CPUs);
      |          ^~~~~~~~~
gmake[2]: *** [sanitizer_linux_libcdep.lo] Error 1
gmake[2]: Leaving directory `/home/uros/gcc-build/x86_64-pc-linux-gnu/libsanitizer/sanitizer_common'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/home/uros/gcc-build/x86_64-pc-linux-gnu/libsanitizer'
gmake: *** [all] Error 2
Comment 1 Martin Liška 2018-11-06 12:35:31 UTC
Confirmed, it's mainline bug, I'll report that.
Comment 2 Martin Liška 2018-11-06 12:41:16 UTC
Reported upstream.
Comment 3 Martin Liška 2018-11-06 13:58:15 UTC
So it looks mainline is not interested in fixing support for 10 years old glibc. I'm also not planning to fix that.
Comment 4 Jakub Jelinek 2018-11-06 14:10:57 UTC
While upstream is careless, we shouldn't be.
You can look e.g. at libgomp/config/linux/affinity.c for how to handle older glibcs that don't define CPU_COUNT, or CPU_*_S, etc.
Comment 5 Martin Liška 2018-11-06 14:20:39 UTC
Ok, sorry for bailing that too early..
Comment 6 Martin Liška 2018-11-06 14:32:42 UTC
Hints from Jakub:

<jakub> marxin: just look at libgomp sources, I have all kinds of stuff there
<marxin> jakub: ok, then let me fix that 
<jakub> marxin: sysconf(_SC_NPROCESSORS_ONLN) is a good fallback if the affinity doesn't work
<jakub> note even the version they wrote is of course incorrect
<jakub> it will not work on machines where the cpuset is very large
<marxin> jakub: due to buffer(4096); ?
<jakub> marxin: cpu_set_t is fixed size
<jakub> marxin: newer glibcs provide APIs where one specifies the size
<marxin> jakub: ok
<jakub> marxin: if they don't want to use sysconf because it allocates memory, then can read /proc/cpuinfo themselves
<marxin> jakub: they read /sys/devices/system/cpu instead
<jakub> marxin: they do that on android only; /sys is newer than /proc though
<jakub> marxin: in any case, CPU_COUNT, if missing, can be easily written using __builtin_popcountl in a loop, see libgomp/config/linux/proc.c (gomp_cpuset_popcount)
<jakub> but that assumption that sched_getaffinity will succeed is bogus, it might fail because it isn't implemented, or may fail because the cpu_set_t is too small
<jakub> marxin: then you can of course allocate using their allocators something bigger and retry
<jakub> marxin: see also gomp_init_num_threads in the same file; while you might avoid the sysconf if they don't want to call it at start, start with cpu_set_t size
<marxin> thanks for hints
<jakub> just note that libgomp is GPL and libsanitizer is not, so copy'n'paste is not allowed
Comment 7 Martin Liška 2018-11-09 09:15:08 UTC
Author: marxin
Date: Fri Nov  9 09:14:36 2018
New Revision: 265950

URL: https://gcc.gnu.org/viewcvs?rev=265950&root=gcc&view=rev
Log:
Fallback in libsanitizer for scudo sanitizer (PR sanitizer/87892).

2018-11-09  Martin Liska  <mliska@suse.cz>

	PR sanitizer/87892
	* sanitizer_common/sanitizer_linux_libcdep.cc (defined): Return
	1 when CPU_COUNT macro is not defined.

Modified:
    trunk/libsanitizer/ChangeLog
    trunk/libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc
Comment 8 Martin Liška 2018-11-09 14:41:37 UTC
Fixed.