Bug 26265 - Spurious 'gc-sections requires either an entry or an undefined symbol' when --init or --fini is specified
Summary: Spurious 'gc-sections requires either an entry or an undefined symbol' when -...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: 2.36
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-19 22:09 UTC by Fangrui Song
Modified: 2020-07-20 12:59 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-07-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-07-19 22:09:44 UTC
link_info.init_function & link_info.fini_function are GC roots. When they are explicitly specified, there is no need for the error:

% ld.bfd -r --gc-sections -init _init a.o
ld.bfd: gc-sections requires either an entry or an undefined symbol
Comment 1 Sourceware Commits 2020-07-20 12:54:43 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 2f5541f384babda4aef3d6c8011a6d15af78e0a3
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jul 20 13:32:34 2020 +0930

    PR26265, Spurious 'gc-sections requires ... when --init or --fini
    
    bfd/
            * elflink.c (_bfd_elf_gc_keep): Use bfd_is_const_section.
    ld/
            PR 26265
            * ldlang.c (undef_from_cmdline): Delete.
            (ldlang_add_undef): Mark "cmdline" param unused.
            (lang_end): Traverse gc_sym_list to determine whether a symbol root
            has been specified.  Update error message.
            * testsuite/ld-gc/noent.d: Adjust for changed error message.
Comment 2 Alan Modra 2020-07-20 12:59:12 UTC
Fixed.