Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 566118 - sys-devel/gcc-4.9.3 installs files that contains TEXTREL on ia64
Summary: sys-devel/gcc-4.9.3 installs files that contains TEXTREL on ia64
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: IA64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://gcc.gnu.org/PR84553
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-18 13:18 UTC by Agostino Sarubbo
Modified: 2018-05-16 22:11 UTC (History)
4 users (show)

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


Attachments
0001-scanelf.c-fix-TEXTREL-parsing-for-files-with-non-zer.patch (0001-scanelf.c-fix-TEXTREL-parsing-for-files-with-non-zer.patch,4.09 KB, patch)
2018-02-18 20:23 UTC, Sergei Trofimovich (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Agostino Sarubbo gentoo-dev 2015-11-18 13:18:38 UTC
* Messages for package sys-devel/gcc-4.9.3:

 * QA Notice: The following files contain runtime text relocations
 *  Text relocations force the dynamic linker to perform extra
 *  work at startup, waste system resources, and may pose a security
 *  risk.  On some architectures, the code may not even function
 *  properly, if at all.
 *  For more information, see http://hardened.gentoo.org/pic-fix-guide.xml
 *  Please include the following list of files in your report:
 * TEXTREL usr/libexec/gcc/ia64-unknown-linux-gnu/4.9.3/cc1plus
 * TEXTREL usr/libexec/gcc/ia64-unknown-linux-gnu/4.9.3/cc1
 * TEXTREL usr/libexec/gcc/ia64-unknown-linux-gnu/4.9.3/lto1
 * TEXTREL usr/libexec/gcc/ia64-unknown-linux-gnu/4.9.3/f951
Comment 1 Agostino Sarubbo gentoo-dev 2015-11-18 13:43:25 UTC
Portage 2.2.14 (python 2.7.9-final-0, default/linux/ia64/13.0, gcc-4.9.3, glibc-2.19-r1, 3.14.14-gentoo ia64)
=================================================================
System uname: Linux-3.14.14-gentoo-ia64-Dual-Core_Intel-R-_Itanium-R-_Processor_9040-with-gentoo-2.2
KiB Mem:    16660784 total,   5077712 free
KiB Swap:    1999184 total,   1991824 free
Timestamp of tree: Wed, 18 Nov 2015 03:00:01 +0000
ld ld di GNU (Gentoo 2.24 p1.4) 2.24
app-shells/bash:          4.2_p53
dev-java/java-config:     2.2.0
dev-lang/perl:            5.20.1-r4
dev-lang/python:          2.7.9-r1, 3.3.5-r1
sys-apps/baselayout:      2.2
sys-apps/openrc:          0.12.4
sys-apps/sandbox:         2.6-r1
sys-devel/autoconf:       2.69
sys-devel/automake:       1.13.4, 1.14.1, 1.15
sys-devel/binutils:       2.24-r3
sys-devel/gcc:            4.7.4, 4.9.3
sys-devel/gcc-config:     1.7.3
sys-devel/libtool:        2.4.6
sys-devel/make:           4.0-r1
sys-kernel/linux-headers: 3.18 (virtual/os-headers)
sys-libs/glibc:           2.19-r1
Repositories: gentoo
ACCEPT_KEYWORDS="ia64"
ACCEPT_LICENSE="*"
CBUILD="ia64-unknown-linux-gnu"
CFLAGS="-O2 -pipe -mtune=itanium2"
CHOST="ia64-unknown-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5.3/ext-active/ /etc/php/apache2-php5.4/ext-active/ /etc/php/apache2-php5.5/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/cgi-php5.4/ext-active/ /etc/php/cgi-php5.5/ext-active/ /etc/php/cli-php5.3/ext-active/ /etc/php/cli-php5.4/ext-active/ /etc/php/cli-php5.5/ext-active/ /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -mtune=itanium2"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps y --keep-going y -1"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs collision-protect config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news parallel-fetch preserve-libs protect-owned sandbox sfperms split-log strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync"
FFLAGS="-O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="it_IT.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu"
MAKEOPTS="-j4"
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"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
USE="acl berkdb bzip2 cli cracklib crypt cxx dri fortran gdbm ia64 iconv ipv6 modules ncurses nls nptl openmp pam pcre readline session ssl tcpd unicode xattr zlib" ALSA_CARDS="hda-intel" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LINGUAS="am fil zh af ca cs da de el es et gl hu nb nl pl pt ro ru sk sl sv uk bg cy en eo fo ga he id ku lt lv mk ms nn sw tn zu ja zh_TW en_GB pt_BR ko zh_CN ar en_CA fi kk oc sr tr fa wa nds as be bn bn_BD bn_IN en_US es_AR es_CL es_ES es_MX eu fy fy_NL ga_IE gu gu_IN hi hi_IN is ka kn ml mr nn_NO or pa pa_IN pt_PT rm si sq sv_SE ta ta_LK te th vi ast dz km my om sh ug uz ca@valencia sr@ijekavian sr@ijekavianlatin sr@latin csb hne mai se es_LA fr_CA zh_HK br la no es_CR et_EE sr_CS bo hsb hy mn sr@Latn lb ne bs tg uz@cyrillic xh be_BY brx ca_XV dgo en_ZA gd kok ks ky lo mni nr ns pap ps rw sa_IN sat sd ss st sw_TZ ti ts ve mt ia az me tl ak hy_AM lg nso son ur_PK it fr nb nb_NO hr nan ur tk cs_CZ da_DK de_1901 de_CH en_AU lt_LT pl_PL sa sk_SK th_TH ta_IN tt sco ha mi ven ar_SY el_GR ro_RO ru_RU sl_SI uk_UA vi_VN ar_SY te_IN de_DE es_VE fa_IR fr_FR hu_HU id_ID it_IT ja_JP ka_GE nl_NL sr_BA sr_RS ca_ES fi_FI he_IL jv ru_gold yi eu_ES" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python2_7 python3_4" RUBY_TARGETS="ruby20 ruby21" USERLAND="GNU" VIDEO_CARDS="radeon"
Comment 2 Andreas K. Hüttel archtester gentoo-dev 2017-08-28 22:14:17 UTC
You should probably file an upstream bug for this.
Comment 3 Sergei Trofimovich (RETIRED) gentoo-dev 2017-12-09 19:08:39 UTC
It could as well be a scanelf bug.
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-18 11:58:16 UTC
The report is still there. New pax-utils version reports the error in a better way:

guppy ~ # scanelf -qTR /usr
scanelf: /usr/libexec/gcc/ia64-unknown-linux-gnu/7.3.0/cc1plus: DT_RELA is out of file range
scanelf: scanelf_file_textrels(): ELF /usr/libexec/gcc/ia64-unknown-linux-gnu/7.3.0/cc1plus has TEXTREL markings but doesnt appear to have any real TEXTREL's !?

scanelf does not recognize the file as valid.
Comment 5 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-18 13:11:26 UTC
It is triggered by scanelf because cc1plus has an empty TEXTREL section.
Usually ia64 files have no TEXTREL sections at all.

    $ dumpelf /usr/libexec/gcc/ia64-unknown-linux-gnu/7.3.0/cc1plus
    /* Dynamic tag #28 'DT_TEXTREL' 0x2099548 */
    {
        .d_tag     = 0x16       ,
        .d_un      = {
                .d_val = 0x0        ,
                .d_ptr = 0x0        ,
        },
    },

For some reason .sh_addr contains absolute address in every SHT_RELA section for any ELF on ia64 system. Be it gcc or anything else.

    /* Section Header #8 '.rela.dyn' 0x20AA610 */
    {
        .sh_type      = 4          , /* [SHT_RELA] */
        .sh_addr      = 0x4000000000104B08 ,
        .sh_offset    = 1067784    , /* (bytes) */
        ...
    },
    /* Section Header #9 '.rela.IA_64.pltoff' 0x20AA650 */
    {
        .sh_type      = 4          , /* [SHT_RELA] */
        .sh_addr      = 0x4000000000120ED0 ,
        .sh_offset    = 44720      , /* (bytes) */
        ...
    },

For comparison on amd64 system:

    /* Section Header #8 '.rela.dyn' 0xBDD58 */
    {
        .sh_type      = 4          , /* [SHT_RELA] */
        .sh_addr      = 0x4148     ,
        .sh_offset    = 16712      , /* (bytes) */
        ...
    },
    /* Section Header #9 '.rela.plt' 0xBDD98 */
    {
        ...
        .sh_type      = 4          , /* [SHT_RELA] */
        .sh_addr      = 0xAEB0     ,
        .sh_offset    = 44720      , /* (bytes) */
        ...
    },

Note how on amd64 address and offset are the same but on ia64 sh_addr contains absolute address.

I think we have a few bugs here:
1. scanelf uses .sh_addr instead of .sh_offset
2. binutils leaves TEXTREL sections even it those are not populated

Let's see if I can fix the first one.
Comment 6 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-18 20:23:25 UTC
Created attachment 520066 [details, diff]
0001-scanelf.c-fix-TEXTREL-parsing-for-files-with-non-zer.patch

0001-scanelf.c-fix-TEXTREL-parsing-for-files-with-non-zer.patch to fix scanelf to report correct TEXTRELs.

This enables correct reports:

$ ./scanelf -T ia64_bug_gcc/cc1plus

 TYPE   TEXTRELS FILE 
  cc1plus: _Z42gt_ggc_mx_hash_table_abstract_type_hasher_Pv [0x4000000001DC2698] in (optimized out: previous gt_ggc_r_gt_cp_typeck2_h) [0x4000000001DC2680]
  cc1plus: _Z42gt_pch_nx_hash_table_abstract_type_hasher_Pv [0x4000000001DC26A0] in (optimized out: previous gt_ggc_r_gt_cp_typeck2_h) [0x4000000001DC2680]
  cc1plus: _Z28gt_ggc_mx_vec_tinfo_s_va_gc_Pv [0x4000000001DD51F8] in (optimized out: previous gt_ggc_r_gt_cp_rtti_h) [0x4000000001DD51E0]
  cc1plus: _Z28gt_pch_nx_vec_tinfo_s_va_gc_Pv [0x4000000001DD5200] in (optimized out: previous gt_ggc_r_gt_cp_rtti_h) [0x4000000001DD51E0]
...
Comment 7 Larry the Git Cow gentoo-dev 2018-02-24 10:16:49 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=e7b8f34f4557d7071a955ccab813ec41aeeb966b

commit e7b8f34f4557d7071a955ccab813ec41aeeb966b
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-02-18 20:10:45 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-02-18 20:10:45 +0000

    scanelf.c: fix TEXTREL parsing for files with non-zero load address
    
    In bug #566118 scanelf failed to decode TEXTRELs on gcc binaries
    where program headers have absolute addresses:
    
        $ dumpelf ia64_bug_gcc/cc1plus
        /* Dynamic tag #25 'DT_RELA' 0x2099518 */
        {
            .d_tag     = 0x7        ,
            .d_un      = {
                    .d_val = 0x4000000000104B08 ,
                    .d_ptr = 0x4000000000104B08 ,
            },
        },
        /* Section Header #8 '.rela.dyn' 0x20AA610 */
        {
            .sh_type      = 4          , /* [SHT_RELA] */
            .sh_addr      = 0x4000000000104B08 ,
            .sh_offset    = 1067784    , /* (bytes) */
        },
    
    Before the change scanelf assumed DT_RELA.d_ptr is
    a relative offset. This is not true in general case
    but good-enough for DSOs as they have zero load address.
    
    This change extends the check for executables.
    To make addresses relative again we find load address
    of first byte from program header with 'p_offset'.
    
        /* Program Header #2 0xB0 */
        {
            .p_type   = 1          , /* [PT_LOAD] */
            .p_offset = 0          , /* (bytes into file) */
            .p_vaddr  = 0x4000000000000000 , /* (virtual addr at runtime) */
            .p_paddr  = 0x4000000000000000 , /* (physical addr at runtime) */
        },
    
    Bug: https://bugs.gentoo.org/566118
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 scanelf.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)}
Comment 8 Larry the Git Cow gentoo-dev 2018-02-24 10:33:42 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e68b80427bfb89876451f40d868d509d5183c327

commit e68b80427bfb89876451f40d868d509d5183c327
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-02-24 10:33:27 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-02-24 10:33:34 +0000

    app-misc/pax-utils: bump up to 1.2.3, bug #566118
    
    This release can print textrels on executable files.
    
    Bug: https://bugs.gentoo.org/566118
    Package-Manager: Portage-2.3.24, Repoman-2.3.6

 app-misc/pax-utils/Manifest               |  1 +
 app-misc/pax-utils/pax-utils-1.2.3.ebuild | 56 +++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)}
Comment 9 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-25 17:25:03 UTC
Here is the minimal reproducer (rdynamic + function pointer in .rodata):

$ cat lto-lang.cc
struct a {
  int (*b)(void);
  int c;
};
int d(void) {}
const a e{d};

int main(){}

$ ia64-unknown-linux-gnu-g++ -O0 -no-pie -fno-PIE lto-lang.cc -o lto-lang -rdynamic && scanelf -qtR lto-lang
TEXTREL  lto-lang
Comment 10 Sergei Trofimovich (RETIRED) gentoo-dev 2018-02-25 20:36:47 UTC
Filed https://gcc.gnu.org/PR84553 upstream to clarify if it's a gcc bug or binutils.
Comment 11 Sergei Trofimovich (RETIRED) gentoo-dev 2018-05-07 12:50:31 UTC
Queued a fix for gcc-8.1.0 patchset 1.3:
    https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo/src/patchsets/gcc/8.1.0/gentoo/

```
date: 2018-05-07 13:47:01 +0100;  author: slyfox;  state: Exp;  lines: +2 -0;  commitid: 71e75af04ab34567;
ia64: fix textrels on -rdynamic binaries

Bug: https://gcc.gnu.org/PR84553
Bug: https://bugs.gentoo.org/566118
```
Comment 12 Larry the Git Cow gentoo-dev 2018-05-16 21:37:45 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=6f027fd9b535c53a19d442b95eea99b2a9158d08

commit 6f027fd9b535c53a19d442b95eea99b2a9158d08
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2018-05-16 21:36:24 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2018-05-16 21:37:04 +0000

    sys-devel/gcc: bump patchset up to 1.3 for gcc-8.1.0
    
    3 new patches:
    + 95_all_ia64-TEXTREL.patch : fix TEXTRELs on -rdynamic binaries
    + 96_all_lto-O2-PR85655.patch : fix gcc -flto SIGSEGV on mariadb
    + 97_all_disable-systemtap-switch.patch : add --disable-systemtap switch
    
    Bug: https://bugs.gentoo.org/566118
    Bug: https://bugs.gentoo.org/655518
    Bug: https://bugs.gentoo.org/654748
    Package-Manager: Portage-2.3.36, Repoman-2.3.9

 sys-devel/gcc/Manifest                                     | 2 +-
 sys-devel/gcc/{gcc-8.1.0-r2.ebuild => gcc-8.1.0-r3.ebuild} | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Comment 13 Sergei Trofimovich (RETIRED) gentoo-dev 2018-05-16 22:11:19 UTC
Let's target 8.1.0-r3 and newer.