Bug 67834 - Local references inside comdat groups
Summary: Local references inside comdat groups
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.2.1
: P3 normal
Target Milestone: 5.5
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2015-10-03 21:39 UTC by John David Anglin
Modified: 2017-10-10 23:11 UTC (History)
4 users (show)

See Also:
Host: hppa-unknown-linux-gnu
Target: hppa-unknown-linux-gnu
Build: hppa-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:

Preprocessed source (450.11 KB, application/x-gzip)
2015-10-03 21:39 UTC, John David Anglin

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2015-10-03 21:39:39 UTC
Created attachment 36442 [details]
Preprocessed source

With the switch to gcc-5 on Debian, we are seeing a number of c++ packages
fail to build with the following error:

_ZXXX referenced in section `.data.rel.ro.local' of YYY: defined in discarded section `.text._ZXXX

Here is the assembler code for _ZN3uhd9transport3sphL19handle_overflow_nopEv:

       .section        .text._ZN3uhd9transport3sphL19handle_overflow_nopEv,"axG",@progbits,_ZN3uhd9transport3sph19recv_packet_handler6resizeEj,comdat
       .align 4        .type   _ZN3uhd9transport3sphL19handle_overflow_nopEv, @function
       .file 6 "/home/dave/debian/uhd/uhd-3.9.1/host/lib/usrp/usrp1/../../transport/super_recv_packet_handler.hpp"
       .loc 6 61 0
       bv,n %r0(%r2)
       .PROCEND        .cfi_endproc
       .size   _ZN3uhd9transport3sphL19handle_overflow_nopEv, .-_ZN3uhd9transport3sphL19handle_overflow_nopEv

Subsequently, there is a reference from a plabel in .data.rel.ro.local:

       .section        .data.rel.ro.local
       .align 4
       .word   P%_ZN3uhd9transport3sphL19handle_overflow_nopEv

COMDAT group section [   10] `.group' [_ZN3uhd9transport3sph19recv_packet_handler6resizeEj] contains 2 sections:
   [Index]    Name
   [  581]   .text._ZN3uhd9transport3sphL19handle_overflow_nopEv
   [ 1282]   .text._ZN3uhd9transport3sph19recv_packet_handler6resizeEj

It is my understanding that local references into COMDAT groups are not allowed.
HPPA is probably particularly sensitive to this because of the "P" PLABEL32

Compile command:
/usr/bin/c++   -DHAVE_CONFIG_H -DIHEX_USE_STDBOOL -DUHD_DLL_EXPORTS -DUHD_IMAGES_DIR=OFF -DUHD_VERSION=30901 -g -O2 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2  -fvisibility=hidden -fvisibility-inlines-hidden -fPIC -I/home/dave/debian/uhd/uhd-3.9.1/build/include -I/home/dave/debian/uhd/uhd-3.9.1/host/include -I/home/dave/debian/uhd/uhd-3.9.1/build/lib/ic_reg_maps -I/home/dave/debian/uhd/uhd-3.9.1/host/lib/convert -I/home/dave/debian/uhd/uhd-3.9.1/build/lib/convert -I/home/dave/debian/uhd/uhd-3.9.1/build/lib/transport/nirio/lvbitx -I/usr/include/libusb-1.0 -I/home/dave/debian/uhd/uhd-3.9.1/host/lib/usrp -I/home/dave/debian/uhd/uhd-3.9.1/host/lib/usrp/cores -I/home/dave/debian/uhd/uhd-3.9.1/host/../firmware/fx2/common -I/home/dave/debian/uhd/uhd-3.9.1/host/lib/usrp/common -I/home/dave/debian/uhd/uhd-3.9.1/host/lib/usrp/common/ad9361_driver    -Wall -Wextra -Wsign-compare -o CMakeFiles/uhd.dir/usrp/usrp1/io_impl.cpp.o -c /home/dave/debian/uhd/uhd-3.9.1/host/lib/usrp/usrp1/io_impl.cpp
Comment 1 John David Anglin 2015-10-05 22:16:22 UTC
This issue now breaks gcc build:

`.LC2' referenced in section `.gnu.linkonce.t._ZN21mem_alloc_descriptionI9mem_us
ageED1Ev' of build/hash-table.o: defined in discarded section `.gnu.linkonce.r._
I19default_hash_traitsIS2_EEE10hash_entryE11xcallocatorE6expandEv.str1.4' of bui

This is with trunk revision 228461.  Occurs in stage2.
Comment 2 John David Anglin 2015-10-05 22:29:29 UTC
Re comment #2, this is with --disable-comdat added to configure command:

../gcc/configure --with-gnu-as --with-gnu-ld --enable-shared --enable-multiarch --enable-linker-build-id --build=hppa-linux-gnu --host=hppa-linux-gnu --target=hppa-linux-gnu --prefix=/home/dave/opt/gnu/gcc/gcc-6 --with-local-prefix=/home/dave/opt/gnu --disable-comdat --enable-threads=posix --enable-__cxa_atexit --build=hppa-linux-gnu --enable-clocale=gnu --enable-java-gc=boehm --enable-languages="c,c++,objc,fortran,obj-c++,java,ada,lto"
Comment 3 John David Anglin 2015-10-11 22:08:01 UTC
The ELF specification says "To facilitate removing a group without leaving dangling references and with only minimal processing of the symbol table, the following rules are followed.

    References to the sections comprising a group from sections outside of the group must be made through symbol table entries with STB_GLOBAL or STB_WEAK binding and section index SHN_UNDEF."

The label _ZN3uhd9transport3sphL19handle_overflow_nopEv is not globalized.

Probably, TREE_PUBLIC is not being set or there needs to be an addition
check added to assemble_start_function to globalize COMDAT functions.  Jason,
could you take a look?
Comment 4 John David Anglin 2015-10-12 14:27:26 UTC
I suppose this is a package bug but it is present in a number
of packages:

static inline void handle_overflow_nop(void){}

class recv_packet_handler{
    vrt_unpacker_type _vrt_unpacker;
    size_t _header_offset_words32;
    double _tick_rate, _samp_rate;
    bool _queue_error_for_next_call;
    size_t _alignment_faulure_threshold;
    rx_metadata_t _queue_metadata;
    struct xport_chan_props_type{
        get_buff_type get_buff;
        issue_stream_cmd_type issue_stream_cmd;
        size_t packet_count;
        handle_overflow_type handle_overflow;
        handle_flowctrl_type handle_flowctrl;
        size_t fc_update_window;

Should there be a warning about a potential dangling reference?
Comment 5 Richard Biener 2015-12-04 10:43:08 UTC
GCC 5.3 is being released, adjusting target milestone.
Comment 6 Richard Biener 2016-06-03 10:03:26 UTC
GCC 5.4 is being released, adjusting target milestone.
Comment 7 Jakub Jelinek 2017-10-10 14:00:00 UTC
The 5 branch has been closed, it is unclear what the state of this PR is on supported branches.
Comment 8 John David Anglin 2017-10-10 23:11:08 UTC
The test case now compiles successfully with 5.4.1 20171003 (Debian 5.4.1-14), g++-6 and g++-7.