Bug 21903 - --no-define-common causes internal error in elf_link_convert_common_type
Summary: --no-define-common causes internal error in elf_link_convert_common_type
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: 2.30
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-04 04:31 UTC by Matthijs van Duin
Modified: 2017-08-23 23:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2017-08-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthijs van Duin 2017-08-04 04:31:25 UTC
echo 'int foo;' | gcc -Wl,--no-define-common -shared -o foo.so -x c -

/usr/bin/ld: BFD (GNU Binutils for Debian) 2.29 internal error, aborting at ../../bfd/elflink.c:9438 in elf_link_convert_common_type
/usr/bin/ld: Please report this bug.
Comment 1 H.J. Lu 2017-08-04 11:33:57 UTC
There is no testcase for --no-define-common.  Linker manual says:

'--no-define-common'
     This option inhibits the assignment of addresses to common symbols.
     The script command 'INHIBIT_COMMON_ALLOCATION' has the same effect.
     *Note Miscellaneous Commands::.

     The '--no-define-common' option allows decoupling the decision to
     assign addresses to Common symbols from the choice of the output
     file type; otherwise a non-Relocatable output type forces assigning
     addresses to Common symbols.  Using '--no-define-common' allows
     Common symbols that are referenced from a shared library to be
     assigned addresses only in the main program.  This eliminates the
     unused duplicate space in the shared library, and also prevents any
     possible confusion over resolving to the wrong duplicate when there
     are many dynamic modules with specialized search paths for runtime
     symbol resolution.

It is unclear if common symbol should be treated as undefined in this
case.  Also is this option only allowed for building shared library?
Comment 2 Matthijs van Duin 2017-08-04 11:55:49 UTC
Well I tried the flag to see if it would convince ld to preserve STT_COMMON in executables or shared libs, as the ELF specification says it is supposed to.
Comment 3 H.J. Lu 2017-08-04 12:23:32 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2017-08/msg00047.html
Comment 4 Sourceware Commits 2017-08-06 15:38:54 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a4819f54c0006554179631189131080be859eefb

commit a4819f54c0006554179631189131080be859eefb
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun Aug 6 08:18:53 2017 -0700

    Treat common symbol as undefined for --no-define-common
    
    When --no-define-common is used to build shared library, treat common
    symbol as undefined so that common symbols that are referenced from a
    shared library to be assigned addresses only in the main program.  This
    eliminates the unused duplicate space in the shared library, and also
    prevents any possible confusion over resolving to the wrong duplicate
    when there are many dynamic modules with specialized search paths for
    runtime symbol resolution.
    
    --no-define-common is only allowed when building a shared library.
    
    bfd/
    
    	PR ld/21903:
    	* elflink.c (elf_link_add_object_symbols): Treat common symbol
    	as undefined for --no-define-common.
    
    include/
    
    	PR ld/21903:
    	* bfdlink.h (bfd_link_info): Add inhibit_common_definition.
    
    ld/
    
    	PR ld/21903:
    	* ld.h (command_line): Remove inhibit_common_definition.
    	* ldgram.y: Replace command_line.inhibit_common_definition with
    	link_info.inhibit_common_definition.
    	* ldlang.c (lang_common): Likewise.
    	* lexsup.c (parse_args): Likewise.
    	* ldmain.c (main): Only allow --no-define-common with -shared.
    	* testsuite/ld-elf/pr21903.s: New file.
    	* testsuite/ld-elf/pr21903a.d: Likewise.
    	* testsuite/ld-elf/pr21903b.d: Likewise.
    	* testsuite/ld-elf/pr21903c.d: Likewise.
    	* testsuite/ld-elf/pr21903d.d: Likewise.
    	* testsuite/ld-elf/pr21903e.d: Likewise.
Comment 5 H.J. Lu 2017-08-06 15:43:04 UTC
Fixed for 2.30.
Comment 6 Sourceware Commits 2017-08-23 23:04:53 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=49263c56bbc622d5a42cfd37b4f5fb6863cd7d24

commit 49263c56bbc622d5a42cfd37b4f5fb6863cd7d24
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Aug 23 16:01:22 2017 -0700

    Update PR ld/21903 tests for dejagnu 1.4.4
    
    Add '\' before -- to workaround dejagnu 1.4.4 which complains:
    
    ERROR: bad switch "--no-define-common may not be used without -shared":...
    
    	* testsuite/ld-elf/pr21903c.d: Add '\' before --.
    	* testsuite/ld-elf/pr21903d.d: Likewise.
    	* testsuite/ld-elf/pr21903e.d: Likewise.