Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 640966 - <sys-libs/glibc-2.27 : build error with profile 17.0 on sparc (sln segfaults)
Summary: <sys-libs/glibc-2.27 : build error with profile 17.0 on sparc (sln segfaults)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://sourceware.org/PR22638
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: default-pie
  Show dependency tree
 
Reported: 2017-12-13 22:20 UTC by Rolf Eike Beer
Modified: 2018-12-12 00:29 UTC (History)
5 users (show)

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


Attachments
build.log (build.log.xz,220.02 KB, application/x-xz)
2017-12-13 22:20 UTC, Rolf Eike Beer
Details
emerge info for a T5140 (emerge.info,15.01 KB, application/x-info)
2017-12-15 20:42 UTC, James McMechan
Details
glibc-2.26-no-memcpy-ifunc.patch (glibc-2.26-no-memcpy-ifunc.patch,854 bytes, patch)
2017-12-20 16:16 UTC, Sergei Trofimovich (RETIRED)
Details | Diff
Patch for seraph@xs4all.nl sed changes (test1.patch,15.21 KB, patch)
2018-02-04 23:06 UTC, James McMechan
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rolf Eike Beer archtester 2017-12-13 22:20:02 UTC
make[1]: *** [Makefile:106: install-symbolic-link] Segmentation fault

It's sln that fails:

#0  0x00000344 in ?? ()
#1  0x00011740 in __libc_setup_tls () at libc-tls.c:180
#2  0x00011174 in __libc_start_main (main=0x230, argc=1, argv=0xffffcdb4, init=0x218, fini=0xf8, rtld_fini=0x0, stack_end=0xffffceee) at libc-start.c:189
#3  0x00010654 in _start () at ../sysdeps/sparc/sparc32/start.S:87

180       memcpy (_dl_static_dtv[2].pointer.val, initimage, filesz);
(gdb) p initimage
$1 = (void *) 0xb6d08
(gdb) p filesz
$2 = 16
(gdb) p _dl_static_dtv 
$3 = 0xb9dd4 <_dl_static_dtv>
(gdb) p _dl_static_dtv[0]
$5 = {counter = 62, pointer = {val = 0x3e, to_free = 0x0}}
(gdb) p _dl_static_dtv[1]
$6 = {counter = 0, pointer = {val = 0x0, to_free = 0x0}}
(gdb) p _dl_static_dtv[2]
$7 = {counter = 772100, pointer = {val = 0xbc804, to_free = 0x0}}
(gdb) p _dl_static_dtv[3]
$8 = {counter = 0, pointer = {val = 0x0, to_free = 0x0}}
(gdb) p _dl_static_dtv[4]
$9 = {counter = 0, pointer = {val = 0x0, to_free = 0x0}}
(gdb) x/4xh 0xb6d08
0xb6d08:        0x000b  0x8414  0x000b  0x8414


Portage 2.3.8 (python 3.5.4-final-0, default/linux/sparc/17.0, gcc-6.4.0, glibc-2.25-r9, 4.14.2 sparc64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-4.14.2-sparc64-sun4v-with-gentoo-2.3
KiB Mem:    33133616 total,   8210048 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Wed, 13 Dec 2017 13:15:01 +0000
Head commit of repository gentoo: 8c957bd55d3acac6af02f13cc9b526ad6f1029b9
sh bash 4.3_p48-r1
ld GNU ld (Gentoo 2.28.1 p1.0) 2.28.1
app-shells/bash:          4.3_p48-r1::gentoo
dev-lang/perl:            5.24.3::gentoo
dev-lang/python:          2.7.14::gentoo, 3.4.5::gentoo, 3.5.4-r1::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.3::gentoo
sys-apps/openrc:          0.34.11::gentoo
sys-apps/sandbox:         2.10-r4::gentoo
sys-devel/autoconf:       2.69::gentoo
sys-devel/automake:       1.15.1-r1::gentoo
sys-devel/binutils:       2.28.1::gentoo
sys-devel/gcc:            5.4.0-r3::gentoo, 6.4.0::gentoo
sys-devel/gcc-config:     1.8-r1::gentoo
sys-devel/libtool:        2.4.6-r3::gentoo
sys-devel/make:           4.2.1::gentoo
sys-kernel/linux-headers: 4.4::gentoo (virtual/os-headers)
sys-libs/glibc:           2.25-r9::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000

ACCEPT_KEYWORDS="sparc"
ACCEPT_LICENSE="* -@EULA"
CBUILD="sparc-unknown-linux-gnu"
CFLAGS="-O2 -mcpu=niagara2 -pipe"
CHOST="sparc-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-O2 -mcpu=niagara2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS=""
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS=""
GENTOO_MIRRORS="ftp://ftp.wh2.tu-dresden.de/pub/mirrors/gentoo ftp://ftp.join.uni-muenster.de/pub/linux/distributions/gentoo"
LANG="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j20"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="acl berkdb big-endian bzip2 cli cracklib crypt cxx dri fortran gdbm iconv ipv6 modules ncurses nls nptl openmp pam pcre readline session sparc ssl tcpd unicode xattr zlib" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-6 php7-0" POSTGRES_TARGETS="postgres9_5" PYTHON_SINGLE_TARGET="python3_5" PYTHON_TARGETS="python2_7 python3_5" RUBY_TARGETS="ruby22" USERLAND="GNU" VIDEO_CARDS="fbdev glint mga r128 radeon dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS

=================================================================
                        Package Settings
=================================================================

sys-libs/glibc-2.25-r9::gentoo was built with the following:
USE="nscd rpc -audit -caps -debug -gd (-hardened) (-multilib) -profile (-selinux) -suid -systemtap (-vanilla)"
CFLAGS="-mcpu=niagara2 -pipe -fcall-used-g6 -O2 -fno-strict-aliasing"
CXXFLAGS="-mcpu=niagara2 -pipe -fcall-used-g6 -O2 -fno-strict-aliasing"


Reproducible: Always
Comment 1 Rolf Eike Beer archtester 2017-12-13 22:20:37 UTC
Created attachment 509968 [details]
build.log
Comment 2 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-14 23:39:12 UTC
The primary suspect is gcc[pie] introduced by 17.0 profile.
Comment 3 James McMechan 2017-12-15 18:09:38 UTC
I too am seeing sln segfaulting during the install phase.
I tried the usual -j1 & -sandbox since those have given me trouble in the past.
So at least another report of failure.
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-15 20:21:35 UTC
(In reply to James McMechan from comment #3)
> I too am seeing sln segfaulting during the install phase.
> I tried the usual -j1 & -sandbox since those have given me trouble in the
> past.
> So at least another report of failure.

Can you post 'emerge --info' for affected system?
Comment 5 James McMechan 2017-12-15 20:42:22 UTC
Created attachment 510224 [details]
emerge info for a T5140

attached emerge info
I have been trying various things.
-j1, -sandbox, binutils-2.29.1-r1
but even at -j64 it takes about 25min
Comment 6 Pengcheng Xu 2017-12-18 04:56:15 UTC
Same problem here, after switching to the 17.0 profile. Building with -j1 gives the same outcome. This is a T5120 box.
# emerge --info
Portage 2.3.8 (python 2.7.14-final-0, default/linux/sparc/17.0, gcc-6.4.0, glibc-2.25-r9, 4.9.49-gentoo-r1 sparc64)
=================================================================
System uname: Linux-4.9.49-gentoo-r1-sparc64-sun4v-with-gentoo-2.3
KiB Mem:     8150424 total,   4470120 free
KiB Swap:      48184 total,     48184 free
Timestamp of repository gentoo: Wed, 13 Dec 2017 05:45:01 +0000
Head commit of repository gentoo: 618a5ee9ca432020e1ce66f1724611b456029bfe
sh bash 4.3_p48-r1
ld GNU ld (Gentoo 2.28.1 p1.0) 2.28.1
app-shells/bash:          4.3_p48-r1::gentoo
dev-lang/perl:            5.24.3::gentoo
dev-lang/python:          2.7.14-r1::gentoo, 3.4.5-r1::gentoo, 3.5.4-r1::gentoo
dev-util/cmake:           3.8.2::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.3::gentoo
sys-apps/openrc:          0.34.11::gentoo
sys-apps/sandbox:         2.10-r4::gentoo
sys-devel/autoconf:       2.69::gentoo
sys-devel/automake:       1.15.1-r1::gentoo
sys-devel/binutils:       2.28.1::gentoo
sys-devel/gcc:            6.4.0::gentoo, 7.2.0::gentoo
sys-devel/gcc-config:     1.8-r1::gentoo
sys-devel/libtool:        2.4.6-r3::gentoo
sys-devel/make:           4.2.1::gentoo
sys-kernel/linux-headers: 4.4::gentoo (virtual/os-headers)
sys-libs/glibc:           2.25-r9::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://mirrors.tuna.tsinghua.edu.cn/gentoo-portage
    priority: -1000

jsteward
    location: /home/jsteward/jsteward
    masters: gentoo

gentoo-zh
    location: /var/lib/layman/gentoo-zh
    sync-type: laymansync
    sync-uri: git://github.com/microcai/gentoo-zh.git
    masters: gentoo
    priority: 50

stuff
    location: /var/lib/layman/stuff
    sync-type: laymansync
    sync-uri: https://github.com/istitov/stuff.git
    masters: gentoo
    priority: 50

ACCEPT_KEYWORDS="sparc"
ACCEPT_LICENSE="* -@EULA"
CBUILD="sparc-unknown-linux-gnu"
CFLAGS="-O2 -mcpu=niagara2 -mtune=niagara2 -pipe"
CHOST="sparc-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/gconf /etc/gentoo-release /etc/php/apache2-php7.0/ext-active/ /etc/php/apache2-php7.1/ext-active/ /etc/php/cgi-php7.0/ext-active/ /etc/php/cgi-php7.1/ext-active/ /etc/php/cli-php7.0/ext-active/ /etc/php/cli-php7.1/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -mcpu=niagara2 -mtune=niagara2 -pipe"
DISTDIR="/usr/portage/distfiles"
FCFLAGS=""
FEATURES="assume-digests binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync news parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS=""
GENTOO_MIRRORS="https://mirrors.tuna.tsinghua.edu.cn/gentoo"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j32"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="acl berkdb big-endian bzip2 cli cracklib crypt cxx dri fortran gdbm iconv ipv6 modules ncurses nls nptl openmp pam pcre php readline session sparc ssl tcpd unicode xattr zlib" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-0" POSTGRES_TARGETS="postgres9_5" PYTHON_SINGLE_TARGET="python3_5" PYTHON_TARGETS="python2_7 python3_5" RUBY_TARGETS="ruby22" USERLAND="GNU" VIDEO_CARDS="fbdev glint mga r128 radeon dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 7 Rolf Eike Beer archtester 2017-12-18 17:40:59 UTC
Can anyone give me instructions how to disable pie for that profile locally so I can test if that is the issue?
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-18 18:02:12 UTC
(In reply to Rolf Eike Beer from comment #7)
> Can anyone give me instructions how to disable pie for that profile locally
> so I can test if that is the issue?

Something like this https://bugs.gentoo.org/641216#c3 should work.

"""
For that you would need to un-force USE=pic on gcc as:

    /etc/portage/profile/package.use.force: sys-devel/gcc -pie

and then build USE=-pie gcc.
"""

Another thing to try is apply patches from https://bugs.gentoo.org/641474
which should switch to using correct startup files for static+default-pie case as it certainly affects 'sln' but I'm not sure it it's enough.
Comment 9 Rolf Eike Beer archtester 2017-12-19 18:00:35 UTC
I have picked only the second patch from bug 641474, which did not help. Also the binutils patch did not help. Building gcc with [-pie] and the same patches _did_ help.
Comment 10 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-20 14:00:02 UTC
Did not find too much but a few hints:

Reproducible in qemu-user and hangs at memcpy() call in __libc_setup_tls:
   https://sourceware.org/git/?p=glibc.git;a=blob;f=csu/libc-tls.c;h=1f8ddaf5430d5de3a59e3b9fe6505200119a80d2;hb=HEAD#l181

    $ qemu-sparc32plus -d in_asm elf/sln
    ...
    IN: __libc_setup_tls
    0x000000000001162c:  add  %l2, %i1, %g1
    0x0000000000011630:  add  %g1, -1, %g1
    0x0000000000011634:  mov  %g0, %y
    0x0000000000011638:  udiv  %g1, %i1, %l4
    0x000000000001163c:  smul  %l4, %i1, %l4
    0x0000000000011640:  sub  %i5, %l4, %o0
    0x0000000000011644:  clr  [ %i4 + 0x14 ]
    0x0000000000011648:  mov  %i3, %o2
    0x000000000001164c:  add  %i0, %o0, %o0
    0x0000000000011650:  st  %l4, [ %l3 + 0x23c ]
    0x0000000000011654:  mov  %i2, %o1
    0x0000000000011658:  st  %o0, [ %i4 + 0x10 ]
    0x000000000001165c:  add  %i0, %i5, %i5
    0x0000000000011660:  call  0xb43e4
    0x0000000000011664:  add  %i4, 8, %i4
    --------------
    IN: 
    0x00000000000b43e4:  b,a   %icc, 0x2e0

It's an early initialization call. Objdump shows exactly the same addresses (handly to debug):

$ objdump -d -S -r elf/sln

  memcpy (_dl_static_dtv[2].pointer.val, initimage, filesz);
   11660:       40 02 8b 61     call  b43e4 <_GLOBAL_OFFSET_TABLE_+0x3e4>

Call into GOT looks a bit fishy.

Same code before being linked into sln:

$ objdump -d -r -S csu/libc-tls.o

 15c:   ba 06 00 1d     add  %i0, %i5, %i5
  memcpy (_dl_static_dtv[2].pointer.val, initimage, filesz);
 160:   40 00 00 00     call  160 <__libc_setup_tls+0x160>
                        160: R_SPARC_WPLT30     memcpy
 164:   b8 07 20 08     add  %i4, 8, %i4
Comment 11 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-20 16:16:43 UTC
Created attachment 511216 [details, diff]
glibc-2.26-no-memcpy-ifunc.patch

__libc_setup_tls() is called before redirectors for IFUNC are configured.
I'm not sure how first pass initializes those:
    https://sourceware.org/git/?p=glibc.git;a=blob;f=csu/libc-start.c;h=34dd1252605519dfa034c836d5c0cb732bc39243;hb=HEAD#l197

Assuming those contain garbage.

Attachted a workaround to avoid memcpy() from IFUNC in __libc_setup_tls().
qemu still hangs early but at least it gets further through __libc_setup_tls().
Comment 12 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-20 16:27:12 UTC
One of the workarounds is to compile glibc with disabled multiarch:
    EXTRA_ECONF=--disable-multi-arch emerge -v1 glibc
Comment 13 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-20 16:41:16 UTC
(In reply to Sergei Trofimovich from comment #12)
> One of the workarounds is to compile glibc with disabled multiarch:
>     EXTRA_ECONF=--disable-multi-arch emerge -v1 glibc

Does not seem to be enough as well.
Comment 14 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-20 16:54:09 UTC
Filed https://sourceware.org/PR22638 upstream to get some guidance on safety of IFUNC usage in early startup code.
Comment 15 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-21 09:24:44 UTC
(In reply to Sergei Trofimovich from comment #14)
> Filed https://sourceware.org/PR22638 upstream to get some guidance on safety
> of IFUNC usage in early startup code.

H.J. and Anreas pointed out IFUNCs get set up before TLS setup thus are safe to use. The problem is in assembly code for sparc which assumes PIC more is used only for DSOs. And that breaks with --enable-default-pie.

Thus most of '#ifdef SHARED' should be changed to '#ifdef PIC'. The good thing is glibc-master changed IFUNC selection from assembly level to C level (and fixing PIC Once and For all there). There is a single patch needed on top of master to make sparc work: https://sourceware.org/ml/libc-alpha/2017-09/msg01140.html

For glibc-2.26 it's less easy. I see a few avenues:
1. do nothing and mask <glibc-2.27 on 17.0 sparc profiles
2. backport a huge batch of patches porting IFUNC selection from assembly to C (some of the patches remove code):
   Adhemerval Zanella (25):
      nptl: Add tests for internal pthread_mutex_t offsets
      nptl: Define __PTHREAD_MUTEX_{NUSERS_AFTER_KIND,USE_UNION}
      sparc: Implement memcpy/mempcpy ifunc selection in C
      sparc: Implement memset/bzero ifunc selection in C
      sparc: Assume VIS3 support
      sparc: refactor sparc64 signbit{f} selector to C
      sparc: refactor sparc64 isnan{f} selector to C
      sparc: refactor sparc64 isinf{f} selector to C
      sparc: refactor sparc64 finite{f} selector to C
      sparc: refactor sparc64 nearbyint{f} selector to C
      sparc: refactor sparc64 lrint{f} selector to C
      sparc: refactor sparc64 rint{f} selector to C
      sparc: refactor sparc64 __mpn_mul_1 selector to C
      sparc: refactor sparc64 __mpn_sub_n selector to C
      sparc: refactor sparc64 __mpn_addmul_1 selector to C
      sparc: refactor sparc64 __mpn_submul_1 selector to C
      sparc: refactor sparc64 __mpn_add_n selector to C
      sparc: refactor sparc32 copysign selector to C
      sparc: refactor sparc32 fabs{f} selector to C
      sparc: refactor sparc32 llrint{f} selector to C
      sparc: refactor sparc32 rint{f} selector to C
      sparc: refactor sparc32 nearbyint{f} selector to C
      sparc: refactor cpu_relax to C
      sparc: Fix sparv9 multiarch build
      sparc: Remove ununsed ifunc assembly macros
   (and likely more)
3. do a targeted "sed 's/SHARED/PIC/g'" on a bunch of "sysdeps/sparc/**.S" files.
Comment 16 Pengcheng Xu 2018-01-14 19:18:08 UTC
(In reply to Sergei Trofimovich from comment #15)
> (In reply to Sergei Trofimovich from comment #14)
> > Filed https://sourceware.org/PR22638 upstream to get some guidance on safety
> > of IFUNC usage in early startup code.
> 
> H.J. and Anreas pointed out IFUNCs get set up before TLS setup thus are safe
> to use. The problem is in assembly code for sparc which assumes PIC more is
> used only for DSOs. And that breaks with --enable-default-pie.
> 
> Thus most of '#ifdef SHARED' should be changed to '#ifdef PIC'. The good
> thing is glibc-master changed IFUNC selection from assembly level to C level
> (and fixing PIC Once and For all there). There is a single patch needed on
> top of master to make sparc work:
> https://sourceware.org/ml/libc-alpha/2017-09/msg01140.html
> 
> For glibc-2.26 it's less easy. I see a few avenues:
> 1. do nothing and mask <glibc-2.27 on 17.0 sparc profiles
> 2. backport a huge batch of patches porting IFUNC selection from assembly to
> C (some of the patches remove code):
>    Adhemerval Zanella (25):
>       nptl: Add tests for internal pthread_mutex_t offsets
>       nptl: Define __PTHREAD_MUTEX_{NUSERS_AFTER_KIND,USE_UNION}
>       sparc: Implement memcpy/mempcpy ifunc selection in C
>       sparc: Implement memset/bzero ifunc selection in C
>       sparc: Assume VIS3 support
>       sparc: refactor sparc64 signbit{f} selector to C
>       sparc: refactor sparc64 isnan{f} selector to C
>       sparc: refactor sparc64 isinf{f} selector to C
>       sparc: refactor sparc64 finite{f} selector to C
>       sparc: refactor sparc64 nearbyint{f} selector to C
>       sparc: refactor sparc64 lrint{f} selector to C
>       sparc: refactor sparc64 rint{f} selector to C
>       sparc: refactor sparc64 __mpn_mul_1 selector to C
>       sparc: refactor sparc64 __mpn_sub_n selector to C
>       sparc: refactor sparc64 __mpn_addmul_1 selector to C
>       sparc: refactor sparc64 __mpn_submul_1 selector to C
>       sparc: refactor sparc64 __mpn_add_n selector to C
>       sparc: refactor sparc32 copysign selector to C
>       sparc: refactor sparc32 fabs{f} selector to C
>       sparc: refactor sparc32 llrint{f} selector to C
>       sparc: refactor sparc32 rint{f} selector to C
>       sparc: refactor sparc32 nearbyint{f} selector to C
>       sparc: refactor cpu_relax to C
>       sparc: Fix sparv9 multiarch build
>       sparc: Remove ununsed ifunc assembly macros
>    (and likely more)
> 3. do a targeted "sed 's/SHARED/PIC/g'" on a bunch of "sysdeps/sparc/**.S"
> files.

Seems like masking <glibc-2.27 will cause problems as libnsl:0 (which is a dependency of opensp, then a dependency of openjade, then a dependency of po4a, which is required for man-db ( nls ? >=app-text/po4a-0.45 ) ) requires <glibc-2.26.
Comment 17 seraph@xs4all.nl 2018-01-29 10:31:34 UTC
> 3. do a targeted "sed 's/SHARED/PIC/g'" on a bunch of "sysdeps/sparc/**.S"
> files.

Following this, I did this as a work-around:

# ebuild /usr/portage/sys-libs/glibc/glibc-2.25-r9.ebuild fetch unpack
# find /var/tmp/portage/sys-libs/glibc-2.25-r9/work/glibc-2.25/sysdeps/sparc/ -name \*.S -exec sed -i 's/def SHARED/def PIC/' {} \; -print
# ebuild /usr/portage/sys-libs/glibc/glibc-2.25-r9.ebuild compile install
# ebuild /usr/portage/sys-libs/glibc/glibc-2.25-r9.ebuild qmerge

This gave me a succesful install and so far, nothing has broken.  Re-emerging @world now, but that will likely take a day or two on this thing.  (Netra T1 200)
Comment 18 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-03 13:35:46 UTC
Queued the fix for 2.27 as: https://github.com/gentoo/glibc/commit/fec498315526476aaf05260677d58f5ac5adaf00
Comment 19 James McMechan 2018-02-04 23:06:10 UTC
Created attachment 517822 [details, diff]
Patch for seraph@xs4all.nl sed changes

Following seraph@xs4all.nl method I have prepared a patch.
I have done full "emerge -e @world" twice successfully.

First I followed seraph's method from comment 17
then I made a patch to put in /etc/portage/patches/sys-libs/glibc-2.25-r9/
So I could do my @world rebuilds without pause.
Two full cycles using the patch so seraph's method looks good.
I am not up to tinkering with ebuild's to the extent of running find/sed between steps.

Thank you.

Enjoy,

Jim
Comment 20 Andreas K. Hüttel archtester gentoo-dev 2018-05-25 18:45:32 UTC
Fixed in sys-libs/glibc-2.27-r3

Should we maybe also backport this to our 2.26 ?!
Comment 21 Andreas K. Hüttel archtester gentoo-dev 2018-05-25 18:47:08 UTC
> 
> Should we maybe also backport this to our 2.26 ?!

Added to gentoo/2.26 branch as 
dec42d1257717054c08b8293d799e640e94df1d7
Comment 22 Sergei Trofimovich (RETIRED) gentoo-dev 2018-05-26 07:54:59 UTC
(In reply to Andreas K. Hüttel from comment #21)
> > 
> > Should we maybe also backport this to our 2.26 ?!
> 
> Added to gentoo/2.26 branch as 
> dec42d1257717054c08b8293d799e640e94df1d7

It was not chear what "this" means. Clickable link: https://github.com/gentoo/glibc/commit/dec42d1257717054c08b8293d799e640e94df1d7

At the risk od stating the obvious. 2.26 will require a lot more fixes as described in #c15 than just start.S tweak.
Comment 23 Rolf Eike Beer archtester 2018-06-24 08:03:09 UTC
This seems not to be in 2.26-r7.
Comment 24 seraph@xs4all.nl 2018-06-24 14:35:57 UTC
(In reply to Rolf Eike Beer from comment #23)
> This seems not to be in 2.26-r7.

2.26-r7 still fails in exactly the same way for me.  My earlier work-around still works on this version though.
Comment 25 Andreas K. Hüttel archtester gentoo-dev 2018-09-11 15:30:57 UTC
2.27 is now available in ~arch, and this is fixed there.
Comment 26 Sergei Trofimovich (RETIRED) gentoo-dev 2018-12-12 00:29:50 UTC
glibc-2.27 is stable on sparc and shows signs of life. Declaring victory.