bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/25020] New: Report "sh_link of section ... points to discarded s


From: i at maskray dot me
Subject: [Bug ld/25020] New: Report "sh_link of section ... points to discarded section ..." for more input sections
Date: Thu, 19 Sep 2019 13:14:10 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=25020

            Bug ID: 25020
           Summary: Report "sh_link of section ... points to discarded
                    section ..." for more input sections
           Product: binutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: i at maskray dot me
  Target Milestone: ---

bfd/elf.c
static bfd_boolean
assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
...

      /* We need to set up sh_link for SHF_LINK_ORDER.  */
      if ((d->this_hdr.sh_flags & SHF_LINK_ORDER) != 0)
        {
          s = elf_linked_to_section (sec);
          if (s)
            {
              /* elf_linked_to_section points to the input section.  */
              if (link_info != NULL)
                {
                  /* Check discarded linkonce section.  */
                  if (discarded_section (s))
                    {
                      asection *kept;
                      _bfd_error_handler
                        /* xgettext:c-format */
                        (_("%pB: sh_link of section `%pA' points to"
                           " discarded section `%pA' of `%pB'"),
                         abfd, d->this_hdr.bfd_section,
                         s, s->owner);

The error is reported if the linked-to section of the first input section is
discarded. If the linked-to section of the second, or third, ... section is
discarded, this error is not issued.




# a.s
.globl _start
_start:
  call .foo1
  call bar0
  call bar1
  call baz0
  call baz1

.section .foo0,"a"
.section .foo1,"a"

## The linked-to section of the first input section is discarded.
.section .bar,"ao",@progbits,.foo0,unique,0
bar0:
.byte 0
.section .bar,"ao",@progbits,.foo1,unique,1
bar1:
.byte 1

## Test another case: the linked-to section of the second input section is
discarded.
.section .baz,"ao",@progbits,.foo1,unique,0
baz0:
.byte 0
.section .baz,"ao",@progbits,.foo0,unique,1
baz1:
.byte 1


# I don't know whether GNU as provides a way to set sh_link + SHF_LINK_ORDER so
I use an llvm-mc extension.

% llvm-mc -filetype=obj a.s -o a.o; ld.bfd a.o -o a --gc-sections               
ld.bfd: a: sh_link of section `.bar' points to discarded section `.foo0' of
`a.o'                              
ld.bfd: final link failed: bad value

The error can be reported on .baz as well

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]