bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/22677] ld -r --gc-section does not KEEP .init_array/.fini_array


From: address@hidden
Subject: [Bug ld/22677] ld -r --gc-section does not KEEP .init_array/.fini_array
Date: Thu, 11 Jan 2018 00:24:29 +0000

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

--- Comment #3 from David Leonard <address@hidden> ---
Hi Nick,

> This appears to be an artifact of the linker that you are using.  If you
> build an x86_64 linker using the FSF sources and run "ld --verbose" you
> should see this as part of the output

You are right that KEEPs for init_array/fini_array are present when -r is not
supplied. But they are lost with -r.

> I think however that the ubuntu version of the linker that you are using may
> have its own, different built-in linker script, without the KEEP statements.
> Please could you check ?

Checked. I found the same issue with a build from clean sources:

$ wget http://mirror.aarnet.edu.au/pub/gnu/binutils/binutils-2.29.1.tar.xz
$ tar xf binutils-2.29.1.tar.xz
$ mkdir build-clean /tmp/usr
$ cd build-clean
$ ../binutils-2.29.1/configure --prefix=/tmp/usr && make && make install
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
[...]

$ /tmp/usr/bin/ld -r --verbose
GNU ld (GNU Binutils) 2.29.1
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   elf_iamcu
   i386linux
   elf_l1om
   elf_k1om
using internal linker script:
==================================================
/* Script for ld -r: link without relocation */
/* Copyright (C) 2014-2017 Free Software Foundation, Inc.
   Copying and distribution of this script, with or without modification,
   are permitted in any medium without royalty provided the copyright
   notice and this notice are preserved.  */
OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64",
              "elf64-x86-64")
OUTPUT_ARCH(i386:x86-64)
[...]

$ /tmp/usr/bin/ld -r --verbose | grep -C1 KEEP
  {
    KEEP (*(SORT_NONE(.init)))
  }
--
  {
    KEEP (*(SORT_NONE(.fini)))
  }
--
  .eh_frame_hdr : { *(.eh_frame_hdr)  }
  .eh_frame     0 : ONLY_IF_RO { KEEP (*(.eh_frame))  }
  .gcc_except_table 0 : ONLY_IF_RO { *(.gcc_except_table
--
  /* Exception handling  */
  .eh_frame     0 : ONLY_IF_RW { KEEP (*(.eh_frame))  }
  .gnu_extab    0 : ONLY_IF_RW { *(.gnu_extab) }
--
  {
    KEEP (*(.preinit_array))
  }
  .jcr          0 : { KEEP (*(.jcr)) }
  .dynamic      0 : { *(.dynamic) }
--
  .debug_addr     0 : { *(.debug_addr) }
  .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
}


Re-verified that gc closure over .init_array still fails until explicit KEEPs
added.

mklibs$ gcc -ffunction-sections -fdata-sections -c -o L.o L.c
mklibs$ /tmp/usr/bin/ld -r --gc-section L.o -u L4var -o libL.o
mklibs$ nm libL.o
0000000000000000 D L4var

mklibs$ cat fixup.ldscript 
SECTIONS {
  .init_array    : { KEEP (*(.init_array)) }
  .fini_array    : { KEEP (*(.fini_array)) }
}
mklibs$ /tmp/usr/bin/ld -r --gc-section L.o -u L4var -o libL.o fixup.ldscript
/tmp/usr/bin/ld: warning: fixup.ldscript contains output sections; did you
forget -T?
mklibs$ nm libL.o
0000000000000000 D L4var
0000000000000000 T L5init
0000000000000004 C L5var
0000000000000000 t Lconstructor

-- 
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]