[v2,0/4] Add lto and none-lto input support for ld -r

Message ID 20240905111452.2554-1-hjl.tools@gmail.com
Headers
Series Add lto and none-lto input support for ld -r |

Message

H.J. Lu Sept. 5, 2024, 11:14 a.m. UTC
  Changes in v2:

1. Allow no-leading spaces in "objdump -h" output.

---
We generate a mixed ET_REL object with ld -r from non-IR ET_REL objects
and IR ET_REL objects, which contains IR sections and a special non-IR
section.  When generating ET_EXEC or ET_DYN output, linker extracts an
non-IR ET_REL object from the special non-IR section in the mixed ET_REL
object and adds it to the list of linker inputs.

H.J. Lu (4):
  ld: Add lto and none-lto input support for ld -r
  Add test for nm on mixed LTO/non-LTO object
  Don't check the plugin target twice
  h8300: Handle .gnu_object_only section

 bfd/bfd-in2.h                     |   16 +-
 bfd/bfd.c                         |   46 +-
 bfd/elf.c                         |    1 +
 bfd/format.c                      |   39 +-
 bfd/opncls.c                      |   66 ++
 bfd/plugin.c                      |  193 +++++-
 bfd/plugin.h                      |    2 +
 bfd/section.c                     |    3 +
 binutils/objcopy.c                |   32 +-
 binutils/readelf.c                |    1 +
 gas/config/tc-h8300.c             |    6 +-
 gas/testsuite/gas/elf/section9.d  |    1 +
 gas/testsuite/gas/elf/section9.s  |    2 +
 include/elf/common.h              |    1 +
 ld/emultempl/aarch64elf.em        |    2 +-
 ld/emultempl/alphaelf.em          |    2 +-
 ld/emultempl/armelf.em            |    2 +-
 ld/emultempl/avrelf.em            |    2 +-
 ld/emultempl/elf.em               |    1 +
 ld/emultempl/ppc32elf.em          |    2 +-
 ld/emultempl/ppc64elf.em          |    2 +-
 ld/emultempl/spuelf.em            |    2 +-
 ld/ld.h                           |    6 +
 ld/ldelf.c                        |   26 +-
 ld/ldelf.h                        |    1 +
 ld/ldexp.c                        |   16 +-
 ld/ldexp.h                        |    4 +-
 ld/ldfile.c                       |    2 +
 ld/ldlang.c                       | 1027 ++++++++++++++++++++++++++++-
 ld/ldlang.h                       |   44 +-
 ld/ldmain.c                       |   80 ++-
 ld/ldmain.h                       |    2 +
 ld/plugin.c                       |    3 +
 ld/scripttempl/elf.sc             |    2 +-
 ld/scripttempl/elf64hppa.sc       |    2 +-
 ld/scripttempl/elfxtensa.sc       |    2 +-
 ld/scripttempl/mep.sc             |    2 +-
 ld/scripttempl/pe.sc              |    1 +
 ld/scripttempl/pep.sc             |    1 +
 ld/testsuite/ld-plugin/lto-10.out |    1 +
 ld/testsuite/ld-plugin/lto-10a.c  |    6 +
 ld/testsuite/ld-plugin/lto-10b.c  |    7 +
 ld/testsuite/ld-plugin/lto-10r.d  |    9 +
 ld/testsuite/ld-plugin/lto-4.out  |    2 +
 ld/testsuite/ld-plugin/lto-4a.c   |    7 +
 ld/testsuite/ld-plugin/lto-4b.c   |    9 +
 ld/testsuite/ld-plugin/lto-4c.c   |    6 +
 ld/testsuite/ld-plugin/lto-4r-a.d |    7 +
 ld/testsuite/ld-plugin/lto-4r-b.d |    7 +
 ld/testsuite/ld-plugin/lto-4r-c.d |    7 +
 ld/testsuite/ld-plugin/lto-4r-d.d |    7 +
 ld/testsuite/ld-plugin/lto.exp    |   66 ++
 52 files changed, 1658 insertions(+), 128 deletions(-)
 create mode 100644 ld/testsuite/ld-plugin/lto-10.out
 create mode 100644 ld/testsuite/ld-plugin/lto-10a.c
 create mode 100644 ld/testsuite/ld-plugin/lto-10b.c
 create mode 100644 ld/testsuite/ld-plugin/lto-10r.d
 create mode 100644 ld/testsuite/ld-plugin/lto-4.out
 create mode 100644 ld/testsuite/ld-plugin/lto-4a.c
 create mode 100644 ld/testsuite/ld-plugin/lto-4b.c
 create mode 100644 ld/testsuite/ld-plugin/lto-4c.c
 create mode 100644 ld/testsuite/ld-plugin/lto-4r-a.d
 create mode 100644 ld/testsuite/ld-plugin/lto-4r-b.d
 create mode 100644 ld/testsuite/ld-plugin/lto-4r-c.d
 create mode 100644 ld/testsuite/ld-plugin/lto-4r-d.d
  

Comments

Alan Modra Sept. 10, 2024, 12:25 a.m. UTC | #1
I haven't yet reviewed this patch and it's going to be a while before
I can, so if someone else can review that would be good.

The following tweak is needed to compile using gcc-4.9.

diff --git a/bfd/format.c b/bfd/format.c
index 949fbd72000..8655c7f639e 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -360,7 +360,7 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
     {
       asection *sec;
       enum bfd_lto_object_type type = lto_non_ir_object;
-      struct lto_section lsection = { 0 };
+      struct lto_section lsection = { 0, 0, 0, 0 };
       /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
 	 section.  */
       for (sec = abfd->sections; sec != NULL; sec = sec->next)
  
H.J. Lu Sept. 10, 2024, 2:21 a.m. UTC | #2
On Mon, Sep 9, 2024 at 5:25 PM Alan Modra <amodra@gmail.com> wrote:
>
> I haven't yet reviewed this patch and it's going to be a while before
> I can, so if someone else can review that would be good.
>
> The following tweak is needed to compile using gcc-4.9.
>
> diff --git a/bfd/format.c b/bfd/format.c
> index 949fbd72000..8655c7f639e 100644
> --- a/bfd/format.c
> +++ b/bfd/format.c
> @@ -360,7 +360,7 @@ bfd_set_lto_type (bfd *abfd ATTRIBUTE_UNUSED)
>      {
>        asection *sec;
>        enum bfd_lto_object_type type = lto_non_ir_object;
> -      struct lto_section lsection = { 0 };
> +      struct lto_section lsection = { 0, 0, 0, 0 };
>        /* GCC uses .gnu.lto_.lto.<some_hash> as a LTO bytecode information
>          section.  */
>        for (sec = abfd->sections; sec != NULL; sec = sec->next)
>
> --
> Alan Modra

I included it in my local branch.

Thanks.