Add support for generating static PIE binaries for s390x. (#2088331)

This commit is contained in:
Nick Clifton 2022-05-19 13:29:18 +01:00
parent 10477980ae
commit 6f4f398193
2 changed files with 169 additions and 19 deletions

View File

@ -0,0 +1,142 @@
diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.37/bfd/elf64-s390.c
--- binutils.orig/bfd/elf64-s390.c 2022-05-19 11:32:09.424050559 +0100
+++ binutils-2.37/bfd/elf64-s390.c 2022-05-19 11:32:29.169924728 +0100
@@ -774,7 +774,7 @@ elf_s390_tls_transition (struct bfd_link
int r_type,
int is_local)
{
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
return r_type;
switch (r_type)
@@ -1026,7 +1026,7 @@ elf_s390_check_relocs (bfd *abfd,
case R_390_TLS_GOTIE20:
case R_390_TLS_GOTIE64:
case R_390_TLS_IEENT:
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
info->flags |= DF_STATIC_TLS;
/* Fall through */
@@ -1107,7 +1107,7 @@ elf_s390_check_relocs (bfd *abfd,
if (r_type == R_390_TLS_LE64 && bfd_link_pie (info))
break;
- if (!bfd_link_pic (info))
+ if (!bfd_link_dll (info))
break;
info->flags |= DF_STATIC_TLS;
/* Fall through */
@@ -1571,7 +1571,7 @@ allocate_dynrelocs (struct elf_link_hash
to R_390_TLS_LE64 requiring no TLS entry. For GOTIE12 and IEENT
we can save the dynamic TLS relocation. */
if (h->got.refcount > 0
- && !bfd_link_pic (info)
+ && !bfd_link_dll (info)
&& h->dynindx == -1
&& elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE)
{
@@ -1876,7 +1876,20 @@ elf_s390_size_dynamic_sections (bfd *out
else if (startswith (bfd_section_name (s), ".rela"))
{
if (s->size != 0 && s != htab->elf.srelplt)
- relocs = true;
+ {
+ relocs = true;
+ if (s == htab->elf.irelplt)
+ {
+ /* In static-pie case, there are IRELATIVE-relocs in
+ .rela.iplt (htab->irelplt), which will later be grouped
+ to .rela.plt. On s390, the IRELATIVE relocations are
+ always located in .rela.iplt - even for non-static case.
+ Ensure that DT_JMPREL, DT_PLTRELA, DT_PLTRELASZ is added
+ to the dynamic section even if htab->srelplt->size == 0.
+ See _bfd_elf_add_dynamic_tags in bfd/elflink.c. */
+ htab->elf.dt_jmprel_required = true;
+ }
+ }
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
@@ -2662,7 +2675,7 @@ elf_s390_relocate_section (bfd *output_b
/* Relocations for tls literal pool entries. */
case R_390_TLS_IE64:
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
{
Elf_Internal_Rela outrel;
asection *sreloc;
@@ -2690,7 +2703,7 @@ elf_s390_relocate_section (bfd *output_b
else if (h != NULL)
{
tls_type = elf_s390_hash_entry(h)->tls_type;
- if (!bfd_link_pic (info) && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
+ if (!bfd_link_dll (info) && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
r_type = R_390_TLS_LE64;
}
if (r_type == R_390_TLS_GD64 && tls_type >= GOT_TLS_IE)
@@ -2801,14 +2814,14 @@ elf_s390_relocate_section (bfd *output_b
if (local_got_offsets == NULL)
abort();
off = local_got_offsets[r_symndx];
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
goto emit_tls_relocs;
}
else
{
off = h->got.offset;
tls_type = elf_s390_hash_entry(h)->tls_type;
- if (bfd_link_pic (info) || h->dynindx != -1 || tls_type < GOT_TLS_IE)
+ if (bfd_link_dll (info) || h->dynindx != -1 || tls_type < GOT_TLS_IE)
goto emit_tls_relocs;
}
@@ -2825,7 +2838,7 @@ elf_s390_relocate_section (bfd *output_b
break;
case R_390_TLS_LDM64:
- if (! bfd_link_pic (info))
+ if (! bfd_link_dll (info))
/* The literal pool entry this relocation refers to gets ignored
by the optimized code of the local exec model. Do nothing
and the value will turn out zero. */
@@ -2900,7 +2913,7 @@ elf_s390_relocate_section (bfd *output_b
continue;
case R_390_TLS_LDO64:
- if (bfd_link_pic (info) || (input_section->flags & SEC_DEBUGGING))
+ if (bfd_link_dll (info) || (input_section->flags & SEC_DEBUGGING))
relocation -= dtpoff_base (info);
else
/* When converting LDO to LE, we must negate. */
@@ -2922,7 +2935,7 @@ elf_s390_relocate_section (bfd *output_b
if (r_type == R_390_TLS_LOAD)
{
- if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
+ if (!bfd_link_dll (info) && (h == NULL || h->dynindx == -1))
{
/* IE->LE transition. Four valid cases:
lg %rx,(0,%ry) -> sllg %rx,%ry,0
@@ -2972,7 +2985,7 @@ elf_s390_relocate_section (bfd *output_b
invalid_tls_insn (input_bfd, input_section, rel);
return false;
}
- if (!bfd_link_pic (info) && (h == NULL || h->dynindx == -1))
+ if (!bfd_link_dll (info) && (h == NULL || h->dynindx == -1))
{
/* GD->LE transition.
brasl %r14,__tls_get_addr@plt -> brcl 0,. */
@@ -2991,7 +3004,7 @@ elf_s390_relocate_section (bfd *output_b
}
else if (r_type == R_390_TLS_LDCALL)
{
- if (!bfd_link_pic (info))
+ if (!bfd_link_dll (info))
{
unsigned int insn0, insn1;
Only in binutils-2.37/bfd: elf64-s390.c.orig

View File

@ -39,7 +39,7 @@
Summary: A GNU collection of binary utilities
Name: binutils%{?name_cross}%{?_with_debug:-debug}
Version: 2.37
Release: 17%{?dist}
Release: 18%{?dist}
License: GPLv3+
URL: https://sourceware.org/binutils
@ -315,6 +315,10 @@ Patch26: binutils-readelf-corrupt-program-headers.patch
# Lifetime: Fixed in 2.39
Patch27: binutils-do-not-use-debuginfod.patch
# Purpose: Support generating static PIE binaries for the s390x.
# Lifetime: Fixed in 2.39
Patch28: binutils-s390x-static-PIE.patch
#----------------------------------------------------------------------------
Provides: bundled(libiberty)
@ -381,6 +385,9 @@ Requires(post): coreutils
BuildRequires: elfutils-debuginfod-client-devel
%endif
# The priority of the linker. Important oif the gold linker is also being built.
%{!?ld_bfd_priority: %global ld_bfd_priority 50}
#----------------------------------------------------------------------------
%description
@ -406,6 +413,14 @@ Requires: binutils = %{version}-%{release}
# BZ 1215242: We need touch...
Requires: coreutils
# BZ 1924068. Since applications that use the BFD library are
# required to link against the static version, ensure that it retains
# its debug informnation.
# FIXME: Yes - this is being done twice. I have no idea why this
# second invocation is necessary but if both are not present the
# static archives will be stripped.
%undefine __brp_strip_static_archive
%description devel
This package contains BFD and opcodes static and dynamic libraries.
@ -420,14 +435,6 @@ dynamic libraries.
Developers starting new projects are strongly encouraged to consider
using libelf instead of BFD.
# BZ 1924068. Since applications that use the BFD library are
# required to link against the static version, ensure that it retains
# its debug informnation.
# FIXME: Yes - this is being done twice. I have no idea why this
# second invocation is necessary but if both are not present the
# static archives will be stripped.
%undefine __brp_strip_static_archive
#----------------------------------------------------------------------------
%if %{with gold}
@ -437,13 +444,6 @@ Summary: The GOLD linker, a faster alternative to the BFD linker
Provides: gold = %{version}-%{release}
Requires: binutils >= %{version}
%description gold
This package provides the GOLD linker, which can be used as an alternative to
the default binutils linker (ld.bfd). The GOLD is generally faster than the
BFD linker, and it supports features such as Identical Code Folding and
Incremental linking. Unfortunately it is not as well maintained as the BFD
linker, and it may become deprecated in the future.
# Gold needs bison in order to build gold/yyscript.c.
BuildRequires: bison, m4, gcc-c++
# The GOLD testsuite needs a static libc++
@ -454,12 +454,17 @@ BuildRequires: gcc-c++
Conflicts: gcc-c++ < 4.0.0
%endif
# The higher of these two numbers determines the default ld.
# If ld_gold_priority is higher than ld_bfd_priority then it will be the default linker.
%{!?ld_gold_priority:%global ld_gold_priority 30}
%endif
%description gold
This package provides the GOLD linker, which can be used as an alternative to
the default binutils linker (ld.bfd). The GOLD is generally faster than the
BFD linker, and it supports features such as Identical Code Folding and
Incremental linking. Unfortunately it is not as well maintained as the BFD
linker, and it may become deprecated in the future.
%{!?ld_bfd_priority: %global ld_bfd_priority 50}
%endif
#----------------------------------------------------------------------------
@ -932,6 +937,9 @@ exit 0
#----------------------------------------------------------------------------
%changelog
* Thu May 19 2022 Nick Clifton <nickc@redhat.comn> - 2.37-18
- Add support for generating static PIE binaries for s390x. (#2088331)
* Thu Mar 10 2022 Nick Clifton <nickc@redhat.comn> - 2.37-17
- Add an option to objdump/readelf to disable accessing debuginfod servers. (#2051741)