diff --git a/backport-x86-64-Add-R_X86_64_CODE_6_GOTTPOFF.patch b/backport-x86-64-Add-R_X86_64_CODE_6_GOTTPOFF.patch new file mode 100644 index 0000000000000000000000000000000000000000..98bef4697da9df8ba86e58f9809b5854489a8447 --- /dev/null +++ b/backport-x86-64-Add-R_X86_64_CODE_6_GOTTPOFF.patch @@ -0,0 +1,1001 @@ +From 5bc71c2a6b8efb27089baa1fecded82be4f550a7 Mon Sep 17 00:00:00 2001 +From: "H.J. Lu" +Date: Sat, 3 Feb 2024 14:32:17 -0800 +Subject: [PATCH] x86-64: Add R_X86_64_CODE_6_GOTTPOFF + +For + + add %reg1, name@gottpoff(%rip), %reg2 + +and + + add name@gottpoff(%rip), %reg1, %reg2 + +add + + #define R_X86_64_CODE_6_GOTTPOFF 50 + +if the instruction starts at 6 bytes before the relocation offset. +They are similar to R_X86_64_GOTTPOFF. Linker can covert GOTTPOFF to + + add $name@tpoff, %reg1, %reg2 + +Rewrite fx_tcbit, fx_tcbit2 and fx_tcbit3 usage to generate +R_X86_64_GOTPCRELX, R_X86_64_REX_GOTPCRELX, R_X86_64_CODE_4_GOTPCRELX, +R_X86_64_CODE_4_GOTTPOFF, R_X86_64_CODE_4_GOTPC32_TLSDESC and +R_X86_64_CODE_6_GOTTPOFF. + +NB: There is no need to check BFD_RELOC_X86_64_CODE_4_GOTTPOFF in +md_assemble since there is only BFD_RELOC_X86_64_GOTTPOFF at this +stage, which will be converted to BFD_RELOC_X86_64_CODE_4_GOTTPOFF +or BFD_RELOC_X86_64_CODE_6_GOTTPOFF in i386_validate_fix. + +5 relocations: + + #define R_X86_64_CODE_5_GOTPCRELX 46 + #define R_X86_64_CODE_5_GOTTPOFF 47 + #define R_X86_64_CODE_5_GOTPC32_TLSDESC 48 + #define R_X86_64_CODE_6_GOTPCRELX 49 + #define R_X86_64_CODE_6_GOTPC32_TLSDESC 51 + +are added for completeness and they are unused. + +bfd/ + + * elf64-x86-64.c (x86_64_elf_howto_table): Add + R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF, + R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX, + R_X86_64_CODE_6_GOTTPOFF and R_X86_64_CODE_6_GOTPC32_TLSDESC. + (R_X86_64_standard): Updated. + (x86_64_reloc_map): Add R_X86_64_CODE_5_GOTPCRELX, + R_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTPC32_TLSDESC, + R_X86_64_CODE_6_GOTPCRELX, R_X86_64_CODE_6_GOTTPOFF and + R_X86_64_CODE_6_GOTPC32_TLSDESC. + (elf_x86_64_check_tls_transition): Handle + R_X86_64_CODE_6_GOTTPOFF. + (elf_x86_64_tls_transition): Likewise. + (elf_x86_64_scan_relocs): Handle R_X86_64_CODE_6_GOTTPOFF. + Issue an error for R_X86_64_CODE_5_GOTPCRELX, + R_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTPC32_TLSDESC, + R_X86_64_CODE_6_GOTPCRELX and R_X86_64_CODE_6_GOTPC32_TLSDESC. + (elf_x86_64_relocate_section): Handle R_X86_64_CODE_6_GOTTPOFF. + * reloc.c (bfd_reloc_code_real): Add + BFD_RELOC_X86_64_CODE_5_GOTPCRELX, + BFD_RELOC_X86_64_CODE_5_GOTTPOFF, + BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC, + BFD_RELOC_X86_64_CODE_6_GOTPCRELX, + BFD_RELOC_X86_64_CODE_6_GOTTPOFF and + BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC. + * bfd-in2.h: Regenerated. + * libbfd.h: Likewise. + +elfcpp/ + + * x86_64.h (R_X86_64_CODE_5_GOTPCRELX): New. + (R_X86_64_CODE_5_GOTTPOFF): Likewise. + (R_X86_64_CODE_5_GOTPC32_TLSDESC): Likewise. + (R_X86_64_CODE_6_GOTPCRELX): Likewise. + (R_X86_64_CODE_6_GOTTPOFF): Likewise. + (R_X86_64_CODE_6_GOTPC32_TLSDESC): Likewise. + +gas/ + + * config/tc-i386.c (tc_i386_fix_adjustable): Handle + BFD_RELOC_X86_64_CODE_6_GOTTPOFF. + (md_assemble): Don't check BFD_RELOC_X86_64_CODE_4_GOTTPOFF. + Allow "add %reg1, foo@gottpoff(%rip), %reg2". + (output_disp): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF. Rewrite + setting fx_tcbitX bits for BFD_RELOC_X86_64_GOTTPOFF, + BFD_RELOC_X86_64_GOTPC32_TLSDESC and BFD_RELOC_32_PCREL. + (md_apply_fix): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF. + (i386_validate_fix): Rewrite fx_tcbitX bit checking for + BFD_RELOC_X86_64_GOTTPOFF, BFD_RELOC_X86_64_GOTPC32_TLSDESC and + BFD_RELOC_32_PCREL. + (tc_gen_reloc): Handle BFD_RELOC_X86_64_CODE_6_GOTTPOFF. + * testsuite/gas/i386/x86-64-gottpoff.d: Updated. + * testsuite/gas/i386/x86-64-gottpoff.s: Add tests for + "add %reg1, foo@gottpoff(%rip), %reg2" and + "add foo@gottpoff(%rip), %reg, %reg2". + +gold/ + + * x86_64.cc (Target_x86_64::optimize_tls_reloc): Handle + R_X86_64_CODE_6_GOTTPOFF. + (Target_x86_64::Scan::get_reference_flags): Likewise. + (Target_x86_64::Scan::local): Likewise. + (Target_x86_64::Scan::global): Likewise. + (Target_x86_64::Relocate::relocate): Likewise. + (Target_x86_64::Relocate::relocate_tls): Likewise. + (Target_x86_64::Relocate::tls_ie_to_le): Handle. + R_X86_64_CODE_6_GOTTPOFF. + * testsuite/x86_64_ie_to_le.s: Add tests for + "add %reg1, foo@gottpoff(%rip), %reg2" and + "add foo@gottpoff(%rip), %reg, %reg2". + * testsuite/x86_64_ie_to_le.sh: Updated. + +include/ + + * elf/x86-64.h (elf_x86_64_reloc_type): Add + R_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTTPOFF, + R_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPCRELX, + R_X86_64_CODE_6_GOTTPOFF and R_X86_64_CODE_6_GOTPC32_TLSDESC. + +ld/ + + * testsuite/ld-x86-64/tlsbindesc.s: Add R_X86_64_CODE_6_GOTTPOFF + tests. + * testsuite/ld-x86-64/tlsbindesc.d: Updated. + * testsuite/ld-x86-64/tlsbindesc.rd: Likewise. +--- + bfd/bfd-in2.h | 6 ++ + bfd/elf64-x86-64.c | 113 ++++++++++++++++++++++- + bfd/libbfd.h | 6 ++ + bfd/reloc.c | 12 +++ + elfcpp/x86_64.h | 24 +++++ + gas/config/tc-i386.c | 102 +++++++++++++++----- + gas/testsuite/gas/i386/x86-64-gottpoff.d | 4 + + gas/testsuite/gas/i386/x86-64-gottpoff.s | 10 ++ + gold/testsuite/x86_64_ie_to_le.s | 2 + + gold/testsuite/x86_64_ie_to_le.sh | 2 + + gold/x86_64.cc | 47 +++++++++- + include/elf/x86-64.h | 20 ++++ + ld/testsuite/ld-x86-64/tlsbindesc.dd | 24 +++++ + ld/testsuite/ld-x86-64/tlsbindesc.rd | 36 ++++---- + ld/testsuite/ld-x86-64/tlsbindesc.s | 8 ++ + 15 files changed, 371 insertions(+), 45 deletions(-) + +diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h +index 581d8fe0b3e..dbafcf8da36 100644 +--- a/bfd/bfd-in2.h ++++ b/bfd/bfd-in2.h +@@ -3894,6 +3894,12 @@ enum bfd_reloc_code_real + BFD_RELOC_X86_64_CODE_4_GOTPCRELX, + BFD_RELOC_X86_64_CODE_4_GOTTPOFF, + BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC, ++ BFD_RELOC_X86_64_CODE_5_GOTPCRELX, ++ BFD_RELOC_X86_64_CODE_5_GOTTPOFF, ++ BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC, ++ BFD_RELOC_X86_64_CODE_6_GOTPCRELX, ++ BFD_RELOC_X86_64_CODE_6_GOTTPOFF, ++ BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC, + + /* ns32k relocations. */ + BFD_RELOC_NS32K_IMM_8, +diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c +index f1253751bbd..2ed120af780 100644 +--- a/bfd/elf64-x86-64.c ++++ b/bfd/elf64-x86-64.c +@@ -179,12 +179,30 @@ static reloc_howto_type x86_64_elf_howto_table[] = + HOWTO(R_X86_64_CODE_4_GOTPC32_TLSDESC, 0, 4, 32, true, 0, + complain_overflow_bitfield, bfd_elf_generic_reloc, + "R_X86_64_CODE_4_GOTPC32_TLSDESC", false, 0, 0xffffffff, true), ++ HOWTO(R_X86_64_CODE_5_GOTPCRELX, 0, 4, 32, true, 0, ++ complain_overflow_signed, bfd_elf_generic_reloc, ++ "R_X86_64_CODE_5_GOTPCRELX", false, 0, 0xffffffff, true), ++ HOWTO(R_X86_64_CODE_5_GOTTPOFF, 0, 4, 32, true, 0, ++ complain_overflow_signed, bfd_elf_generic_reloc, ++ "R_X86_64_CODE_5_GOTTPOFF", false, 0, 0xffffffff, true), ++ HOWTO(R_X86_64_CODE_5_GOTPC32_TLSDESC, 0, 4, 32, true, 0, ++ complain_overflow_bitfield, bfd_elf_generic_reloc, ++ "R_X86_64_CODE_5_GOTPC32_TLSDESC", false, 0, 0xffffffff, true), ++ HOWTO(R_X86_64_CODE_6_GOTPCRELX, 0, 4, 32, true, 0, ++ complain_overflow_signed, bfd_elf_generic_reloc, ++ "R_X86_64_CODE_6_GOTPCRELX", false, 0, 0xffffffff, true), ++ HOWTO(R_X86_64_CODE_6_GOTTPOFF, 0, 4, 32, true, 0, ++ complain_overflow_signed, bfd_elf_generic_reloc, ++ "R_X86_64_CODE_6_GOTTPOFF", false, 0, 0xffffffff, true), ++ HOWTO(R_X86_64_CODE_6_GOTPC32_TLSDESC, 0, 4, 32, true, 0, ++ complain_overflow_bitfield, bfd_elf_generic_reloc, ++ "R_X86_64_CODE_6_GOTPC32_TLSDESC", false, 0, 0xffffffff, true), + + /* We have a gap in the reloc numbers here. + R_X86_64_standard counts the number up to this point, and + R_X86_64_vt_offset is the value to subtract from a reloc type of + R_X86_64_GNU_VT* to form an index into this table. */ +-#define R_X86_64_standard (R_X86_64_CODE_4_GOTPC32_TLSDESC + 1) ++#define R_X86_64_standard (R_X86_64_CODE_6_GOTPC32_TLSDESC + 1) + #define R_X86_64_vt_offset (R_X86_64_GNU_VTINHERIT - R_X86_64_standard) + + /* GNU extension to record C++ vtable hierarchy. */ +@@ -256,6 +274,12 @@ static const struct elf_reloc_map x86_64_reloc_map[] = + { BFD_RELOC_X86_64_CODE_4_GOTPCRELX, R_X86_64_CODE_4_GOTPCRELX, }, + { BFD_RELOC_X86_64_CODE_4_GOTTPOFF, R_X86_64_CODE_4_GOTTPOFF, }, + { BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC, R_X86_64_CODE_4_GOTPC32_TLSDESC, }, ++ { BFD_RELOC_X86_64_CODE_5_GOTPCRELX, R_X86_64_CODE_5_GOTPCRELX, }, ++ { BFD_RELOC_X86_64_CODE_5_GOTTPOFF, R_X86_64_CODE_5_GOTTPOFF, }, ++ { BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC, R_X86_64_CODE_5_GOTPC32_TLSDESC, }, ++ { BFD_RELOC_X86_64_CODE_6_GOTPCRELX, R_X86_64_CODE_6_GOTPCRELX, }, ++ { BFD_RELOC_X86_64_CODE_6_GOTTPOFF, R_X86_64_CODE_6_GOTTPOFF, }, ++ { BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC, R_X86_64_CODE_6_GOTPC32_TLSDESC, }, + { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, }, + { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, }, + }; +@@ -1283,6 +1307,23 @@ elf_x86_64_check_tls_transition (bfd *abfd, + + goto check_gottpoff; + ++ case R_X86_64_CODE_6_GOTTPOFF: ++ /* Check transition from IE access model: ++ add %reg1, foo@gottpoff(%rip), %reg2 ++ where reg1/reg2 are one of r16 to r31. */ ++ ++ if (offset < 6 ++ || (offset + 4) > sec->size ++ || contents[offset - 6] != 0x62) ++ return false; ++ ++ val = bfd_get_8 (abfd, contents + offset - 2); ++ if (val != 0x01 && val != 0x03) ++ return false; ++ ++ val = bfd_get_8 (abfd, contents + offset - 1); ++ return (val & 0xc7) == 5; ++ + case R_X86_64_GOTTPOFF: + /* Check transition from IE access model: + mov foo@gottpoff(%rip), %reg +@@ -1417,6 +1458,7 @@ elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, + case R_X86_64_TLSDESC_CALL: + case R_X86_64_GOTTPOFF: + case R_X86_64_CODE_4_GOTTPOFF: ++ case R_X86_64_CODE_6_GOTTPOFF: + if (bfd_link_executable (info)) + { + if (h == NULL) +@@ -1464,6 +1506,8 @@ elf_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd, + /* Return TRUE if there is no transition. */ + if (from_type == to_type + || (from_type == R_X86_64_CODE_4_GOTTPOFF ++ && to_type == R_X86_64_GOTTPOFF) ++ || (from_type == R_X86_64_CODE_6_GOTTPOFF + && to_type == R_X86_64_GOTTPOFF)) + return true; + +@@ -2177,6 +2221,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info, + + case R_X86_64_GOTTPOFF: + case R_X86_64_CODE_4_GOTTPOFF: ++ case R_X86_64_CODE_6_GOTTPOFF: + if (!bfd_link_executable (info)) + info->flags |= DF_STATIC_TLS; + /* Fall through */ +@@ -2214,6 +2259,7 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info, + break; + case R_X86_64_GOTTPOFF: + case R_X86_64_CODE_4_GOTTPOFF: ++ case R_X86_64_CODE_6_GOTTPOFF: + tls_type = GOT_TLS_IE; + break; + case R_X86_64_GOTPC32_TLSDESC: +@@ -2503,6 +2549,26 @@ elf_x86_64_scan_relocs (bfd *abfd, struct bfd_link_info *info, + } + break; + ++ case R_X86_64_CODE_5_GOTPCRELX: ++ case R_X86_64_CODE_5_GOTTPOFF: ++ case R_X86_64_CODE_5_GOTPC32_TLSDESC: ++ case R_X86_64_CODE_6_GOTPCRELX: ++ case R_X86_64_CODE_6_GOTPC32_TLSDESC: ++ { ++ /* These relocations are added only for completeness and ++ aren't be used. */ ++ if (h) ++ name = h->root.root.string; ++ else ++ name = bfd_elf_sym_name (abfd, symtab_hdr, isym, ++ NULL); ++ _bfd_error_handler ++ /* xgettext:c-format */ ++ (_("%pB: unsupported relocation %s against symbol `%s'"), ++ abfd, x86_64_elf_howto_table[r_type].name, name); ++ } ++ break; ++ + /* This relocation describes the C++ object vtable hierarchy. + Reconstruct it for later use during GC. */ + case R_X86_64_GNU_VTINHERIT: +@@ -3570,6 +3636,7 @@ elf_x86_64_relocate_section (bfd *output_bfd, + case R_X86_64_TLSDESC_CALL: + case R_X86_64_GOTTPOFF: + case R_X86_64_CODE_4_GOTTPOFF: ++ case R_X86_64_CODE_6_GOTTPOFF: + tls_type = GOT_UNKNOWN; + if (h == NULL && local_got_offsets) + tls_type = elf_x86_local_got_tls_type (input_bfd) [r_symndx]; +@@ -3920,6 +3987,50 @@ elf_x86_64_relocate_section (bfd *output_bfd, + contents + roff); + continue; + } ++ else if (r_type == R_X86_64_CODE_6_GOTTPOFF) ++ { ++ /* IE->LE transition: ++ Originally it is ++ add %reg1, foo@gottpoff(%rip), %reg2 ++ or ++ add foo@gottpoff(%rip), %reg1, %reg2 ++ We change it into: ++ add $foo@tpoff, %reg1, %reg2 ++ */ ++ unsigned int reg, byte1; ++ unsigned int updated_byte1; ++ ++ if (roff < 6) ++ goto corrupt_input; ++ ++ /* Move the R bits to the B bits in EVEX payload ++ byte 1. */ ++ byte1 = bfd_get_8 (input_bfd, contents + roff - 5); ++ updated_byte1 = byte1; ++ ++ /* Set the R bits since they is inverted. */ ++ updated_byte1 |= 1 << 7 | 1 << 4; ++ ++ /* Update the B bits from the R bits. */ ++ if ((byte1 & (1 << 7)) == 0) ++ updated_byte1 &= ~(1 << 5); ++ if ((byte1 & (1 << 4)) == 0) ++ updated_byte1 |= 1 << 3; ++ ++ reg = bfd_get_8 (input_bfd, contents + roff - 1); ++ reg >>= 3; ++ ++ bfd_put_8 (output_bfd, updated_byte1, ++ contents + roff - 5); ++ bfd_put_8 (output_bfd, 0x81, ++ contents + roff - 2); ++ bfd_put_8 (output_bfd, 0xc0 | reg, ++ contents + roff - 1); ++ bfd_put_32 (output_bfd, ++ elf_x86_64_tpoff (info, relocation), ++ contents + roff); ++ continue; ++ } + else + BFD_ASSERT (false); + } +diff --git a/bfd/libbfd.h b/bfd/libbfd.h +index ebd4f24149b..40bbe6a3886 100644 +--- a/bfd/libbfd.h ++++ b/bfd/libbfd.h +@@ -1463,6 +1463,12 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@", + "BFD_RELOC_X86_64_CODE_4_GOTPCRELX", + "BFD_RELOC_X86_64_CODE_4_GOTTPOFF", + "BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC", ++ "BFD_RELOC_X86_64_CODE_5_GOTPCRELX", ++ "BFD_RELOC_X86_64_CODE_5_GOTTPOFF", ++ "BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC", ++ "BFD_RELOC_X86_64_CODE_6_GOTPCRELX", ++ "BFD_RELOC_X86_64_CODE_6_GOTTPOFF", ++ "BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC", + "BFD_RELOC_NS32K_IMM_8", + "BFD_RELOC_NS32K_IMM_16", + "BFD_RELOC_NS32K_IMM_32", +diff --git a/bfd/reloc.c b/bfd/reloc.c +index e74cbd75e96..7583b7fd552 100644 +--- a/bfd/reloc.c ++++ b/bfd/reloc.c +@@ -2481,6 +2481,18 @@ ENUMX + BFD_RELOC_X86_64_CODE_4_GOTTPOFF + ENUMX + BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC ++ENUMX ++ BFD_RELOC_X86_64_CODE_5_GOTPCRELX ++ENUMX ++ BFD_RELOC_X86_64_CODE_5_GOTTPOFF ++ENUMX ++ BFD_RELOC_X86_64_CODE_5_GOTPC32_TLSDESC ++ENUMX ++ BFD_RELOC_X86_64_CODE_6_GOTPCRELX ++ENUMX ++ BFD_RELOC_X86_64_CODE_6_GOTTPOFF ++ENUMX ++ BFD_RELOC_X86_64_CODE_6_GOTPC32_TLSDESC + ENUMDOC + x86-64/elf relocations. + +diff --git a/elfcpp/x86_64.h b/elfcpp/x86_64.h +index 135f339fccf..5d254ce483b 100644 +--- a/elfcpp/x86_64.h ++++ b/elfcpp/x86_64.h +@@ -110,6 +110,30 @@ enum + // descriptor in GOT if the + // instruction starts at 4 bytes + // before the relocation offset. ++ R_X86_64_CODE_5_GOTPCRELX = 46, // 32 bit signed PC relative offset to ++ // GOT if the instruction starts at 5 ++ // bytes before the relocation offset, ++ // relaxable. ++ R_X86_64_CODE_5_GOTTPOFF = 47, // 32 bit signed PC relative offset to ++ // GOT entry for IE symbol if the ++ // instruction starts at 5 bytes before ++ // the relocation offset. ++ R_X86_64_CODE_5_GOTPC32_TLSDESC = 48, // 32-bit PC relative to TLS ++ // descriptor in GOT if the ++ // instruction starts at 5 bytes ++ // before the relocation offset. ++ R_X86_64_CODE_6_GOTPCRELX = 49, // 32 bit signed PC relative offset to ++ // GOT if the instruction starts at 6 ++ // bytes before the relocation offset, ++ // relaxable. ++ R_X86_64_CODE_6_GOTTPOFF = 50, // 32 bit signed PC relative offset to ++ // GOT entry for IE symbol if the ++ // instruction starts at 6 bytes before ++ // the relocation offset. ++ R_X86_64_CODE_6_GOTPC32_TLSDESC = 51, // 32-bit PC relative to TLS ++ // descriptor in GOT if the ++ // instruction starts at 6 bytes ++ // before the relocation offset. + // GNU vtable garbage collection extensions. + R_X86_64_GNU_VTINHERIT = 250, + R_X86_64_GNU_VTENTRY = 251 +diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c +index 50d890c4481..9e7bb1dd4d6 100644 +--- a/gas/config/tc-i386.c ++++ b/gas/config/tc-i386.c +@@ -3648,6 +3648,7 @@ tc_i386_fix_adjustable (fixS *fixP) + || fixP->fx_r_type == BFD_RELOC_X86_64_DTPOFF64 + || fixP->fx_r_type == BFD_RELOC_X86_64_GOTTPOFF + || fixP->fx_r_type == BFD_RELOC_X86_64_CODE_4_GOTTPOFF ++ || fixP->fx_r_type == BFD_RELOC_X86_64_CODE_6_GOTTPOFF + || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF32 + || fixP->fx_r_type == BFD_RELOC_X86_64_TPOFF64 + || fixP->fx_r_type == BFD_RELOC_X86_64_GOTOFF64 +@@ -6795,10 +6796,19 @@ md_assemble (char *line) + for (j = i.imm_operands; j < i.operands; ++j) + switch (i.reloc[j]) + { ++ case BFD_RELOC_X86_64_GOTTPOFF: ++ if (i.tm.mnem_off == MN_add ++ && i.tm.opcode_space == SPACE_EVEXMAP4 ++ && i.mem_operands == 1 ++ && i.base_reg ++ && i.base_reg->reg_num == RegIP ++ && i.tm.operand_types[0].bitfield.class == Reg ++ && i.tm.operand_types[2].bitfield.class == Reg) ++ /* Allow APX: add %reg1, foo@gottpoff(%rip), %reg2. */ ++ break; ++ /* Fall through. */ + case BFD_RELOC_386_TLS_GOTIE: + case BFD_RELOC_386_TLS_LE_32: +- case BFD_RELOC_X86_64_GOTTPOFF: +- case BFD_RELOC_X86_64_CODE_4_GOTTPOFF: + case BFD_RELOC_X86_64_TLSLD: + as_bad (_("TLS relocation cannot be used with `%s'"), insn_name (&i.tm)); + return; +@@ -12040,6 +12050,7 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off) + case BFD_RELOC_X86_64_TLSLD: + case BFD_RELOC_X86_64_GOTTPOFF: + case BFD_RELOC_X86_64_CODE_4_GOTTPOFF: ++ case BFD_RELOC_X86_64_CODE_6_GOTTPOFF: + case BFD_RELOC_X86_64_GOTPC32_TLSDESC: + case BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC: + case BFD_RELOC_X86_64_TLSDESC_CALL: +@@ -12056,9 +12067,30 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off) + && !i.prefix[ADDR_PREFIX]) + fixP->fx_signed = 1; + +- /* Set fx_tcbit3 for REX2 prefix. */ +- if (is_apx_rex2_encoding ()) +- fixP->fx_tcbit3 = 1; ++ if (reloc_type == BFD_RELOC_X86_64_GOTTPOFF ++ && i.tm.opcode_space == SPACE_EVEXMAP4) ++ { ++ /* Only "add %reg1, foo@gottpoff(%rip), %reg2" is ++ allowed in md_assemble. Set fx_tcbit2 for EVEX ++ prefix. */ ++ fixP->fx_tcbit2 = 1; ++ continue; ++ } ++ ++ if (i.base_reg && i.base_reg->reg_num == RegIP) ++ { ++ if (reloc_type == BFD_RELOC_X86_64_GOTPC32_TLSDESC) ++ { ++ /* Set fx_tcbit for REX2 prefix. */ ++ if (is_apx_rex2_encoding ()) ++ fixP->fx_tcbit = 1; ++ continue; ++ } ++ } ++ /* In 64-bit, i386_validate_fix updates only (%rip) ++ relocations. */ ++ else if (object_64bit) ++ continue; + + /* Check for "call/jmp *mem", "mov mem, %reg", + "test %reg, mem" and "binop mem, %reg" where binop +@@ -12083,10 +12115,22 @@ output_disp (fragS *insn_start_frag, offsetT insn_start_off) + { + if (object_64bit) + { +- fixP->fx_tcbit = i.rex != 0; +- if (i.base_reg +- && (i.base_reg->reg_num == RegIP)) +- fixP->fx_tcbit2 = 1; ++ if (reloc_type == BFD_RELOC_X86_64_GOTTPOFF) ++ { ++ /* Set fx_tcbit for REX2 prefix. */ ++ if (is_apx_rex2_encoding ()) ++ fixP->fx_tcbit = 1; ++ } ++ else ++ { ++ /* Set fx_tcbit3 for REX2 prefix. */ ++ if (is_apx_rex2_encoding ()) ++ fixP->fx_tcbit3 = 1; ++ else if (i.rex) ++ fixP->fx_tcbit2 = 1; ++ else ++ fixP->fx_tcbit = 1; ++ } + } + else + fixP->fx_tcbit2 = 1; +@@ -15563,6 +15607,7 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) + case BFD_RELOC_X86_64_TLSLD: + case BFD_RELOC_X86_64_GOTTPOFF: + case BFD_RELOC_X86_64_CODE_4_GOTTPOFF: ++ case BFD_RELOC_X86_64_CODE_6_GOTTPOFF: + case BFD_RELOC_X86_64_GOTPC32_TLSDESC: + case BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC: + value = 0; /* Fully resolved at runtime. No addend. */ +@@ -17144,13 +17189,27 @@ i386_validate_fix (fixS *fixp) + && (!S_IS_DEFINED (fixp->fx_addsy) + || S_IS_EXTERNAL (fixp->fx_addsy)); + +- if (fixp->fx_tcbit3) ++ /* BFD_RELOC_X86_64_GOTTPOFF: ++ 1. fx_tcbit -> BFD_RELOC_X86_64_CODE_4_GOTTPOFF ++ 2. fx_tcbit2 -> BFD_RELOC_X86_64_CODE_6_GOTTPOFF ++ BFD_RELOC_X86_64_GOTPC32_TLSDESC: ++ 1. fx_tcbit -> BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC ++ BFD_RELOC_32_PCREL: ++ 1. fx_tcbit -> BFD_RELOC_X86_64_GOTPCRELX ++ 2. fx_tcbit2 -> BFD_RELOC_X86_64_REX_GOTPCRELX ++ 3. fx_tcbit3 -> BFD_RELOC_X86_64_CODE_4_GOTPCRELX ++ 4. else -> BFD_RELOC_X86_64_GOTPCREL ++ */ ++ if (fixp->fx_r_type == BFD_RELOC_X86_64_GOTTPOFF) + { +- if (fixp->fx_r_type == BFD_RELOC_X86_64_GOTTPOFF) ++ if (fixp->fx_tcbit) + fixp->fx_r_type = BFD_RELOC_X86_64_CODE_4_GOTTPOFF; +- else if (fixp->fx_r_type == BFD_RELOC_X86_64_GOTPC32_TLSDESC) +- fixp->fx_r_type = BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC; ++ else if (fixp->fx_tcbit2) ++ fixp->fx_r_type = BFD_RELOC_X86_64_CODE_6_GOTTPOFF; + } ++ else if (fixp->fx_r_type == BFD_RELOC_X86_64_GOTPC32_TLSDESC ++ && fixp->fx_tcbit) ++ fixp->fx_r_type = BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC; + #endif + + if (fixp->fx_subsy) +@@ -17162,15 +17221,12 @@ i386_validate_fix (fixS *fixp) + if (!object_64bit) + abort (); + #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF) +- if (fixp->fx_tcbit2) +- { +- if (fixp->fx_tcbit3) +- fixp->fx_r_type = BFD_RELOC_X86_64_CODE_4_GOTPCRELX; +- else +- fixp->fx_r_type = (fixp->fx_tcbit +- ? BFD_RELOC_X86_64_REX_GOTPCRELX +- : BFD_RELOC_X86_64_GOTPCRELX); +- } ++ if (fixp->fx_tcbit) ++ fixp->fx_r_type = BFD_RELOC_X86_64_GOTPCRELX; ++ else if (fixp->fx_tcbit2) ++ fixp->fx_r_type = BFD_RELOC_X86_64_REX_GOTPCRELX; ++ else if (fixp->fx_tcbit3) ++ fixp->fx_r_type = BFD_RELOC_X86_64_CODE_4_GOTPCRELX; + else + #endif + fixp->fx_r_type = BFD_RELOC_X86_64_GOTPCREL; +@@ -17296,6 +17352,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) + case BFD_RELOC_X86_64_DTPOFF64: + case BFD_RELOC_X86_64_GOTTPOFF: + case BFD_RELOC_X86_64_CODE_4_GOTTPOFF: ++ case BFD_RELOC_X86_64_CODE_6_GOTTPOFF: + case BFD_RELOC_X86_64_TPOFF32: + case BFD_RELOC_X86_64_TPOFF64: + case BFD_RELOC_X86_64_GOTOFF64: +@@ -17440,6 +17497,7 @@ tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp) + case BFD_RELOC_X86_64_TLSLD: + case BFD_RELOC_X86_64_GOTTPOFF: + case BFD_RELOC_X86_64_CODE_4_GOTTPOFF: ++ case BFD_RELOC_X86_64_CODE_6_GOTTPOFF: + case BFD_RELOC_X86_64_GOTPC32_TLSDESC: + case BFD_RELOC_X86_64_CODE_4_GOTPC32_TLSDESC: + case BFD_RELOC_X86_64_TLSDESC_CALL: +diff --git a/gas/testsuite/gas/i386/x86-64-gottpoff.d b/gas/testsuite/gas/i386/x86-64-gottpoff.d +index d42abccc6d9..f2c039abe72 100644 +--- a/gas/testsuite/gas/i386/x86-64-gottpoff.d ++++ b/gas/testsuite/gas/i386/x86-64-gottpoff.d +@@ -16,4 +16,8 @@ Disassembly of section .text: + +[a-f0-9]+: 48 8b 05 00 00 00 00 mov 0x0\(%rip\),%rax # 2c <_start\+0x2c> 28: R_X86_64_GOTTPOFF foo-0x4 + +[a-f0-9]+: d5 48 03 05 00 00 00 00 add 0x0\(%rip\),%r16 # 34 <_start\+0x34> 30: R_X86_64_CODE_4_GOTTPOFF foo-0x4 + +[a-f0-9]+: d5 48 8b 25 00 00 00 00 mov 0x0\(%rip\),%r20 # 3c <_start\+0x3c> 38: R_X86_64_CODE_4_GOTTPOFF foo-0x4 ++ +[a-f0-9]+: 62 74 fc 10 01 05 00 00 00 00 add %r8,0x0\(%rip\),%r16 # 46 <_start\+0x46> 42: R_X86_64_CODE_6_GOTTPOFF foo-0x4 ++ +[a-f0-9]+: 62 f4 9c 18 03 05 00 00 00 00 add 0x0\(%rip\),%rax,%r12 # 50 <_start\+0x50> 4c: R_X86_64_CODE_6_GOTTPOFF foo-0x4 ++ +[a-f0-9]+: 62 74 fc 10 01 05 00 00 00 00 add %r8,0x0\(%rip\),%r16 # 5a <_start\+0x5a> 56: R_X86_64_CODE_6_GOTTPOFF foo-0x4 ++ +[a-f0-9]+: 62 f4 9c 18 03 05 00 00 00 00 add 0x0\(%rip\),%rax,%r12 # 64 <_start\+0x64> 60: R_X86_64_CODE_6_GOTTPOFF foo-0x4 + #pass +diff --git a/gas/testsuite/gas/i386/x86-64-gottpoff.s b/gas/testsuite/gas/i386/x86-64-gottpoff.s +index 6f8f9d1480c..0335ec5debf 100644 +--- a/gas/testsuite/gas/i386/x86-64-gottpoff.s ++++ b/gas/testsuite/gas/i386/x86-64-gottpoff.s +@@ -13,3 +13,13 @@ _start: + + addq r16, QWORD PTR [rip + foo@GOTTPOFF] + movq r20, QWORD PTR [rip + foo@GOTTPOFF] ++ ++ .att_syntax prefix ++ ++ addq %r8, foo@GOTTPOFF(%rip), %r16 ++ addq foo@GOTTPOFF(%rip), %rax, %r12 ++ ++ .intel_syntax noprefix ++ ++ addq r16, QWORD PTR [rip + foo@GOTTPOFF], r8 ++ addq r12, rax, QWORD PTR [rip + foo@GOTTPOFF] +diff --git a/gold/testsuite/x86_64_ie_to_le.s b/gold/testsuite/x86_64_ie_to_le.s +index c5752068866..bd0643dc87f 100644 +--- a/gold/testsuite/x86_64_ie_to_le.s ++++ b/gold/testsuite/x86_64_ie_to_le.s +@@ -7,6 +7,8 @@ _start: + movq foo@gottpoff(%rip), %rax + addq foo@gottpoff(%rip), %r16 + movq foo@gottpoff(%rip), %r20 ++ addq %r30, foo@gottpoff(%rip), %r8 ++ addq foo@gottpoff(%rip), %rax, %r20 + .size _start, .-_start + .section .tdata,"awT",@progbits + .align 4 +diff --git a/gold/testsuite/x86_64_ie_to_le.sh b/gold/testsuite/x86_64_ie_to_le.sh +index 9d2e082f3e0..5308712ddbd 100755 +--- a/gold/testsuite/x86_64_ie_to_le.sh ++++ b/gold/testsuite/x86_64_ie_to_le.sh +@@ -27,3 +27,5 @@ grep -q "add[ \t]\+\$0x[a-f0-9]\+,%r12" x86_64_ie_to_le.stdout + grep -q "mov[ \t]\+\$0x[a-f0-9]\+,%rax" x86_64_ie_to_le.stdout + grep -q "add[ \t]\+\$0x[a-f0-9]\+,%r16" x86_64_ie_to_le.stdout + grep -q "mov[ \t]\+\$0x[a-f0-9]\+,%r20" x86_64_ie_to_le.stdout ++grep -q "add[ \t]\+\$0x[a-f0-9]\+,%r30,%r8" x86_64_ie_to_le.stdout ++grep -q "add[ \t]\+\$0x[a-f0-9]\+,%rax,%r20" x86_64_ie_to_le.stdout +diff --git a/gold/x86_64.cc b/gold/x86_64.cc +index 58e191a055a..f77430bfb3d 100644 +--- a/gold/x86_64.cc ++++ b/gold/x86_64.cc +@@ -2920,6 +2920,11 @@ Target_x86_64::optimize_tls_reloc(bool is_final, int r_type, + // Another Local-Dynamic reloc. + return tls::TLSOPT_TO_LE; + ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: ++ if (r_offset <= 6 || *(reloc_view - 6) != 0x62) ++ return tls::TLSOPT_NONE; ++ goto handle_gottpoff; ++ + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: + if (r_offset <= 4 || *(reloc_view - 4) != 0xd5) + return tls::TLSOPT_NONE; +@@ -2929,6 +2934,7 @@ Target_x86_64::optimize_tls_reloc(bool is_final, int r_type, + // from the GOT. If we know that we are linking against the + // local symbol, we can switch to Local-Exec, which links the + // thread offset into the instruction. ++handle_gottpoff: + if (is_final) + return tls::TLSOPT_TO_LE; + return tls::TLSOPT_NONE; +@@ -2997,6 +3003,7 @@ Target_x86_64::Scan::get_reference_flags(unsigned int r_type) + case elfcpp::R_X86_64_DTPOFF64: + case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + case elfcpp::R_X86_64_TPOFF32: // Local-exec + return Symbol::TLS_REF; + +@@ -3362,6 +3369,7 @@ need_got: + // These are initial tls relocs, which are expected when linking + case elfcpp::R_X86_64_CODE_4_GOTPC32_TLSDESC: + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + { + section_size_type stype; + reloc_view = object->section_contents(data_shndx, &stype, true); +@@ -3464,6 +3472,7 @@ need_got: + + case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + layout->set_has_static_tls(); + if (optimized_type == tls::TLSOPT_NONE) + { +@@ -3902,6 +3911,7 @@ Target_x86_64::Scan::global(Symbol_table* symtab, + // These are initial tls relocs, which are expected for global() + case elfcpp::R_X86_64_CODE_4_GOTPC32_TLSDESC: + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + { + section_size_type stype; + reloc_view = object->section_contents(data_shndx, &stype, true); +@@ -3920,7 +3930,8 @@ Target_x86_64::Scan::global(Symbol_table* symtab, + // when building an executable. + const bool is_final = (gsym->final_value_is_known() || + ((r_type == elfcpp::R_X86_64_GOTTPOFF || +- r_type == elfcpp::R_X86_64_CODE_4_GOTTPOFF) && ++ r_type == elfcpp::R_X86_64_CODE_4_GOTTPOFF|| ++ r_type == elfcpp::R_X86_64_CODE_6_GOTTPOFF) && + gsym->is_undefined() && + parameters->options().output_is_executable())); + size_t r_offset = reloc.get_r_offset(); +@@ -4006,6 +4017,7 @@ Target_x86_64::Scan::global(Symbol_table* symtab, + + case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + layout->set_has_static_tls(); + if (optimized_type == tls::TLSOPT_NONE) + { +@@ -4608,6 +4620,7 @@ Target_x86_64::Relocate::relocate( + case elfcpp::R_X86_64_DTPOFF64: + case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + case elfcpp::R_X86_64_TPOFF32: // Local-exec + this->relocate_tls(relinfo, target, relnum, rela, r_type, gsym, psymval, + view, address, view_size); +@@ -4894,6 +4907,7 @@ Target_x86_64::Relocate::relocate_tls( + + case elfcpp::R_X86_64_GOTTPOFF: // Initial-exec + case elfcpp::R_X86_64_CODE_4_GOTTPOFF: ++ case elfcpp::R_X86_64_CODE_6_GOTTPOFF: + if (gsym != NULL + && gsym->is_undefined() + && parameters->options().output_is_executable()) +@@ -5308,11 +5322,19 @@ Target_x86_64::Relocate::tls_ie_to_le( + + // movq foo@gottpoff(%rip),%reg ==> movq $YY,%reg + // addq foo@gottpoff(%rip),%reg ==> addq $YY,%reg ++ // addq %reg1,foo@gottpoff(%rip),%reg2 ==> addq $YY,%reg1,%reg2 ++ // addq foo@gottpoff(%rip),%reg1,%reg2 ==> addq $YY,%reg1,%reg2 + +- tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, -3); ++ int off1; ++ if (r_type == elfcpp::R_X86_64_CODE_6_GOTTPOFF) ++ off1 = -5; ++ else ++ off1 = -3; ++ ++ tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, off1); + tls::check_range(relinfo, relnum, rela.get_r_offset(), view_size, 4); + +- unsigned char op1 = view[-3]; ++ unsigned char op1 = view[off1]; + unsigned char op2 = view[-2]; + unsigned char op3 = view[-1]; + unsigned char reg = op3 >> 3; +@@ -5350,7 +5372,7 @@ Target_x86_64::Relocate::tls_ie_to_le( + view[-1] = 0x80 | reg | (reg << 3); + } + } +- else ++ else if (r_type == elfcpp::R_X86_64_CODE_4_GOTTPOFF) + { + if (op2 == 0x8b) + op2 = 0xc7; +@@ -5362,6 +5384,23 @@ Target_x86_64::Relocate::tls_ie_to_le( + view[-2] = op2; + view[-1] = 0xc0 | reg; + } ++ else ++ { ++ unsigned char updated_op1 = op1; ++ ++ // Set the R bits since they is inverted. ++ updated_op1 |= 1 << 7 | 1 << 4; ++ ++ // Update the B bits from the R bits. ++ if ((op1 & (1 << 7)) == 0) ++ updated_op1 &= ~(1 << 5); ++ if ((op1 & (1 << 4)) == 0) ++ updated_op1 |= 1 << 3; ++ ++ view[-5] = updated_op1; ++ view[-2] = 0x81; ++ view[-1] = 0xc0 | reg; ++ } + + if (tls_segment != NULL) + value -= tls_segment->memsz(); +diff --git a/include/elf/x86-64.h b/include/elf/x86-64.h +index 33a824620a6..ea5036a8bbf 100644 +--- a/include/elf/x86-64.h ++++ b/include/elf/x86-64.h +@@ -92,6 +92,26 @@ START_RELOC_NUMBERS (elf_x86_64_reloc_type) + /* 32 bit signed pc relative offset to TLS descriptor in the GOT if + instruction starts at 4 bytes before the relocation offset. */ + RELOC_NUMBER (R_X86_64_CODE_4_GOTPC32_TLSDESC, 45) ++ /* Load from 32 bit signed pc relative offset to GOT entry if the ++ instruction starts at 5 bytes before the relocation offset, ++ relaxable. */ ++ RELOC_NUMBER (R_X86_64_CODE_5_GOTPCRELX, 46) ++ /* 32 bit signed pc relative offset to TLS descriptor in the GOT if ++ instruction starts at 5 bytes before the relocation offset. */ ++ RELOC_NUMBER (R_X86_64_CODE_5_GOTPC32_TLSDESC, 47) ++ /* PC relative offset to IE GOT entry if the instruction starts at ++ 5 bytes before the relocation offset. */ ++ RELOC_NUMBER (R_X86_64_CODE_5_GOTTPOFF, 48) ++ /* Load from 32 bit signed pc relative offset to GOT entry if the ++ instruction starts at 6 bytes before the relocation offset, ++ relaxable. */ ++ RELOC_NUMBER (R_X86_64_CODE_6_GOTPCRELX, 49) ++ /* PC relative offset to IE GOT entry if the instruction starts at ++ 6 bytes before the relocation offset. */ ++ RELOC_NUMBER (R_X86_64_CODE_6_GOTTPOFF, 50) ++ /* 32 bit signed pc relative offset to TLS descriptor in the GOT if ++ instruction starts at 6 bytes before the relocation offset. */ ++ RELOC_NUMBER (R_X86_64_CODE_6_GOTPC32_TLSDESC, 51) + RELOC_NUMBER (R_X86_64_GNU_VTINHERIT, 250) /* GNU C++ hack */ + RELOC_NUMBER (R_X86_64_GNU_VTENTRY, 251) /* GNU C++ hack */ + END_RELOC_NUMBERS (R_X86_64_max) +diff --git a/ld/testsuite/ld-x86-64/tlsbindesc.dd b/ld/testsuite/ld-x86-64/tlsbindesc.dd +index 4587cc751b4..be89f38199d 100644 +--- a/ld/testsuite/ld-x86-64/tlsbindesc.dd ++++ b/ld/testsuite/ld-x86-64/tlsbindesc.dd +@@ -169,18 +169,42 @@ Disassembly of section .text: + +[0-9a-f]+: d5 48 03 05 ([0-9a-f]{2} ){3}[ ]+add 0x[0-9a-f]+\(%rip\),%r16 +# [0-9a-f]+ + # -> R_X86_64_TPOFF64 sG2 + +[0-9a-f]+: 00 * ++ +[0-9a-f]+: 62 f4 fc 10 01 ([0-9a-f]{2} ){2}[ ]+add %rax,0x[0-9a-f]+\(%rip\),%r16 +# [0-9a-f]+ ++# -> R_X86_64_TPOFF64 sG2 ++ +[0-9a-f]+: ([0-9a-f]{2} ){3} * ++ +[0-9a-f]+: 62 f4 fc 10 03 ([0-9a-f]{2} ){2}[ ]+add 0x[0-9a-f]+\(%rip\),%rax,%r16 +# [0-9a-f]+ ++# -> R_X86_64_TPOFF64 sG2 ++ +[0-9a-f]+: ([0-9a-f]{2} ){3} * + # IE -> LE against global var defined in exec + +[0-9a-f]+: d5 18 81 c1 60 ff ff[ ]+add \$0xf+60,%r17 + # sg1 + +[0-9a-f]+: ff * ++ +[0-9a-f]+: 62 d4 f4 10 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r8,%r17 ++# sg1 ++ +[0-9a-f]+: ff ff ff * ++ +[0-9a-f]+: 62 d4 f4 10 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r8,%r17 ++# sg1 ++ +[0-9a-f]+: ff ff ff * + # IE -> LE against local var + +[0-9a-f]+: d5 18 81 c2 80 ff ff[ ]+add \$0xf+80,%r18 + # sl1 + +[0-9a-f]+: ff * ++ +[0-9a-f]+: 62 d4 fc 18 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r8,%rax ++# sl1 ++ +[0-9a-f]+: ff ff ff * ++ +[0-9a-f]+: 62 d4 fc 18 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r8,%rax ++# sl1 ++ +[0-9a-f]+: ff ff ff * + # IE -> LE against hidden var + +[0-9a-f]+: d5 18 81 c3 a0 ff ff[ ]+add \$0xf+a0,%r19 + # sh1 + +[0-9a-f]+: ff * ++ +[0-9a-f]+: 62 fc bc 18 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r19,%r8 ++# sh1 ++ +[0-9a-f]+: ff ff ff * ++ +[0-9a-f]+: 62 fc bc 18 81 ([0-9a-f]{2} ){2}[ ]+add \$0x[0-9a-f]+,%r19,%r8 ++# sh1 ++ +[0-9a-f]+: ff ff ff * + # Direct access through %fs + # IE against global var + +[0-9a-f]+: d5 48 8b 25 ([0-9a-f]{2} ){3}[ ]+mov 0x[0-9a-f]+\(%rip\),%r20 +# [0-9a-f]+ +diff --git a/ld/testsuite/ld-x86-64/tlsbindesc.rd b/ld/testsuite/ld-x86-64/tlsbindesc.rd +index daaea7a5371..59325b04e19 100644 +--- a/ld/testsuite/ld-x86-64/tlsbindesc.rd ++++ b/ld/testsuite/ld-x86-64/tlsbindesc.rd +@@ -15,12 +15,12 @@ Section Headers: + +\[[ 0-9]+\] .dynsym +.* + +\[[ 0-9]+\] .dynstr +.* + +\[[ 0-9]+\] .rela.dyn +.* +- +\[[ 0-9]+\] .text +PROGBITS +0+401000 0+1000 0+25d 00 +AX +0 +0 +4096 +- +\[[ 0-9]+\] .tdata +PROGBITS +0+60125d 0+125d 0+60 00 WAT +0 +0 +1 +- +\[[ 0-9]+\] .tbss +NOBITS +0+6012bd 0+12bd 0+40 00 WAT +0 +0 +1 +- +\[[ 0-9]+\] .dynamic +DYNAMIC +0+6012c0 0+12c0 0+100 10 +WA +4 +0 +8 +- +\[[ 0-9]+\] .got +PROGBITS +0+6013c0 0+13c0 0+20 08 +WA +0 +0 +8 +- +\[[ 0-9]+\] .got.plt +PROGBITS +0+6013e0 0+13e0 0+18 08 +WA +0 +0 +8 ++ +\[[ 0-9]+\] .text +PROGBITS +0+401000 0+1000 0+2ad 00 +AX +0 +0 +4096 ++ +\[[ 0-9]+\] .tdata +PROGBITS +0+6012ad 0+12ad 0+60 00 WAT +0 +0 +1 ++ +\[[ 0-9]+\] .tbss +NOBITS +0+60130d 0+130d 0+40 00 WAT +0 +0 +1 ++ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+601310 0+1310 0+100 10 +WA +4 +0 +8 ++ +\[[ 0-9]+\] .got +PROGBITS +0+601410 0+1410 0+20 08 +WA +0 +0 +8 ++ +\[[ 0-9]+\] .got.plt +PROGBITS +0+601430 0+1430 0+18 08 +WA +0 +0 +8 + +\[[ 0-9]+\] .symtab +.* + +\[[ 0-9]+\] .strtab +.* + +\[[ 0-9]+\] .shstrtab +.* +@@ -28,7 +28,7 @@ Key to Flags: + #... + + Elf file type is EXEC \(Executable file\) +-Entry point 0x401165 ++Entry point 0x4011b5 + There are [0-9]+ program headers, starting at offset [0-9]+ + + Program Headers: +@@ -36,10 +36,10 @@ Program Headers: + +PHDR.* + +INTERP.* + .*Requesting program interpreter.* +- +LOAD +0x0+ 0x0+400000 0x0+400000 0x0+125d 0x0+125d R E 0x200000 +- +LOAD +0x0+125d 0x0+60125d 0x0+60125d 0x0+19b 0x0+19b RW +0x200000 +- +DYNAMIC +0x0+12c0 0x0+6012c0 0x0+6012c0 0x0+100 0x0+100 RW +0x8 +- +TLS +0x0+125d 0x0+60125d 0x0+60125d 0x0+60 0x0+a0 R +0x1 ++ +LOAD +0x0+ 0x0+400000 0x0+400000 0x0+12ad 0x0+12ad R E 0x200000 ++ +LOAD +0x0+12ad 0x0+6012ad 0x0+6012ad 0x0+19b 0x0+19b RW +0x200000 ++ +DYNAMIC +0x0+1310 0x0+601310 0x0+601310 0x0+100 0x0+100 RW +0x8 ++ +TLS +0x0+12ad 0x0+6012ad 0x0+6012ad 0x0+60 0x0+a0 R +0x1 + + Section to Segment mapping: + +Segment Sections... +@@ -52,10 +52,10 @@ Program Headers: + + Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 4 entries: + +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend +-0+6013c0 +0+100000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0 +-0+6013c8 +0+200000012 R_X86_64_TPOFF64 +0+ sG2 \+ 0 +-0+6013d0 +0+300000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0 +-0+6013d8 +0+400000012 R_X86_64_TPOFF64 +0+ sG1 \+ 0 ++0+601410 +0+100000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0 ++0+601418 +0+200000012 R_X86_64_TPOFF64 +0+ sG2 \+ 0 ++0+601420 +0+300000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0 ++0+601428 +0+400000012 R_X86_64_TPOFF64 +0+ sG1 \+ 0 + + Symbol table '\.dynsym' contains [0-9]+ entries: + +Num: +Value +Size +Type +Bind +Vis +Ndx +Name +@@ -88,8 +88,8 @@ Symbol table '\.symtab' contains [0-9]+ entries: + +[0-9]+: 0+9c +0 +TLS +LOCAL +DEFAULT +8 bl8 + .* FILE +LOCAL +DEFAULT +ABS + +[0-9]+: 0+a0 +0 +TLS +LOCAL +DEFAULT +7 _TLS_MODULE_BASE_ +- +[0-9]+: 0+6012c0 +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC +- +[0-9]+: 0+6013e0 +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_ ++ +[0-9]+: 0+601310 +0 +OBJECT +LOCAL +DEFAULT +9 _DYNAMIC ++ +[0-9]+: 0+601430 +0 +OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_ + +[0-9]+: 0+1c +0 +TLS +GLOBAL +DEFAULT +7 sg8 + +[0-9]+: 0+7c +0 +TLS +GLOBAL +DEFAULT +8 bg8 + +[0-9]+: 0+74 +0 +TLS +GLOBAL +DEFAULT +8 bg6 +@@ -104,7 +104,7 @@ Symbol table '\.symtab' contains [0-9]+ entries: + +[0-9]+: 0+58 +0 +TLS +GLOBAL +HIDDEN +7 sh7 + +[0-9]+: 0+5c +0 +TLS +GLOBAL +HIDDEN +7 sh8 + +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +7 sg1 +- +[0-9]+: 0+401165 +0 +FUNC +GLOBAL +DEFAULT +6 _start ++ +[0-9]+: 0+4011b5 +0 +FUNC +GLOBAL +DEFAULT +6 _start + +[0-9]+: 0+4c +0 +TLS +GLOBAL +HIDDEN +7 sh4 + +[0-9]+: 0+78 +0 +TLS +GLOBAL +DEFAULT +8 bg7 + +[0-9]+: 0+50 +0 +TLS +GLOBAL +HIDDEN +7 sh5 +diff --git a/ld/testsuite/ld-x86-64/tlsbindesc.s b/ld/testsuite/ld-x86-64/tlsbindesc.s +index b80e5f192c0..4747fc1bc30 100644 +--- a/ld/testsuite/ld-x86-64/tlsbindesc.s ++++ b/ld/testsuite/ld-x86-64/tlsbindesc.s +@@ -129,15 +129,23 @@ fn2: + + /* IE against global var */ + addq sG2@gottpoff(%rip), %r16 ++ addq %rax, sG2@gottpoff(%rip), %r16 ++ addq sG2@gottpoff(%rip), %rax, %r16 + + /* IE -> LE against global var defined in exec */ + addq sg1@gottpoff(%rip), %r17 ++ addq %r8, sg1@gottpoff(%rip), %r17 ++ addq sg1@gottpoff(%rip), %r8, %r17 + + /* IE -> LE against local var */ + addq sl1@gottpoff(%rip), %r18 ++ addq %r8, sl1@gottpoff(%rip), %rax ++ addq sl1@gottpoff(%rip), %r8, %rax + + /* IE -> LE against hidden var */ + addq sh1@gottpoff(%rip), %r19 ++ addq %r19, sh1@gottpoff(%rip), %r8 ++ addq sh1@gottpoff(%rip), %r19, %r8 + + /* Direct access through %fs */ + +-- +2.31.1 + diff --git a/binutils-2.19.50.0.1-output-format.sed b/binutils-2.19.50.0.1-output-format.sed new file mode 100644 index 0000000000000000000000000000000000000000..fd770cb255d266b685133ca1230d42d850cfcd51 --- /dev/null +++ b/binutils-2.19.50.0.1-output-format.sed @@ -0,0 +1,38 @@ +# Generate OUTPUT_FORMAT line for .so files from the system linker output. +# Imported from glibc/Makerules. + +/ld.*[ ]-E[BL]/b f +/collect.*[ ]-E[BL]/b f +/OUTPUT_FORMAT[^)]*$/{N +s/\n[ ]*/ / +} +t o +: o +s/^.*OUTPUT_FORMAT(\([^,]*\), \1, \1).*$/OUTPUT_FORMAT(\1)/ +t q +s/^.*OUTPUT_FORMAT(\([^,]*\), \([^,]*\), \([^,]*\)).*$/\1,\2,\3/ +t s +s/^.*OUTPUT_FORMAT(\([^,)]*\).*$)/OUTPUT_FORMAT(\1)/ +t q +d +: s +s/"//g +G +s/\n// +s/^\([^,]*\),\([^,]*\),\([^,]*\),B/OUTPUT_FORMAT(\2)/p +s/^\([^,]*\),\([^,]*\),\([^,]*\),L/OUTPUT_FORMAT(\3)/p +s/^\([^,]*\),\([^,]*\),\([^,]*\)/OUTPUT_FORMAT(\1)/p +/,/s|^|*** BUG in libc/scripts/output-format.sed *** |p +q +: q +s/"//g +p +q +: f +s/^.*[ ]-E\([BL]\)[ ].*$/,\1/ +t h +s/^.*[ ]-E\([BL]\)$/,\1/ +t h +d +: h +h diff --git a/binutils-2.27-aarch64-ifunc.patch b/binutils-2.27-aarch64-ifunc.patch new file mode 100644 index 0000000000000000000000000000000000000000..562ef18c231c6b2fee44183b1e943d8a2a7a719a --- /dev/null +++ b/binutils-2.27-aarch64-ifunc.patch @@ -0,0 +1,11 @@ +diff -rup binutils.orig/bfd/elfnn-aarch64.c binutils-2.27/bfd/elfnn-aarch64.c +--- binutils.orig/bfd/elfnn-aarch64.c 2017-02-21 10:45:19.311956006 +0000 ++++ binutils-2.27/bfd/elfnn-aarch64.c 2017-02-21 11:55:07.517922655 +0000 +@@ -4947,6 +4947,7 @@ elfNN_aarch64_final_link_relocate (reloc + it here if it is defined in a non-shared object. */ + if (h != NULL + && h->type == STT_GNU_IFUNC ++ && (input_section->flags & SEC_ALLOC) + && h->def_regular) + { + asection *plt; diff --git a/binutils-2.42.spec b/binutils-2.42.spec new file mode 100644 index 0000000000000000000000000000000000000000..8fae807f51891f1e1e823a4d288dbed9aa411c05 --- /dev/null +++ b/binutils-2.42.spec @@ -0,0 +1,1292 @@ +%{?scl_package:%global scl gcc-toolset-14} +%global _vendor %{?_vendor:%{_vendor}}%{!?_vendor:openEuler} +%global _scl_prefix gcc-toolset-14- +%global _scl_path /opt/%{_vendor}/gcc-toolset-14 +%global _scl_root /opt/%{_vendor}/gcc-toolset-14/root +%global _prefix %{_scl_root}/usr +%global _sysconfdir %{_scl_root}/etc +%global _libdir %{_prefix}/lib64 +%global _infodir %{_prefix}/share/info +%global _bindir %{_prefix}/bin +%global _mandir %{_prefix}/share/man +%global _root_sbindir /usr/sbin +%global binutils_ver %{nil} + +Summary: A GNU collection of binary utilities +Name: %{?_scl_prefix}binutils%{binutils_ver} +Version: 2.42 +Release: 3 +License: GPLv3+ +URL: https://sourceware.org/binutils +ExcludeArch: loongarch64 + +#---Start of Configure Options----------------------------------------------- + +# The binutils can be built with the following parameters to change +# the default behaviour: + +# --with bootstrap Build with minimal dependencies. +# --with clang Force building with CLANG instead of GCC. +# --with crossbuilds Build cross targeted versions of the binutils as well as natives. +# --with debug Build without optimizations and without splitting the debuginfo into a separate file. +# --with debuginfod Disable support for debuginfod. +# --without docs Skip building documentation. Default is with docs, except when building a cross binutils. +# --without gold Disable building of the GOLD linker. +# --without gprofng Do not build the GprofNG profiler. +# --without systemzlib Use the binutils version of zlib. +# --without testsuite Do not run the testsuite. Default is to run it. + +# Other configuration options can be set by modifying the following defines. + +# Create shared libraries. +%define enable_shared 1 + +# Create deterministic archives (ie ones without timestamps). +# Default is off because of BZ 1195883. +%define enable_deterministic_archives 0 + +# Generate a warning when linking creates an executable stack +%define warn_for_executable_stacks 1 + +# Generate a warning when linking creates a segment with read, write and execute permissions +%define warn_for_rwx_segments 1 + +# Turn the above warnings into errors. +# Only effective if the warnings are enabled. +# Disabled by default because this is now handled by a macro in redhat-rpm-config. +%define error_for_executable_stacks 0 +%define error_for_rwx_segments 0 + +# Enable support for GCC LTO compilation. +# Disable if it is necessary to work around bugs in LTO. +%define enable_lto 1 + +# Enable support for generating new dtags in the linker +# Disable if it is necessary to use RPATH instead. +%define enable_new_dtags 0 + +# Enable the compression of debug sections as default behaviour of the +# assembler and linker. This option is disabled for now. The assembler and +# linker have command line options to override the default behaviour. +%define default_compress_debug 0 + +# Default to read-only-relocations (relro) in shared binaries. +# This is enabled as a security feature. +%define default_relro 1 + +# Enable the default generation of GNU Build notes by the assembler. +# This option is disabled as it has turned out to be problematic for the i686 +# architecture, although the exact reason has not been determined. (See +# BZ 1572485). It also breaks building EFI binaries on AArch64, as these +# cannot have relocations against absolute symbols. +%define default_generate_notes 0 + +# Enable thread support in the GOLD linker (if it is being built). This is +# particularly important if plugins to the linker intend to use threads +# themselves. See BZ 1636479 for more details. This option is made +# configurable in case there is ever a need to disable thread support. +%define enable_threading 1 + +# Enable the use of separate code and data segments for all architectures, +# not just x86/x86_64. +%define enable_separate_code 0 + +#----End of Configure Options------------------------------------------------ + +# Note - in the future the gold linker may become deprecated. +%ifnarch riscv64 +%bcond_without gold +%else +# RISC-V does not have ld.gold thus disable by default. +%bcond_with gold +%endif + +# Default: Not bootstrapping. +%bcond_with bootstrap +# Default: Not debug +%bcond_with debug +# Default: Always build documentation. +%bcond_without docs +# Default: Always run the testsuite. FIXME: Temporarily disable it. +%bcond_with testsuite +# Default: Not support debuginfod. +%bcond_with debuginfod +# Default: Not build binutils-gprofng package. +%bcond_with gprofng +# Default: Use the system supplied version of the zlib compression library. +%bcond_without systemzlib + +# Allow the user to override the compiler used to build the binutils. +# The default build compiler is gcc if %%toolchain is not clang. +%if "%toolchain" == "clang" +%bcond_without clang +%else +%bcond_with clang +%endif + +%if %{with clang} +%global toolchain clang +%else +%global toolchain gcc +%endif + +# (Do not) create cross targeted versions of the binutils. +%bcond_with crossbuilds +# %%bcond_without crossbuilds + +%if %{with bootstrap} +%undefine with_docs +%undefine with_testsuite +%undefine with_gprofng +%endif + +%if %{with debug} +%undefine with_testsuite +%define enable_shared 0 +%endif + +# GprofNG currenly only supports the x86 and AArch64 architectures. +%ifnarch x86_64 aarch64 +%undefine with_gprofng +%endif + +# The opcodes library needs a few functions defined in the bfd +# library, but these symbols are not defined in the stub bfd .so +# that is available at link time. (They are present in the real +# .so that is used at run time). +%undefine _strict_symbol_defs_build + +# BZ 1924068. Since applications that use the BFD library are +# required to link against the static version, ensure that it retains +# its debug informnation. +%undefine __brp_strip_static_archive + +#---------------------------------------------------------------------------- + +# Note - the Linux Kernel binutils releases are too unstable and contain +# too many controversial patches so we stick with the official FSF version +# instead. + +Source: https://ftp.gnu.org/gnu/binutils/binutils-%{version}.tar.xz +Source2: binutils-2.19.50.0.1-output-format.sed + +#---------------------------------------------------------------------------- + +# OpenEuler Patch Naming Rules +# https://gitee.com/openeuler/TC/blob/master/oEEP/oEEP-0012%20openEuler%E8%BD%AF%E4%BB%B6%E5%8C%85%E9%9D%9Eupstream%E6%94%AF%E6%8C%81%E5%A4%9A%E6%9E%B6%E6%9E%84%E4%BB%A3%E7%A0%81%E6%8F%90%E4%BA%A4%E8%A7%84%E5%88%99.md + +# Part 1000 - 1999 +# Part 3000 - 4999 +# Purpose: Add support for RVA23U64 mandatory extensions. +# Lifetime: Backport from upstreams: +# 25f05199bb7e35820c23e802424484accb7936b1 +# 3ba06284d2cada7a4798f7849da113661aff07dd +# 8a3ffa71945816b941d3dea9ebc7013d5be7a1a4 +Patch3001: binutils-2.44-backport-RISC-V-Add-platform-property-capability-extensions.patch +Patch3002: binutils-2.44-backport-RISC-V-Add-support-for-Zimop-extension.patch +Patch3003: binutils-2.44-backport-RISC-V-Add-support-for-Zcmop-extension.patch + +# Part 5000 - +# Purpose: Use /lib64 and /usr/lib64 instead of /lib and /usr/lib in the +# default library search path of 64-bit targets. +# Lifetime: Permanent, but it should not be. This is a bug in the libtool +# sources used in both binutils and gcc, (specifically the +# libtool.m4 file). These are based on a version released in 2009 +# (2.2.6?) rather than the latest version. (Definitely fixed in +# libtool version 2.4.6). +Patch5001: binutils-libtool-lib64.patch + +# Purpose: Exports the demangle.h header file (associated with the libiberty +# sources) with the binutils-devel rpm. +# Lifetime: Permanent. This is a Vendor specific patch. +Patch5002: binutils-export-demangle.h.patch + +# Purpose: Disables the check in the BFD library's bfd.h header file that +# config.h has been included before the bfd.h header. See BZ +# #845084 for more details. +# Lifetime: Permanent - but it should not be. The bfd.h header defines +# various types that are dependent upon configuration options, so +# the order of inclusion is important. +# FIXME: It would be better if the packages using the bfd.h header were +# fixed so that they do include the header files in the correct +# order. +Patch5003: binutils-no-config-h-check.patch + +# Purpose: Do not create PLT entries for AARCH64 IFUNC symbols referenced in +# debug sections. +# Lifetime: Permanent. +# FIXME: Find related bug. Decide on permanency. +Patch5004: binutils-2.27-aarch64-ifunc.patch + +# Purpose: Allow OS specific sections in section groups. +# Lifetime: Fixed in 2.42 (maybe) +Patch5005: binutils-special-sections-in-groups.patch + +# Purpose: Stop gold from aborting when input sections with the same name +# have different flags. +# Lifetime: Fixed in 2.42 (maybe) +Patch5006: binutils-gold-mismatched-section-flags.patch + +%if %{enable_new_dtags} +# Purpose: Change ld man page so that it says that --enable-new-dtags is the default. +# Lifetime: Permanent +Patch5007: binutils-update-linker-manual.patch +%endif + +# Purpose: Stop an abort when using dwp to process a file with no dwo links. +# Lifetime: Fixed in 2.42 (maybe) +Patch5008: binutils-gold-empty-dwp.patch + +# Purpose: Support new relocation type for APX. +# Lifetime: Fixed in 2.43 +Patch5009: backport-x86-64-Add-R_X86_64_CODE_6_GOTTPOFF.patch + +#---------------------------------------------------------------------------- + +Provides: bundled(libiberty) + +%if %{with debug} +# Define this if you want to skip the strip step and preserve debug info. +# Useful for testing. +%define __debug_install_post : > %{_builddir}/%{?buildsubdir}/debugfiles.list +%define debug_package %{nil} +%endif + +# Perl, sed and touch are all used in the %%prep section of this spec file. +BuildRequires: autoconf, automake, perl, sed, coreutils, make, chrpath + +%if %{with clang} +BuildRequires: clang compiler-rt +%else + +# Use the GTS version of gcc to build the binutils so that the built static libraries +# (libfd.a, libopcodes.a libiberty.a libsframe.a) use the same LTO version as the one +# that will be used by consumers of GTS binutils. +# Note - during GTS bootstrap these have to be changed to the systemOS versions. +BuildRequires: gcc + + +%endif + +%if %{with gold} +# Gold needs bison in order to build gold/yyscript.c. The GOLD testsuite needs a static libc++ +BuildRequires: bison, m4, gcc-c++, libstdc++-static + +%if ! %{with clang} +BuildRequires: gcc-c++ +Conflicts: gcc-c++ < 4.0.0 +%endif +%endif + +%if %{without bootstrap} +BuildRequires: gettext, flex, jansson-devel +%if %{with systemzlib} +BuildRequires: zlib-devel +%endif +%endif + +%if %{with docs} +BuildRequires: texinfo >= 4.0 +# BZ 920545: We need pod2man in order to build the manual pages. +BuildRequires: /usr/bin/pod2man +%else +BuildRequires: findutils +%endif + +# Required for: ld-bootstrap/bootstrap.exp bootstrap with --static +# It should not be required for: ld-elf/elf.exp static {preinit,init,fini} array +%if %{with testsuite} +# relro_test.sh uses dc which is part of the bc rpm, hence its inclusion here. +# sharutils is needed so that we can uuencode the testsuite results. +BuildRequires: dejagnu, glibc-static, sharutils, bc, libstdc++ +%if %{with systemzlib} +BuildRequires: zlib-devel +%endif +%endif + +%if %{with debuginfod} +BuildRequires: elfutils-debuginfod-client-devel +%endif + +%define alternatives_cmd %{_root_sbindir}/alternatives +%define alternatives_cmdline %{alternatives_cmd} --altdir %{_sysconfdir}/alternatives --admindir %{_scl_root}/var/lib/alternatives + + +Requires(post): %{alternatives_cmd} +Requires(preun): %{alternatives_cmd} + +# We also need rm. +Requires(post): coreutils + +%if %{with gold} +# For now we make the binutils package require the gold sub-package. +# That way other packages that have a requirement on "binutils" but +# actually want gold will not have to be changed. In the future, if +# we decide to deprecate gold, we can remove this requirement, and +# then update other packages as necessary. +Requires: %{?_scl_prefix}binutils-gold >= %{version} +%endif + +# On ARM EABI systems, we do want -gnueabi to be part of the +# target triple. +%ifnarch %{arm} +%define _gnu %{nil} +%endif + +#---------------------------------------------------------------------------- + +%description +Binutils is a collection of binary utilities, including ar (for +creating, modifying and extracting from archives), as (a family of GNU +assemblers), gprof (for displaying call graph profile data), ld (the +GNU linker), nm (for listing symbols from object files), objcopy (for +copying and translating object files), objdump (for displaying +information from object files), ranlib (for generating an index for +the contents of an archive), readelf (for displaying detailed +information about binary files), size (for listing the section sizes +of an object or archive file), strings (for listing printable strings +from files), strip (for discarding symbols), and addr2line (for +converting addresses to file and line). + +#---------------------------------------------------------------------------- + +%package -n %{?_scl_prefix}binutils-devel%{binutils_ver} +Summary: BFD and opcodes static and dynamic libraries and header files +Provides: %{?_scl_prefix}binutils-static = %{version}-%{release} +%if %{with systemzlib} +Requires: zlib-devel +%endif +Requires: %{?_scl_prefix}binutils = %{version}-%{release} +# BZ 1215242: We need touch... +Requires: coreutils + +%description -n %{?_scl_prefix}binutils-devel%{binutils_ver} +This package contains BFD and opcodes static and dynamic libraries. + +The dynamic libraries are in this package, rather than a separate +base package because they are actually linker scripts that force +the use of the static libraries. This is because the API of the +BFD library is too unstable to be used dynamically. + +The static libraries are here because they are now needed by the +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} + +%package -n %{?_scl_prefix}binutils-gold%{binutils_ver} +Summary: The GOLD linker, a faster alternative to the BFD linker +Provides: %{?_scl_prefix}binutils-gold = %{version}-%{release} +Requires: %{?_scl_prefix}binutils >= %{version} + +%description -n %{?_scl_prefix}binutils-gold%{binutils_ver} +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. + +# The higher of these two numbers determines the default linker. +%{!?ld_gold_priority:%global ld_gold_priority 30} + +%endif + +%{!?ld_bfd_priority: %global ld_bfd_priority 50} + +#---------------------------------------------------------------------------- + +%if %{with gprofng} +%package -n %{?_scl_prefix}gprofng%{binutils_ver} +Summary: Next Generating code profiling tool +Provides: %{?_scl_prefix}binutils-gprofng = %{version}-%{release} +Requires: %{?_scl_prefix}binutils = %{version}-%{release} + +%description -n %{?_scl_prefix}gprofng%{binutils_ver} +GprofNG is the GNU Next Generation Profiler for analyzing the performance +of Linux applications. + +%endif + +#---------------------------------------------------------------------------- + +%if %{with crossbuilds} + +# Uncomment this when testing changes to the spec file, especially the cross building support. +# Remember to comment it out again once the testing is complete. +# %%undefine with_testsuite + +# The list of cross targets to build. +%global system %{_vendor}-linux +%global cross_targets aarch64-%{system} ppc64le-%{system} s390x-%{system} x86_64-%{system} + +%package -n %{?_scl_prefix}cross-binutils-aarch64%{binutils_ver} +Summary: Cross targeted AArch64 binutils for developer use. Not intended for production. +Provides: cross-binutils-aarch64 = %{version}-%{release} +Requires: coreutils +%if %{with systemzlib} +Requires: zlib-devel +%endif +BuildRequires: autoconf automake perl sed coreutils make gcc findutils gcc-c++ +ExcludeArch: aarch64-linux-gnu aarch64-%{_vendor}-linux + +%description -n %{?_scl_prefix}cross-binutils-aarch64%{binutils_ver} +This package contains an AArch64 cross targeted version of the binutils for +use by developers. It is NOT INTENDED FOR PRODUCTION use. + + +%package -n %{?_scl_prefix}cross-binutils-ppc64le%{binutils_ver} +Summary: Cross targeted PPC64LE binutils for developer use. Not intended for production. +Provides: cross-binutils-ppc64le = %{version}-%{release} +Requires: coreutils +%if %{with systemzlib} +Requires: zlib-devel +%endif +BuildRequires: autoconf automake perl sed coreutils make gcc findutils gcc-c++ +ExcludeArch: ppc64le-linux-gnu ppc64le-%{_vendor}-linux + +%description -n %{?_scl_prefix}cross-binutils-ppc64le%{binutils_ver} +This package contains a PPC64LE cross targeted version of the binutils for +use by developers. It is NOT INTENDED FOR PRODUCTION use. + + +%package -n %{?_scl_prefix}cross-binutils-s390x%{binutils_ver} +Summary: Cross targeted S390X binutils for developer use. Not intended for production. +Provides: cross-binutils-s390x = %{version}-%{release} +Requires: coreutils +%if %{with systemzlib} +Requires: zlib-devel +%endif +BuildRequires: autoconf automake perl sed coreutils make gcc findutils gcc-c++ +ExcludeArch: s390x-linux-gnu s390x-%{_vendor}-linux + +%description -n %{?_scl_prefix}cross-binutils-s390x%{binutils_ver} +This package contains a S390X cross targeted version of the binutils for +use by developers. It is NOT INTENDED FOR PRODUCTION use. + + +%package -n %{?_scl_prefix}cross-binutils-x86_64%{binutils_ver} +Summary: Cross targeted X86_64 binutils for developer use. Not intended for production. +Provides: cross-binutils-x86_64 = %{version}-%{release} +Requires: coreutils +%if %{with systemzlib} +Requires: zlib-devel +%endif +BuildRequires: autoconf automake perl sed coreutils make gcc findutils gcc-c++ +ExcludeArch: x86_64-linux-gnu x86_64-%{_vendor}-linux i686-linux-gnu i686-%{_vendor}-linux + +%description -n %{?_scl_prefix}cross-binutils-x86_64%{binutils_ver} +This package contains a X86_64 cross targeted version of the binutils for +use by developers. It is NOT INTENDED FOR PRODUCTION use. + +%endif + +#---------------------------------------------------------------------------- + +%prep +# NB/ Do not add {?_scl_prefix} to the -n option below. The binutils sources +# uppack into a directory called binutils-VERSION not gcc-toolset-13-binutils-VERSION. +%autosetup -p1 -n binutils-%{version} + +# On ppc64 and aarch64, we might use 64KiB pages +sed -i -e '/#define.*ELF_COMMONPAGESIZE/s/0x1000$/0x10000/' bfd/elf*ppc.c +sed -i -e '/#define.*ELF_COMMONPAGESIZE/s/0x1000$/0x10000/' bfd/elf*aarch64.c +sed -i -e '/common_pagesize/s/4 /64 /' gold/powerpc.cc +sed -i -e '/pagesize/s/0x1000,/0x10000,/' gold/aarch64.cc + +# LTP issues +perl -pi -e 's/i\[3-7\]86/i[34567]86/g' */conf* +sed -i -e 's/%''{release}/%{release}/g' bfd/Makefile{.am,.in} +sed -i -e '/^libopcodes_la_\(DEPENDENCIES\|LIBADD\)/s,$, ../bfd/libbfd.la,' opcodes/Makefile.{am,in} + +# Build libbfd.so and libopcodes.so with -Bsymbolic-functions if possible. +if gcc %{optflags} -v --help 2>&1 | grep -q -- -Bsymbolic-functions; then +sed -i -e 's/^libbfd_la_LDFLAGS = /&-Wl,-Bsymbolic-functions /' bfd/Makefile.{am,in} +sed -i -e 's/^libopcodes_la_LDFLAGS = /&-Wl,-Bsymbolic-functions /' opcodes/Makefile.{am,in} +fi + +# $PACKAGE is used for the gettext catalog name. +sed -i -e 's/^ PACKAGE=/ PACKAGE=%{?cross}/' */configure + +# Undo the name change to run the testsuite. +for tool in binutils gas ld +do + sed -i -e "2aDEJATOOL = $tool" $tool/Makefile.am + sed -i -e "s/^DEJATOOL = .*/DEJATOOL = $tool/" $tool/Makefile.in +done + +# Touch the .info files so that they are newer then the .texi files and +# hence do not need to be rebuilt. This eliminates the need for makeinfo. +# The -print is there just to confirm that the command is working. +%if %{without docs} + find . -name *.info -print -exec touch {} \; +%else +# If we are creating the docs, touch the texi files so that the info and +# man pages will be rebuilt. + find . -name *.texi -print -exec touch {} \; +%endif + +%ifarch %{power64} +%define _target_platform %{_arch}-%{_vendor}-%{_host_os} +%endif + +#---------------------------------------------------------------------------- + +%build + +# Building is now handled by functions which allow for both native and cross +# builds. Builds are created in their own sub-directory of the sources, which +# allows for both native and cross builds to be created at the same time. + +# compute_global_configuration() +# Build the CARGS variable which contains the global configuration arguments. +compute_global_configuration() +{ + CARGS="--quiet \ + --build=%{_target_platform} \ + --host=%{_target_platform} \ + --enable-ld \ + --enable-plugins \ + --enable-64-bit-bfd \ + --with-bugurl=https://gitee.com/src-openeuler/binutils-2.42/issues/" + +%if %{without bootstrap} + CARGS="$CARGS --enable-jansson=yes" +%endif + +%if %{with debuginfod} + CARGS="$CARGS --with-debuginfod" +%endif + +%if %{with gprofng} + CARGS="$CARGS --enable-gprofng=yes" +%else + CARGS="$CARGS --enable-gprofng=no" +%endif + +%if %{with systemzlib} + CARGS="$CARGS --with-system-zlib" +%endif + +%if %{default_compress_debug} + CARGS="$CARGS --enable-compressed-debug-sections=all" +%else + CARGS="$CARGS --enable-compressed-debug-sections=none" +%endif + +%if %{default_generate_notes} + CARGS="$CARGS --enable-generate-build-notes=yes" +%else + CARGS="$CARGS --enable-generate-build-notes=no" +%endif + +%if %{default_relro} + CARGS="$CARGS --enable-relro=yes" +%else + CARGS="$CARGS --enable-relro=no" +%endif + +%if %{enable_deterministic_archives} + CARGS="$CARGS --enable-deterministic-archives" +%else + CARGS="$CARGS --enable-deterministic-archives=no" +%endif + +%if %{warn_for_executable_stacks} + CARGS="$CARGS --enable-warn-execstack=yes" + CARGS="$CARGS --enable-default-execstack=no" +%if %{error_for_executable_stacks} + CARGS="$CARGS --enable-error-execstack=yes" +%endif +%else + CARGS="$CARGS --enable-warn-execstack=no" +%endif + +%if %{warn_for_rwx_segments} + CARGS="$CARGS --enable-warn-rwx-segments=yes" +%if %{error_for_rwx_segments} + CARGS="$CARGS --enable-error-rwx-segments=yes" +%endif +%else + CARGS="$CARGS --enable-warn-rwx-segments=no" +%endif + +%if %{enable_lto} + CARGS="$CARGS --enable-lto" +%endif + +%if %{enable_new_dtags} + CARGS="$CARGS --enable-new-dtags --disable-rpath" +%endif + +%if %{enable_separate_code} + CARGS="$CARGS --enable-separate-code=yes" +%endif + +%if %{enable_threading} + CARGS="$CARGS --enable-threads=yes" +%else + CARGS="$CARGS --enable-threads=no" +%endif +} + +# run_target_configuration() +# Create and configure the build tree. +# $1 is the target architecture +# $2 is 1 if this is a native build +# $3 is 1 if shared libraries should be built +# +run_target_configuration() +{ + local target="$1" + local native="$2" + local shared="$3" + local builddir=build-$target + + # Create a build directory + rm -rf $builddir + mkdir $builddir + pushd $builddir + + echo "BUILDING the Binutils for TARGET $target (native ? $native) (shared ? $shared)" + + %set_build_flags + +%ifarch %{power64} + export CFLAGS="$RPM_OPT_FLAGS -Wno-error" +%else + export CFLAGS="$RPM_OPT_FLAGS" +%endif + +%if %{with debug} + %undefine _fortify_level + export CFLAGS="$CFLAGS -O0 -ggdb2 -Wno-error" +%endif + + export CXXFLAGS="$CXXFLAGS $CFLAGS" + + # BZ 1541027 - include the linker flags from %%{_vendor}-rpm-config as well. + export LDFLAGS=$RPM_LD_FLAGS + +%if %{enable_new_dtags} + # Build the tools with new dtags, as well as supporting their generation by the linker. + export LDFLAGS="$LDFLAGS -Wl,--enable-new-dtags" +%endif + + if test x$native == x1 ; then + # Extra targets to build along with the native one. + # + # BZ 1920373: Enable PEP support for all targets as the PERF package's + # testsuite expects to be able to read PE format files ragrdless of + # the host's architecture. + case $target in + s390*) + # Note - The s390-linux target is there so that the GOLD linker will + # build. By default, if configured for just s390x-linux, the GOLD + # configure system will only include support for 64-bit targets, but + # the s390x gold backend uses both 32-bit and 64-bit templates. + TARGS="--enable-targets=s390-linux,s390x-linux,x86_64-pep" + ;; + ia64*) + TARGS="--enable-targets=ia64-linux,x86_64-pep" + ;; + ppc64-*) + TARGS="--enable-targets=powerpc64le-linux,x86_64-pep" + ;; + ppc64le*) + TARGS="--enable-targets=powerpc-linux,x86_64-pep" + ;; + *) + TARGS="--enable-targets=x86_64-pep" + ;; + esac + + # Set up the sysroot and paths. + SARGS="--with-sysroot=/ \ + --prefix=%{_prefix} \ + --libdir=%{_libdir} \ + --sysconfdir=%{_sysconfdir}" +%if %{with gold} + SARGS="$SARGS --enable-gold=default" +%else + SARGS="$SARGS --disable-gold" +%endif + + else # Cross builds + + # No extra targets are supported. + TARGS="" + + # Disable the GOLD linker for cross builds because although it does + # support sysroots specified on the command line, it does not support + # them in linker scripts via the =/$SYSROOT prefix. + SARGS="--with-sysroot=yes \ + --program-prefix=$target- \ + --prefix=%{_prefix}/$target \ + --libdir=%{_libdir} \ + --exec-prefix=%{_usr} \ + --sysconfdir=%{_sysconfdir} \ + --disable-gold" + fi + + if test x$shared == x1 ; then + RARGS="--enable-shared" + else + RARGS="--disable-shared" + fi + + ../configure --target=$target $CARGS $SARGS $RARGS $TARGS || cat config.log + + popd +} + +# build_target () +# Builds a configured set of sources. +# $1 is the target architecture +build_target() +{ + local target="$1" + local builddir=build-$target + + pushd $builddir + +%if %{with docs} + # Because of parallel building, info has to be made after all. + %make_build %{_smp_mflags} tooldir=%{_prefix} all + %make_build %{_smp_mflags} tooldir=%{_prefix} info +%else + %make_build %{_smp_mflags} tooldir=%{_prefix} MAKEINFO=true all +%endif + + popd +} + +# run_tests() +# Test a built (but not installed) binutils. +# $1 is the target architecture +# $2 is 1 if this is a native build +# +run_tests() +{ + local target="$1" + local native="$2" + + echo "TESTING the binutils FOR TARGET $target (native ? $native)" + + # Do not use %%check as it is run after %%install where libbfd.so is rebuilt + # with -fvisibility=hidden no longer being usable in its shared form. +%if %{without testsuite} + echo ================ $target == TESTSUITE DISABLED ==================== + return +%endif + + pushd build-$target + + # FIXME: I have not been able to find a way to capture a "failed" return + # value from "make check" without having it also stop the build. So in + # order to obtain the logs from the test runs if a check fails I have to + # run the tests twice. Once to generate the logs and then a second time + # to generate the correct exit code. + + echo ================ $target == TEST RUN 1 ============================= + + # Run the tests and accumulate the logs - but ignore failures... + + if test x$native == x1 ; then + make -k check-gas check-binutils check-ld < /dev/null || : +%if %{with gold} + # The GOLD testsuite always returns an error code, even if no tests fail. + make -k check-gold < /dev/null || : +%endif + else + # Do not try running linking tests for the cross-binutils. + make -k check-gas check-binutils < /dev/null || : + fi + + for f in {gas/testsuite/gas,ld/ld,binutils/binutils}.sum + do + if [ -f $f ]; then + cat $f + fi + done + +%if %{with gold} + if [ -f gold/test-suite.log ]; then + cat gold/test-suite.log + fi + if [ -f gold/testsuite/test-suite.log ]; then + cat gold/testsuite/*.log + fi +%endif + + for file in {gas/testsuite/gas,ld/ld,binutils/binutils}.{sum,log} + do + if [ -f $file ]; then + ln $file binutils-$target-$(basename $file) || : + fi + done + + tar cjf binutils-$target.tar.xz binutils-$target-*.{sum,log} + uuencode binutils-$target.tar.xz binutils-$target.tar.xz + rm -f binutils-$target.tar.xz binutils-$target-*.{sum,log} + +%if %{with gold} + if [ -f gold/testsuite/test-suite.log ]; then + tar cjf binutils-$target-gold.log.tar.xz gold/testsuite/*.log + uuencode binutils-$target-gold.log.tar.xz binutils-$target-gold.log.tar.xz + rm -f binutils-$target-gold.log.tar.xz + fi +%endif + + echo ================ $target == TEST RUN 2 ============================= + + # Run the tests and this time fail if there are any errors. + + if test x$native == x1 ; then + make -k check-gas check-binutils check-ld < /dev/null + # Ignore the gold tests - they always fail + else + # Do not try running linking tests for the cross-binutils. + make -k check-gas check-binutils < /dev/null + fi + + popd +} + +#---------------------------------------------------------------------------- + +# There is a problem with the clang+libtool+lto combination. +# The LDFLAGS containing -flto are not being passed when linking the +# libbfd.so, so the build fails. Solution: disable LTO. +%if %{with clang} +%define enable_lto 0 +%endif + +%if %{with clang} +%define _with_cc_clang 1 +%endif + +# Disable LTO on arm due to: +# https://bugzilla.redhat.com/show_bug.cgi?id=1918924 +%ifarch %{arm} +%define enable_lto 0 +%endif + +%if !0%{?enable_lto} +%global _lto_cflags %{nil} +%endif + +compute_global_configuration + +# Build the native configuration. +run_target_configuration %{_target_platform} 1 %{enable_shared} +build_target %{_target_platform} +run_tests %{_target_platform} 1 + +%if %{with crossbuilds} + +# Build the cross configurations. +for f in %{cross_targets}; do + + # Skip the native build. + if test x$f != x%{_target_platform}; then + # We could improve the cross build's size by enabling shared libraries but + # the produced binaries may be less convenient in the embedded environment. + run_target_configuration $f 0 0 + build_target $f + run_tests $f 0 + fi +done + +%endif + +#---------------------------------------------------------------------------- + +%install + +mkdir -p %{buildroot}%{_scl_root}/etc/alternatives %{buildroot}%{_scl_root}/var/lib/alternatives +# install_binutils() +# Install the binutils. +# $1 is the target architecture +# $2 is 1 if this is a native build +# $3 is 1 if shared libraries should be built +# +install_binutils() +{ + local target="$1" + local native="$2" + local shared="$3" + + local local_root=%{buildroot}/%{_prefix} + local local_bindir=$local_root/bin + local local_libdir=%{buildroot}%{_libdir} + local local_mandir=$local_root/share/man/man1 + local local_incdir=$local_root/include + local local_infodir=$local_root/share/info + local local_libdir + + mkdir -p $local_libdir + mkdir -p $local_incdir + mkdir -p $local_mandir + mkdir -p $local_infodir + + echo "INSTALLING the binutils FOR TARGET $target (native ? $native) (shared ? $shared)" + + pushd build-$target + + if test x$native == x1 ; then + +%if %{with docs} + %make_install DESTDIR=%{buildroot} + make prefix=%{buildroot}%{_prefix} infodir=$local_infodir install-info +%else + %make_install DESTDIR=%{buildroot} MAKEINFO=true +%endif + + # Rebuild the static libiaries with -fPIC. + # It would be nice to build the static libraries with -fno-lto so that + # they can be used by programs that are built with a different version + # of GCC from the one used to build the libraries, but this will trigger + # warnings from annocheck. + + # Future: Remove libiberty together with its header file, projects should bundle it. + %make_build -s -C libiberty clean + %set_build_flags + %make_build -s CFLAGS="-g -fPIC $RPM_OPT_FLAGS" -C libiberty + + # Without the hidden visibility the 3rd party shared libraries would export + # the bfd non-stable ABI. + %make_build -s -C bfd clean + %set_build_flags + %make_build -s CFLAGS="-g -fPIC $RPM_OPT_FLAGS -fvisibility=hidden" -C bfd + + %make_build -s -C opcodes clean + %set_build_flags + %make_build -s CFLAGS="-g -fPIC $RPM_OPT_FLAGS" -C opcodes + + %make_build -s -C libsframe clean + %set_build_flags + %make_build -s CFLAGS="-g -fPIC $RPM_OPT_FLAGS" -C libsframe + + install -m 644 bfd/.libs/libbfd.a $local_libdir + install -m 644 libiberty/libiberty.a $local_libdir + install -m 644 ../include/libiberty.h $local_incdir + install -m 644 opcodes/.libs/libopcodes.a $local_libdir + install -m 644 libsframe/.libs/libsframe.a $local_libdir + + # Remove Windows/Novell only man pages + rm -f $local_mandir/{dlltool,nlmconv,windres,windmc}* +%if %{without docs} + rm -f $local_mandir/{addr2line,ar,as,c++filt,elfedit,gprof,ld,nm,objcopy,objdump,ranlib,readelf,size,strings,strip}* + rm -f $local_infodir/{as,bfd,binutils,gprof,ld}* +%endif + +%if %{enable_shared} + chmod +x $local_libdir/lib*.so* + chrpath -d $local_libdir/lib*.so* + chmod +x $local_bindir/* + chrpath -d $local_bindir/* +%endif + + # Prevent programs from linking against libbfd and libopcodes + # dynamically, as they are changed far too often. + rm -f $local_libdir/lib{bfd,opcodes}.so + + # Remove libtool files, which reference the .so libs + rm -f %local_libdir/lib{bfd,opcodes}.la + + # Sanity check --enable-64-bit-bfd really works. + grep '^#define BFD_ARCH_SIZE 64$' $local_incdir/bfd.h + # Fix multilib conflicts of generated values by __WORDSIZE-based expressions. +%ifarch %{ix86} x86_64 ppc %{power64} s390 s390x sh3 sh4 sparc sparc64 arm + sed -i -e '/^#include "ansidecl.h"/{p;s~^.*$~#include ~;}' \ + -e 's/^#define BFD_DEFAULT_TARGET_SIZE \(32\|64\) *$/#define BFD_DEFAULT_TARGET_SIZE __WORDSIZE/' \ + -e 's/^#define BFD_HOST_64BIT_LONG [01] *$/#define BFD_HOST_64BIT_LONG (__WORDSIZE == 64)/' \ + -e 's/^#define BFD_HOST_64_BIT \(long \)\?long *$/#if __WORDSIZE == 32\ +#define BFD_HOST_64_BIT long long\ +#else\ +#define BFD_HOST_64_BIT long\ +#endif/' \ + -e 's/^#define BFD_HOST_U_64_BIT unsigned \(long \)\?long *$/#define BFD_HOST_U_64_BIT unsigned BFD_HOST_64_BIT/' \ + $local_incdir/bfd.h +%endif + + touch -r ../bfd/bfd-in2.h $local_incdir/bfd.h + + # Generate .so linker scripts for dependencies; imported from glibc/Makerules: + + # This fragment of linker script gives the OUTPUT_FORMAT statement + # for the configuration we are building. + OUTPUT_FORMAT="\ +/* Ensure this .so library will not be used by a link for a different format + on a multi-architecture system. */ +$(gcc $CFLAGS $LDFLAGS -shared -x c /dev/null -o /dev/null -Wl,--verbose -v 2>&1 | sed -n -f "%{SOURCE2}")" + + tee $local_libdir/libbfd.so <> binutils.lang + cat bfd.lang >> binutils.lang + cat gas.lang >> binutils.lang + cat gprof.lang >> binutils.lang + + if [ -x ld/ld-new ]; then + %find_lang ld + cat ld.lang >> binutils.lang + fi + + if [ -x gold/ld-new ]; then + %find_lang gold + cat gold.lang >> binutils.lang + fi + + popd +} + +#---------------------------------------------------------------------------- + +install_binutils %{_target_platform} 1 %{enable_shared} + +%if %{with crossbuilds} + +for f in %{cross_targets}; do + if test x$f != x%{_target_platform}; then + install_binutils $f 0 0 + fi +done + +%endif + +# Stop check-rpaths from complaining about standard runpaths. +export QA_RPATHS=0x0003 + +#---------------------------------------------------------------------------- + +%if %{with gold} +%post -n %{?_scl_prefix}binutils-gold%{binutils_ver} + +%{alternatives_cmdline} --install %{_bindir}/ld ld \ + %{_bindir}/ld.gold %{ld_gold_priority} +exit 0 +%endif + +%post + +# Remove the /usr/bin/ld file so that the alternatives program +# can replace it with a symbolic link. +%__rm -f %{_bindir}/ld +%{alternatives_cmdline} --install %{_bindir}/ld ld \ + %{_bindir}/ld.bfd %{ld_bfd_priority} + +# Do not run "alternatives --auto ld" here. Leave the setting to +# however the user previously had it set. See BZ 1592069 for more details. + +%ldconfig_post + +exit 0 + +#---------------------------------------------------------------------------- + +# Note: $1 == 0 means that there is an uninstall in progress. +# $1 == 1 means that there is an upgrade in progress. + +%if %{with gold} +%preun -n %{?_scl_prefix}binutils-gold%{binutils_ver} +if [ $1 = 0 ]; then + %{alternatives_cmdline} --remove ld %{_bindir}/ld.gold +fi +exit 0 +%endif + +%preun +if [ $1 = 0 ]; then + %{alternatives_cmdline} --remove ld %{_bindir}/ld.bfd +fi +touch %{_bindir}/ld +exit 0 + +#---------------------------------------------------------------------------- + +%postun +%ldconfig_postun + +#---------------------------------------------------------------------------- + +%files -f build-%{_target_platform}/binutils.lang +%dir %{_scl_root}/etc/alternatives +%dir %{_scl_root}/var/lib/alternatives + +%if %{with crossbuilds} +%if "%{_target_platform}" != "aarch64-%{system}" +%exclude /usr/aarch64-%{system}/* +%exclude /usr/bin/aarch64-%{system}-* +%endif + +%if "%{_target_platform}" != "ppc64le-%{system}" +%exclude /usr/ppc64le-%{system}/* +%exclude /usr/bin/ppc64le-%{system}-* +%endif + +%if "%{_target_platform}" != "s390x-%{system}" +%exclude /usr/s390x-%{system}/* +%exclude /usr/bin/s390x-%{system}-* +%endif + +%if "%{_target_platform}" != "x86_64-%{system}" +%exclude /usr/x86_64-%{system}/* +%exclude /usr/bin/x86_64-%{system}-* +%endif +%endif + +%{_bindir}/[!l]* +# %%verify(symlink) does not work for some reason, so using "owner" instead. +%verify(owner) %{_bindir}/ld +%{_bindir}/ld.bfd +%{_libdir}/*\.la +%if %{with gprofng} +%exclude %{_bindir}/gp-* +%exclude %{_bindir}/gprofng +%endif + +%if %{with docs} +%{_mandir}/man1/ +%exclude %{_mandir}/man1/gp* + +%{_infodir}/as.info* +%{_infodir}/binutils.info* +%{_infodir}/ld.info* +%{_infodir}/ldint.info* +%{_infodir}/bfd.info* +%{_infodir}/ctf-spec.info* +%{_infodir}/gprof.info* +%{_infodir}/sframe-spec.info* + +%if %{with gprofng} +%exclude %{_infodir}/gprofng* +%endif +%endif + +%if %{enable_shared} +%{_libdir}/lib*.so +%{_libdir}/lib*.so.* +%exclude %{_libdir}/libbfd.so +%exclude %{_libdir}/libopcodes.so +%exclude %{_libdir}/libctf.a +%exclude %{_libdir}/libctf-nobfd.a + +%dir %{_libdir}/bfd-plugins +%{_libdir}/bfd-plugins/libdep.so +%endif + +%if %{with debug} +%dir %{_libdir}/bfd-plugins +%{_libdir}/bfd-plugins/libdep.a +%endif + +%files -n %{?_scl_prefix}binutils-devel%{binutils_ver} +%{_prefix}/include/* +%{_libdir}/lib*.a +%{_libdir}/libbfd.so +%{_libdir}/libopcodes.so +%exclude %{_libdir}/lib*.la + +%if %{with gold} +%files -n %{?_scl_prefix}binutils-gold%{binutils_ver} +%{_bindir}/%{?cross}ld.gold +%endif + +%if %{with gprofng} +%files -n %{?_scl_prefix}gprofng%{binutils_ver} +%{_bindir}/gp-* +%{_bindir}/gprofng +%{_mandir}/man1/gp-* +%{_mandir}/man1/gprofng* +%{_infodir}/gprofng.info.* +%dir %{_libdir}/gprofng +%{_libdir}/gprofng/* +%{_prefix}/usr/gprofng.rc +%endif + +%if %{with crossbuilds} + +%if "%{_target_platform}" != "aarch64-%{system}" +%files -n %{?_scl_prefix}cross-binutils-aarch64%{binutils_ver} +/usr/aarch64-%{system}/ +/usr/bin/aarch64-%{system}-* +%endif + +%if "%{_target_platform}" != "ppc64le-%{system}" +%files -n %{?_scl_prefix}cross-binutils-ppc64le%{binutils_ver} +/usr/ppc64le-%{system}/ +/usr/bin/ppc64le-%{system}-* +%endif + +%if "%{_target_platform}" != "s390x-%{system}" +%files -n %{?_scl_prefix}cross-binutils-s390x%{binutils_ver} +/usr/s390x-%{system}/ +/usr/bin/s390x-%{system}-* +%endif + +%if "%{_target_platform}" != "x86_64-%{system}" +%files -n %{?_scl_prefix}cross-binutils-x86_64%{binutils_ver} +/usr/x86_64-%{system}/ +/usr/bin/x86_64-%{system}-* +%endif + +%endif + +#---------------------------------------------------------------------------- +%changelog +* Wed Jul 02 2025 zhangenpei - 2.42-3 +- Backport RVA23U64 mandatory extensions. + +* Wed May 28 2025 Hu,Lin - 2.42-2 +- Fix relocation issue for APX. + +* Thu Aug 15 2024 zhaoshujian - 2.42-1 +- Init binutils 2.42 +- Reference: https://gitlab.com/redhat/centos-stream/rpms/binutils + diff --git a/binutils-2.42.tar.xz b/binutils-2.42.tar.xz new file mode 100644 index 0000000000000000000000000000000000000000..810591acb51f4d37afd460e179a80dcfbb78fcc8 Binary files /dev/null and b/binutils-2.42.tar.xz differ diff --git a/binutils-2.44-backport-RISC-V-Add-platform-property-capability-extensions.patch b/binutils-2.44-backport-RISC-V-Add-platform-property-capability-extensions.patch new file mode 100644 index 0000000000000000000000000000000000000000..4976c6e8562a5db15305c9489d4f27690c3e2799 --- /dev/null +++ b/binutils-2.44-backport-RISC-V-Add-platform-property-capability-extensions.patch @@ -0,0 +1,83 @@ +diff -rup binutils.orig/bfd/elfxx-riscv.c binutils-2.42/bfd/elfxx-riscv.c +--- binutils.orig/bfd/elfxx-riscv.c 2025-07-01 10:16:05.889931463 +0800 ++++ binutils-2.42/bfd/elfxx-riscv.c 2025-07-01 10:16:55.803095052 +0800 +@@ -1113,6 +1113,12 @@ static struct riscv_implicit_subset risc + {"g", "zicsr", check_implicit_always}, + {"g", "zifencei", check_implicit_always}, + {"m", "zmmul", check_implicit_always}, ++ {"shcounterenw", "h", check_implicit_always}, ++ {"shgatpa", "h", check_implicit_always}, ++ {"shtvala", "h", check_implicit_always}, ++ {"shvsatpa", "h", check_implicit_always}, ++ {"shvstvala", "h", check_implicit_always}, ++ {"shvstvecd", "h", check_implicit_always}, + {"h", "zicsr", check_implicit_always}, + {"q", "d", check_implicit_always}, + {"v", "d", check_implicit_always}, +@@ -1199,9 +1205,16 @@ static struct riscv_implicit_subset risc + {"smepmp", "zicsr", check_implicit_always}, + {"ssaia", "zicsr", check_implicit_always}, + {"sscofpmf", "zicsr", check_implicit_always}, ++ {"sscounterenw", "zicsr", check_implicit_always}, + {"ssstateen", "zicsr", check_implicit_always}, + {"sstc", "zicsr", check_implicit_always}, ++ {"sstvala", "zicsr", check_implicit_always}, ++ {"sstvecd", "zicsr", check_implicit_always}, ++ {"ssu64xl", "zicsr", check_implicit_always}, ++ ++ {"svade", "zicsr", check_implicit_always}, + {"svadu", "zicsr", check_implicit_always}, ++ {"svbare", "zicsr", check_implicit_always}, + + {"xsfvcp", "zve32x", check_implicit_always}, + {NULL, NULL, NULL} +@@ -1261,6 +1274,11 @@ static struct riscv_supported_ext riscv_ + + static struct riscv_supported_ext riscv_supported_std_z_ext[] = + { ++ {"zic64b", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"ziccamoa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"ziccif", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"zicclsm", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"ziccrse", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zicbom", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zicbop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zicboz", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, +@@ -1274,6 +1292,8 @@ static struct riscv_supported_ext riscv_ + {"zihintpause", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, + {"zihpm", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, + {"zmmul", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"za64rs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"za128rs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zawrs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zfa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zfh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, +@@ -1345,15 +1365,28 @@ static struct riscv_supported_ext riscv_ + + static struct riscv_supported_ext riscv_supported_std_s_ext[] = + { ++ {"shcounterenw", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"shgatpa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"shtvala", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"shvsatpa", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"shvstvala", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"shvstvecd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"smaia", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"smcntrpmf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"smepmp", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"smstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"ssaia", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"ssccptr", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"sscofpmf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"sscounterenw", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"ssstateen", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"sstc", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"sstvala", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"sstvecd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"ssu64xl", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"svade", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"svadu", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"svbare", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"svinval", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"svnapot", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"svpbmt", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, diff --git a/binutils-2.44-backport-RISC-V-Add-support-for-Zcmop-extension.patch b/binutils-2.44-backport-RISC-V-Add-support-for-Zcmop-extension.patch new file mode 100644 index 0000000000000000000000000000000000000000..5a405d2af8c23b5846711b837e1979ecc55591ea --- /dev/null +++ b/binutils-2.44-backport-RISC-V-Add-support-for-Zcmop-extension.patch @@ -0,0 +1,112 @@ +diff -rup binutils.orig/bfd/elfxx-riscv.c binutils-2.42/bfd/elfxx-riscv.c +--- binutils.orig/bfd/elfxx-riscv.c 2025-07-01 10:28:57.536983487 +0800 ++++ binutils-2.42/bfd/elfxx-riscv.c 2025-07-01 10:29:16.665474728 +0800 +@@ -1113,6 +1113,8 @@ static struct riscv_implicit_subset risc + {"g", "zicsr", check_implicit_always}, + {"g", "zifencei", check_implicit_always}, + {"m", "zmmul", check_implicit_always}, ++ {"zcmop", "zca", check_implicit_always}, ++ + {"shcounterenw", "h", check_implicit_always}, + {"shgatpa", "h", check_implicit_always}, + {"shtvala", "h", check_implicit_always}, +@@ -1361,6 +1363,7 @@ static struct riscv_supported_ext riscv_ + {"zcb", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zcf", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zcd", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, ++ {"zcmop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {NULL, 0, 0, 0, 0} + }; + +@@ -2604,6 +2607,8 @@ riscv_multi_subset_supports (riscv_parse + case INSN_CLASS_ZCB_AND_ZMMUL: + return (riscv_subset_supports (rps, "zcb") + && riscv_subset_supports (rps, "zmmul")); ++ case INSN_CLASS_ZCMOP: ++ return riscv_subset_supports (rps, "zcmop"); + case INSN_CLASS_SVINVAL: + return riscv_subset_supports (rps, "svinval"); + case INSN_CLASS_H: +@@ -2858,6 +2863,8 @@ riscv_multi_subset_supports_ext (riscv_p + return _("zcb' and `zbb"); + case INSN_CLASS_ZCB_AND_ZMMUL: + return _("zcb' and `zmmul', or `zcb' and `m"); ++ case INSN_CLASS_ZCMOP: ++ return "zcmop"; + case INSN_CLASS_SVINVAL: + return "svinval"; + case INSN_CLASS_H: +diff -rup binutils.orig/include/opcode/riscv.h binutils-2.42/include/opcode/riscv.h +--- binutils.orig/include/opcode/riscv.h 2025-07-01 10:29:00.552376203 +0800 ++++ binutils-2.42/include/opcode/riscv.h 2025-07-01 10:29:16.669475249 +0800 +@@ -465,6 +465,7 @@ enum riscv_insn_class + INSN_CLASS_ZCB_AND_ZBA, + INSN_CLASS_ZCB_AND_ZBB, + INSN_CLASS_ZCB_AND_ZMMUL, ++ INSN_CLASS_ZCMOP, + INSN_CLASS_SVINVAL, + INSN_CLASS_ZICBOM, + INSN_CLASS_ZICBOP, +diff -rup binutils.orig/include/opcode/riscv-opc.h binutils-2.42/include/opcode/riscv-opc.h +--- binutils.orig/include/opcode/riscv-opc.h 2025-07-01 10:29:00.551376073 +0800 ++++ binutils-2.42/include/opcode/riscv-opc.h 2025-07-01 10:29:16.668475119 +0800 +@@ -2235,6 +2235,23 @@ + #define MASK_C_NOT 0xfc7f + #define MATCH_C_MUL 0x9c41 + #define MASK_C_MUL 0xfc63 ++/* Zcmop instructions. */ ++#define MATCH_C_MOP_1 0x6081 ++#define MASK_C_MOP_1 0xffff ++#define MATCH_C_MOP_3 0x6181 ++#define MASK_C_MOP_3 0xffff ++#define MATCH_C_MOP_5 0x6281 ++#define MASK_C_MOP_5 0xffff ++#define MATCH_C_MOP_7 0x6381 ++#define MASK_C_MOP_7 0xffff ++#define MATCH_C_MOP_9 0x6481 ++#define MASK_C_MOP_9 0xffff ++#define MATCH_C_MOP_11 0x6581 ++#define MASK_C_MOP_11 0xffff ++#define MATCH_C_MOP_13 0x6681 ++#define MASK_C_MOP_13 0xffff ++#define MATCH_C_MOP_15 0x6781 ++#define MASK_C_MOP_15 0xffff + /* Svinval instruction. */ + #define MATCH_SINVAL_VMA 0x16000073 + #define MASK_SINVAL_VMA 0xfe007fff +@@ -4038,6 +4055,15 @@ DECLARE_INSN(c_lhu, MATCH_C_LHU, MASK_C_ + DECLARE_INSN(c_lh, MATCH_C_LH, MASK_C_LH) + DECLARE_INSN(c_sb, MATCH_C_SB, MASK_C_SB) + DECLARE_INSN(c_sh, MATCH_C_SH, MASK_C_SH) ++/* Zcmop instructions. */ ++DECLARE_INSN(c_mop_1, MATCH_C_MOP_1, MASK_C_MOP_1) ++DECLARE_INSN(c_mop_3, MATCH_C_MOP_3, MASK_C_MOP_3) ++DECLARE_INSN(c_mop_5, MATCH_C_MOP_5, MASK_C_MOP_5) ++DECLARE_INSN(c_mop_7, MATCH_C_MOP_7, MASK_C_MOP_7) ++DECLARE_INSN(c_mop_9, MATCH_C_MOP_9, MASK_C_MOP_9) ++DECLARE_INSN(c_mop_11, MATCH_C_MOP_11, MASK_C_MOP_11) ++DECLARE_INSN(c_mop_13, MATCH_C_MOP_13, MASK_C_MOP_13) ++DECLARE_INSN(c_mop_15, MATCH_C_MOP_15, MASK_C_MOP_15) + /* Vendor-specific (T-Head) XTheadBa instructions. */ + DECLARE_INSN(th_addsl, MATCH_TH_ADDSL, MASK_TH_ADDSL) + /* Vendor-specific (T-Head) XTheadBb instructions. */ +diff -rup binutils.orig/opcodes/riscv-opc.c binutils-2.42/opcodes/riscv-opc.c +--- binutils.orig/opcodes/riscv-opc.c 2025-07-01 10:29:02.563638145 +0800 ++++ binutils-2.42/opcodes/riscv-opc.c 2025-07-01 10:29:16.669475249 +0800 +@@ -2035,6 +2035,16 @@ const struct riscv_opcode riscv_opcodes[ + {"c.zext.b", 0, INSN_CLASS_ZCB, "Cs", MATCH_C_ZEXT_B, MASK_C_ZEXT_B, match_opcode, 0 }, + {"c.sext.w", 64, INSN_CLASS_ZCB, "d", MATCH_C_ADDIW, MASK_C_ADDIW|MASK_RVC_IMM, match_rd_nonzero, INSN_ALIAS }, + ++/* Zcmop instructions. */ ++{"c.mop.1", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_1, MASK_C_MOP_1, match_opcode, 0 }, ++{"c.mop.3", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_3, MASK_C_MOP_3, match_opcode, 0 }, ++{"c.mop.5", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_5, MASK_C_MOP_5, match_opcode, 0 }, ++{"c.mop.7", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_7, MASK_C_MOP_7, match_opcode, 0 }, ++{"c.mop.9", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_9, MASK_C_MOP_9, match_opcode, 0 }, ++{"c.mop.11", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_11, MASK_C_MOP_11, match_opcode, 0 }, ++{"c.mop.13", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_13, MASK_C_MOP_13, match_opcode, 0 }, ++{"c.mop.15", 0, INSN_CLASS_ZCMOP, "", MATCH_C_MOP_15, MASK_C_MOP_15, match_opcode, 0 }, ++ + /* Supervisor instructions. */ + {"csrr", 0, INSN_CLASS_ZICSR, "d,E", MATCH_CSRRS, MASK_CSRRS|MASK_RS1, match_opcode, INSN_ALIAS }, + {"csrwi", 0, INSN_CLASS_ZICSR, "E,Z", MATCH_CSRRWI, MASK_CSRRWI|MASK_RD, match_opcode, INSN_ALIAS }, diff --git a/binutils-2.44-backport-RISC-V-Add-support-for-Zimop-extension.patch b/binutils-2.44-backport-RISC-V-Add-support-for-Zimop-extension.patch new file mode 100644 index 0000000000000000000000000000000000000000..83d49b0c52293f098cc80affd6f10bc81497e6e9 --- /dev/null +++ b/binutils-2.44-backport-RISC-V-Add-support-for-Zimop-extension.patch @@ -0,0 +1,231 @@ +diff -rup binutils.orig/bfd/elfxx-riscv.c binutils-2.42/bfd/elfxx-riscv.c +--- binutils.orig/bfd/elfxx-riscv.c 2025-07-01 10:21:19.489412455 +0800 ++++ binutils-2.42/bfd/elfxx-riscv.c 2025-07-01 10:21:39.880067385 +0800 +@@ -1291,6 +1291,7 @@ static struct riscv_supported_ext riscv_ + {"zihintntl", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zihintpause", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, + {"zihpm", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 }, ++ {"zimop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"zmmul", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"za64rs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, + {"za128rs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 }, +@@ -2464,6 +2465,8 @@ riscv_multi_subset_supports (riscv_parse + || riscv_subset_supports (rps, "zca"))); + case INSN_CLASS_ZIHINTPAUSE: + return riscv_subset_supports (rps, "zihintpause"); ++ case INSN_CLASS_ZIMOP: ++ return riscv_subset_supports (rps, "zimop"); + case INSN_CLASS_M: + return riscv_subset_supports (rps, "m"); + case INSN_CLASS_ZMMUL: +@@ -2686,6 +2689,8 @@ riscv_multi_subset_supports_ext (riscv_p + return _("c' or `zca"); + case INSN_CLASS_ZIHINTPAUSE: + return "zihintpause"; ++ case INSN_CLASS_ZIMOP: ++ return "zimop"; + case INSN_CLASS_M: + return "m"; + case INSN_CLASS_ZMMUL: +diff -rup binutils.orig/include/opcode/riscv.h binutils-2.42/include/opcode/riscv.h +--- binutils.orig/include/opcode/riscv.h 2025-07-01 10:21:21.698591754 +0800 ++++ binutils-2.42/include/opcode/riscv.h 2025-07-01 10:21:39.882067547 +0800 +@@ -420,6 +420,7 @@ enum riscv_insn_class + INSN_CLASS_ZIHINTNTL, + INSN_CLASS_ZIHINTNTL_AND_C, + INSN_CLASS_ZIHINTPAUSE, ++ INSN_CLASS_ZIMOP, + INSN_CLASS_ZMMUL, + INSN_CLASS_ZAWRS, + INSN_CLASS_F_INX, +diff -rup binutils.orig/include/opcode/riscv-opc.h binutils-2.42/include/opcode/riscv-opc.h +--- binutils.orig/include/opcode/riscv-opc.h 2025-07-01 10:21:21.698591754 +0800 ++++ binutils-2.42/include/opcode/riscv-opc.h 2025-07-01 10:21:39.882067547 +0800 +@@ -2315,6 +2315,87 @@ + #define MASK_C_NTL_S1 0xffff + #define MATCH_C_NTL_ALL 0x9016 + #define MASK_C_NTL_ALL 0xffff ++/* Zimop instructions. */ ++#define MATCH_MOP_R_0 0x81c04073 ++#define MASK_MOP_R_0 0xfff0707f ++#define MATCH_MOP_R_1 0x81d04073 ++#define MASK_MOP_R_1 0xfff0707f ++#define MATCH_MOP_R_2 0x81e04073 ++#define MASK_MOP_R_2 0xfff0707f ++#define MATCH_MOP_R_3 0x81f04073 ++#define MASK_MOP_R_3 0xfff0707f ++#define MATCH_MOP_R_4 0x85c04073 ++#define MASK_MOP_R_4 0xfff0707f ++#define MATCH_MOP_R_5 0x85d04073 ++#define MASK_MOP_R_5 0xfff0707f ++#define MATCH_MOP_R_6 0x85e04073 ++#define MASK_MOP_R_6 0xfff0707f ++#define MATCH_MOP_R_7 0x85f04073 ++#define MASK_MOP_R_7 0xfff0707f ++#define MATCH_MOP_R_8 0x89c04073 ++#define MASK_MOP_R_8 0xfff0707f ++#define MATCH_MOP_R_9 0x89d04073 ++#define MASK_MOP_R_9 0xfff0707f ++#define MATCH_MOP_R_10 0x89e04073 ++#define MASK_MOP_R_10 0xfff0707f ++#define MATCH_MOP_R_11 0x89f04073 ++#define MASK_MOP_R_11 0xfff0707f ++#define MATCH_MOP_R_12 0x8dc04073 ++#define MASK_MOP_R_12 0xfff0707f ++#define MATCH_MOP_R_13 0x8dd04073 ++#define MASK_MOP_R_13 0xfff0707f ++#define MATCH_MOP_R_14 0x8de04073 ++#define MASK_MOP_R_14 0xfff0707f ++#define MATCH_MOP_R_15 0x8df04073 ++#define MASK_MOP_R_15 0xfff0707f ++#define MATCH_MOP_R_16 0xc1c04073 ++#define MASK_MOP_R_16 0xfff0707f ++#define MATCH_MOP_R_17 0xc1d04073 ++#define MASK_MOP_R_17 0xfff0707f ++#define MATCH_MOP_R_18 0xc1e04073 ++#define MASK_MOP_R_18 0xfff0707f ++#define MATCH_MOP_R_19 0xc1f04073 ++#define MASK_MOP_R_19 0xfff0707f ++#define MATCH_MOP_R_20 0xc5c04073 ++#define MASK_MOP_R_20 0xfff0707f ++#define MATCH_MOP_R_21 0xc5d04073 ++#define MASK_MOP_R_21 0xfff0707f ++#define MATCH_MOP_R_22 0xc5e04073 ++#define MASK_MOP_R_22 0xfff0707f ++#define MATCH_MOP_R_23 0xc5f04073 ++#define MASK_MOP_R_23 0xfff0707f ++#define MATCH_MOP_R_24 0xc9c04073 ++#define MASK_MOP_R_24 0xfff0707f ++#define MATCH_MOP_R_25 0xc9d04073 ++#define MASK_MOP_R_25 0xfff0707f ++#define MATCH_MOP_R_26 0xc9e04073 ++#define MASK_MOP_R_26 0xfff0707f ++#define MATCH_MOP_R_27 0xc9f04073 ++#define MASK_MOP_R_27 0xfff0707f ++#define MATCH_MOP_R_28 0xcdc04073 ++#define MASK_MOP_R_28 0xfff0707f ++#define MATCH_MOP_R_29 0xcdd04073 ++#define MASK_MOP_R_29 0xfff0707f ++#define MATCH_MOP_R_30 0xcde04073 ++#define MASK_MOP_R_30 0xfff0707f ++#define MATCH_MOP_R_31 0xcdf04073 ++#define MASK_MOP_R_31 0xfff0707f ++#define MATCH_MOP_RR_0 0x82004073 ++#define MASK_MOP_RR_0 0xfe00707f ++#define MATCH_MOP_RR_1 0x86004073 ++#define MASK_MOP_RR_1 0xfe00707f ++#define MATCH_MOP_RR_2 0x8a004073 ++#define MASK_MOP_RR_2 0xfe00707f ++#define MATCH_MOP_RR_3 0x8e004073 ++#define MASK_MOP_RR_3 0xfe00707f ++#define MATCH_MOP_RR_4 0xc2004073 ++#define MASK_MOP_RR_4 0xfe00707f ++#define MATCH_MOP_RR_5 0xc6004073 ++#define MASK_MOP_RR_5 0xfe00707f ++#define MATCH_MOP_RR_6 0xca004073 ++#define MASK_MOP_RR_6 0xfe00707f ++#define MATCH_MOP_RR_7 0xce004073 ++#define MASK_MOP_RR_7 0xfe00707f + /* Zawrs instructions. */ + #define MATCH_WRS_NTO 0x00d00073 + #define MASK_WRS_NTO 0xffffffff +@@ -3852,6 +3933,47 @@ DECLARE_INSN(c_ntl_p1, MATCH_C_NTL_P1, M + DECLARE_INSN(c_ntl_pall, MATCH_C_NTL_PALL, MASK_C_NTL_PALL) + DECLARE_INSN(c_ntl_s1, MATCH_C_NTL_S1, MASK_C_NTL_S1) + DECLARE_INSN(c_ntl_all, MATCH_C_NTL_ALL, MASK_C_NTL_ALL) ++/* Zimop instructions. */ ++DECLARE_INSN(MOP_R_0, MATCH_MOP_R_0, MASK_MOP_R_0) ++DECLARE_INSN(MOP_R_1, MATCH_MOP_R_1, MASK_MOP_R_1) ++DECLARE_INSN(MOP_R_2, MATCH_MOP_R_2, MASK_MOP_R_2) ++DECLARE_INSN(MOP_R_3, MATCH_MOP_R_3, MASK_MOP_R_3) ++DECLARE_INSN(MOP_R_4, MATCH_MOP_R_4, MASK_MOP_R_4) ++DECLARE_INSN(MOP_R_5, MATCH_MOP_R_5, MASK_MOP_R_5) ++DECLARE_INSN(MOP_R_6, MATCH_MOP_R_6, MASK_MOP_R_6) ++DECLARE_INSN(MOP_R_7, MATCH_MOP_R_7, MASK_MOP_R_7) ++DECLARE_INSN(MOP_R_8, MATCH_MOP_R_8, MASK_MOP_R_8) ++DECLARE_INSN(MOP_R_9, MATCH_MOP_R_9, MASK_MOP_R_9) ++DECLARE_INSN(MOP_R_10, MATCH_MOP_R_10, MASK_MOP_R_10) ++DECLARE_INSN(MOP_R_11, MATCH_MOP_R_11, MASK_MOP_R_11) ++DECLARE_INSN(MOP_R_12, MATCH_MOP_R_12, MASK_MOP_R_12) ++DECLARE_INSN(MOP_R_13, MATCH_MOP_R_13, MASK_MOP_R_13) ++DECLARE_INSN(MOP_R_14, MATCH_MOP_R_14, MASK_MOP_R_14) ++DECLARE_INSN(MOP_R_15, MATCH_MOP_R_15, MASK_MOP_R_15) ++DECLARE_INSN(MOP_R_16, MATCH_MOP_R_16, MASK_MOP_R_16) ++DECLARE_INSN(MOP_R_17, MATCH_MOP_R_17, MASK_MOP_R_17) ++DECLARE_INSN(MOP_R_18, MATCH_MOP_R_18, MASK_MOP_R_18) ++DECLARE_INSN(MOP_R_19, MATCH_MOP_R_19, MASK_MOP_R_19) ++DECLARE_INSN(MOP_R_20, MATCH_MOP_R_20, MASK_MOP_R_20) ++DECLARE_INSN(MOP_R_21, MATCH_MOP_R_21, MASK_MOP_R_21) ++DECLARE_INSN(MOP_R_22, MATCH_MOP_R_22, MASK_MOP_R_22) ++DECLARE_INSN(MOP_R_23, MATCH_MOP_R_23, MASK_MOP_R_23) ++DECLARE_INSN(MOP_R_24, MATCH_MOP_R_24, MASK_MOP_R_24) ++DECLARE_INSN(MOP_R_25, MATCH_MOP_R_25, MASK_MOP_R_25) ++DECLARE_INSN(MOP_R_26, MATCH_MOP_R_26, MASK_MOP_R_26) ++DECLARE_INSN(MOP_R_27, MATCH_MOP_R_27, MASK_MOP_R_27) ++DECLARE_INSN(MOP_R_28, MATCH_MOP_R_28, MASK_MOP_R_28) ++DECLARE_INSN(MOP_R_29, MATCH_MOP_R_29, MASK_MOP_R_29) ++DECLARE_INSN(MOP_R_30, MATCH_MOP_R_30, MASK_MOP_R_30) ++DECLARE_INSN(MOP_R_31, MATCH_MOP_R_31, MASK_MOP_R_31) ++DECLARE_INSN(MOP_RR_0, MATCH_MOP_RR_0, MASK_MOP_RR_0) ++DECLARE_INSN(MOP_RR_1, MATCH_MOP_RR_1, MASK_MOP_RR_1) ++DECLARE_INSN(MOP_RR_2, MATCH_MOP_RR_2, MASK_MOP_RR_2) ++DECLARE_INSN(MOP_RR_3, MATCH_MOP_RR_3, MASK_MOP_RR_3) ++DECLARE_INSN(MOP_RR_4, MATCH_MOP_RR_4, MASK_MOP_RR_4) ++DECLARE_INSN(MOP_RR_5, MATCH_MOP_RR_5, MASK_MOP_RR_5) ++DECLARE_INSN(MOP_RR_6, MATCH_MOP_RR_6, MASK_MOP_RR_6) ++DECLARE_INSN(MOP_RR_7, MATCH_MOP_RR_7, MASK_MOP_RR_7) + /* Zawrs instructions. */ + DECLARE_INSN(wrs_nto, MATCH_WRS_NTO, MASK_WRS_NTO) + DECLARE_INSN(wrs_sto, MATCH_WRS_STO, MASK_WRS_STO) +diff -rup binutils.orig/opcodes/riscv-opc.c binutils-2.42/opcodes/riscv-opc.c +--- binutils.orig/opcodes/riscv-opc.c 2025-07-01 10:21:23.053701737 +0800 ++++ binutils-2.42/opcodes/riscv-opc.c 2025-07-01 10:21:39.884067709 +0800 +@@ -996,6 +996,48 @@ const struct riscv_opcode riscv_opcodes[ + {"czero.eqz", 0, INSN_CLASS_ZICOND, "d,s,t", MATCH_CZERO_EQZ, MASK_CZERO_EQZ, match_opcode, 0 }, + {"czero.nez", 0, INSN_CLASS_ZICOND, "d,s,t", MATCH_CZERO_NEZ, MASK_CZERO_NEZ, match_opcode, 0 }, + ++/* Zimop instructions. */ ++{"mop.r.0", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_0, MASK_MOP_R_0, match_opcode, 0 }, ++{"mop.r.1", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_1, MASK_MOP_R_1, match_opcode, 0 }, ++{"mop.r.2", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_2, MASK_MOP_R_2, match_opcode, 0 }, ++{"mop.r.3", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_3, MASK_MOP_R_3, match_opcode, 0 }, ++{"mop.r.4", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_4, MASK_MOP_R_4, match_opcode, 0 }, ++{"mop.r.5", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_5, MASK_MOP_R_5, match_opcode, 0 }, ++{"mop.r.6", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_6, MASK_MOP_R_6, match_opcode, 0 }, ++{"mop.r.7", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_7, MASK_MOP_R_7, match_opcode, 0 }, ++{"mop.r.8", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_8, MASK_MOP_R_8, match_opcode, 0 }, ++{"mop.r.9", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_9, MASK_MOP_R_9, match_opcode, 0 }, ++{"mop.r.10", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_10, MASK_MOP_R_10, match_opcode, 0 }, ++{"mop.r.11", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_11, MASK_MOP_R_11, match_opcode, 0 }, ++{"mop.r.12", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_12, MASK_MOP_R_12, match_opcode, 0 }, ++{"mop.r.13", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_13, MASK_MOP_R_13, match_opcode, 0 }, ++{"mop.r.14", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_14, MASK_MOP_R_14, match_opcode, 0 }, ++{"mop.r.15", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_15, MASK_MOP_R_15, match_opcode, 0 }, ++{"mop.r.16", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_16, MASK_MOP_R_16, match_opcode, 0 }, ++{"mop.r.17", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_17, MASK_MOP_R_17, match_opcode, 0 }, ++{"mop.r.18", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_18, MASK_MOP_R_18, match_opcode, 0 }, ++{"mop.r.19", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_19, MASK_MOP_R_19, match_opcode, 0 }, ++{"mop.r.20", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_20, MASK_MOP_R_20, match_opcode, 0 }, ++{"mop.r.21", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_21, MASK_MOP_R_21, match_opcode, 0 }, ++{"mop.r.22", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_22, MASK_MOP_R_22, match_opcode, 0 }, ++{"mop.r.23", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_23, MASK_MOP_R_23, match_opcode, 0 }, ++{"mop.r.24", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_24, MASK_MOP_R_24, match_opcode, 0 }, ++{"mop.r.25", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_25, MASK_MOP_R_25, match_opcode, 0 }, ++{"mop.r.26", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_26, MASK_MOP_R_26, match_opcode, 0 }, ++{"mop.r.27", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_27, MASK_MOP_R_27, match_opcode, 0 }, ++{"mop.r.28", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_28, MASK_MOP_R_28, match_opcode, 0 }, ++{"mop.r.29", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_29, MASK_MOP_R_29, match_opcode, 0 }, ++{"mop.r.30", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_30, MASK_MOP_R_30, match_opcode, 0 }, ++{"mop.r.31", 0, INSN_CLASS_ZIMOP, "d,s", MATCH_MOP_R_31, MASK_MOP_R_31, match_opcode, 0 }, ++{"mop.rr.0", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_0, MASK_MOP_RR_0, match_opcode, 0 }, ++{"mop.rr.1", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_1, MASK_MOP_RR_1, match_opcode, 0 }, ++{"mop.rr.2", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_2, MASK_MOP_RR_2, match_opcode, 0 }, ++{"mop.rr.3", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_3, MASK_MOP_RR_3, match_opcode, 0 }, ++{"mop.rr.4", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_4, MASK_MOP_RR_4, match_opcode, 0 }, ++{"mop.rr.5", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_5, MASK_MOP_RR_5, match_opcode, 0 }, ++{"mop.rr.6", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_6, MASK_MOP_RR_6, match_opcode, 0 }, ++{"mop.rr.7", 0, INSN_CLASS_ZIMOP, "d,s,t", MATCH_MOP_RR_7, MASK_MOP_RR_7, match_opcode, 0 }, ++ + /* Zawrs instructions. */ + {"wrs.nto", 0, INSN_CLASS_ZAWRS, "", MATCH_WRS_NTO, MASK_WRS_NTO, match_opcode, 0 }, + {"wrs.sto", 0, INSN_CLASS_ZAWRS, "", MATCH_WRS_STO, MASK_WRS_STO, match_opcode, 0 }, diff --git a/binutils-export-demangle.h.patch b/binutils-export-demangle.h.patch new file mode 100644 index 0000000000000000000000000000000000000000..9716a8bfacaa5fd4e8cffb60f69e37cc614f2e19 --- /dev/null +++ b/binutils-export-demangle.h.patch @@ -0,0 +1,33 @@ +diff -rup binutils.orig/bfd/Makefile.am binutils-2.32/bfd/Makefile.am +--- binutils.orig/bfd/Makefile.am 2019-02-08 12:22:51.395684251 +0000 ++++ binutils-2.32/bfd/Makefile.am 2019-02-08 12:22:53.970664973 +0000 +@@ -33,7 +33,7 @@ bfdlibdir = @bfdlibdir@ + bfdincludedir = @bfdincludedir@ + bfdlib_LTLIBRARIES = libbfd.la + bfdinclude_HEADERS = $(BFD_H) $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \ +- $(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h ++ $(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h $(INCDIR)/demangle.h + else !INSTALL_LIBBFD + # Empty these so that the respective installation directories will not be created. + bfdlibdir = +diff -rup binutils.orig/bfd/Makefile.in binutils-2.32/bfd/Makefile.in +--- binutils.orig/bfd/Makefile.in 2019-02-08 12:21:35.291254044 +0000 ++++ binutils-2.32/bfd/Makefile.in 2019-02-08 12:22:10.163992947 +0000 +@@ -249,7 +249,7 @@ am__can_run_installinfo = \ + esac + am__bfdinclude_HEADERS_DIST = $(INCDIR)/plugin-api.h bfd.h \ + $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \ +- $(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h ++ $(INCDIR)/diagnostics.h $(INCDIR)/bfdlink.h $(INCDIR)/demangle.h + HEADERS = $(bfdinclude_HEADERS) + RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ + distclean-recursive maintainer-clean-recursive +@@ -468,7 +468,7 @@ libbfd_la_LDFLAGS = $(am__append_1) -rel + @INSTALL_LIBBFD_FALSE@bfdinclude_HEADERS = $(am__append_2) + @INSTALL_LIBBFD_TRUE@bfdinclude_HEADERS = $(BFD_H) \ + @INSTALL_LIBBFD_TRUE@ $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h \ +-@INSTALL_LIBBFD_TRUE@ $(INCDIR)/diagnostics.h \ ++@INSTALL_LIBBFD_TRUE@ $(INCDIR)/diagnostics.h $(INCDIR)/demangle.h \ + @INSTALL_LIBBFD_TRUE@ $(INCDIR)/bfdlink.h $(am__append_2) + @INSTALL_LIBBFD_FALSE@rpath_bfdlibdir = @bfdlibdir@ + @INSTALL_LIBBFD_FALSE@noinst_LTLIBRARIES = libbfd.la diff --git a/binutils-gold-empty-dwp.patch b/binutils-gold-empty-dwp.patch new file mode 100644 index 0000000000000000000000000000000000000000..b716565985cffdb534678907617884a5ef8559f5 --- /dev/null +++ b/binutils-gold-empty-dwp.patch @@ -0,0 +1,11 @@ +--- binutils.orig/gold/dwp.cc 2023-05-02 13:26:44.075148082 +0100 ++++ binutils-2.40/gold/dwp.cc 2023-05-02 13:27:16.189130127 +0100 +@@ -2418,6 +2418,8 @@ main(int argc, char** argv) + { + Dwo_file exe_file(exe_filename); + exe_file.read_executable(&files); ++ if (files.empty()) ++ gold_fatal(_("Could not find any dwo links in specified EXE")); + } + + // Add any additional files listed on command line. diff --git a/binutils-gold-mismatched-section-flags.patch b/binutils-gold-mismatched-section-flags.patch new file mode 100644 index 0000000000000000000000000000000000000000..63dba2b4b10949050c3622a8eadcb639d4bb1b9f --- /dev/null +++ b/binutils-gold-mismatched-section-flags.patch @@ -0,0 +1,19 @@ +diff -rup binutils.orig/gold/layout.cc binutils-2.32/gold/layout.cc +--- binutils.orig/gold/layout.cc 2019-06-24 14:37:36.013086899 +0100 ++++ binutils-2.32/gold/layout.cc 2019-06-24 14:41:40.054517479 +0100 +@@ -868,6 +868,7 @@ Layout::get_output_section(const char* n + && (same_name->flags() & elfcpp::SHF_TLS) == 0) + os = same_name; + } ++#if 0 /* BZ 1722715, PR 17556. */ + else if ((flags & elfcpp::SHF_TLS) == 0) + { + elfcpp::Elf_Xword zero_flags = 0; +@@ -878,6 +879,7 @@ Layout::get_output_section(const char* n + if (p != this->section_name_map_.end()) + os = p->second; + } ++#endif + } + + if (os == NULL) diff --git a/binutils-libtool-lib64.patch b/binutils-libtool-lib64.patch new file mode 100644 index 0000000000000000000000000000000000000000..142fc7e27422785c5f5236eca2f6393ee6fdefa0 --- /dev/null +++ b/binutils-libtool-lib64.patch @@ -0,0 +1,236 @@ +diff -rcp ../binutils-2.20.51.0.7.original/bfd/configure ./bfd/configure +--- a/bfd/configure 2010-04-08 14:53:48.000000000 +0100 ++++ b/bfd/configure 2010-04-08 14:56:50.000000000 +0100 +@@ -10762,10 +10762,34 @@ + # before this can be enabled. + hardcode_into_libs=yes + ++ # find out which ABI we are using ++ libsuff= ++ case "$host_cpu" in ++ x86_64*|s390*|powerpc*|ppc*|sparc*) ++ echo 'int i;' > conftest.$ac_ext ++ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ++ (eval $ac_compile) 2>&5 ++ ac_status=$? ++ echo "$as_me:$LINENO: \$? = $ac_status" >&5 ++ (exit $ac_status); }; then ++ case `/usr/bin/file conftest.$ac_objext` in ++ *64-bit*) ++ libsuff=64 ++ if test x"$sys_lib_search_path_spec" = x"/lib /usr/lib /usr/local/lib"; then ++ sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" ++ fi ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff}" ++ ;; ++ esac ++ fi ++ rm -rf conftest* ++ ;; ++ esac ++ + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` +- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on +diff -rcp ../binutils-2.20.51.0.7.original/binutils/configure ./binutils/configure +--- a/binutils/configure 2010-04-08 14:53:45.000000000 +0100 ++++ b/binutils/configure 2010-04-08 14:56:21.000000000 +0100 +@@ -10560,10 +10560,34 @@ + # before this can be enabled. + hardcode_into_libs=yes + ++ # find out which ABI we are using ++ libsuff= ++ case "$host_cpu" in ++ x86_64*|s390*|powerpc*|ppc*|sparc*) ++ echo 'int i;' > conftest.$ac_ext ++ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ++ (eval $ac_compile) 2>&5 ++ ac_status=$? ++ echo "$as_me:$LINENO: \$? = $ac_status" >&5 ++ (exit $ac_status); }; then ++ case `/usr/bin/file conftest.$ac_objext` in ++ *64-bit*) ++ libsuff=64 ++ if test x"$sys_lib_search_path_spec" = x"/lib /usr/lib /usr/local/lib"; then ++ sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" ++ fi ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff}" ++ ;; ++ esac ++ fi ++ rm -rf conftest* ++ ;; ++ esac ++ + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` +- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on +diff -rcp ../binutils-2.20.51.0.7.original/gas/configure ./gas/configure +--- a/gas/configure 2010-04-08 14:53:47.000000000 +0100 ++++ b/gas/configure 2010-04-08 14:57:24.000000000 +0100 +@@ -10547,10 +10547,34 @@ + # before this can be enabled. + hardcode_into_libs=yes + ++ # find out which ABI we are using ++ libsuff= ++ case "$host_cpu" in ++ x86_64*|s390*|powerpc*|ppc*|sparc*) ++ echo 'int i;' > conftest.$ac_ext ++ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ++ (eval $ac_compile) 2>&5 ++ ac_status=$? ++ echo "$as_me:$LINENO: \$? = $ac_status" >&5 ++ (exit $ac_status); }; then ++ case `/usr/bin/file conftest.$ac_objext` in ++ *64-bit*) ++ libsuff=64 ++ if test x"$sys_lib_search_path_spec" = x"/lib /usr/lib /usr/local/lib"; then ++ sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" ++ fi ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff}" ++ ;; ++ esac ++ fi ++ rm -rf conftest* ++ ;; ++ esac ++ + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` +- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on +diff -rcp ../binutils-2.20.51.0.7.original/gprof/configure ./gprof/configure +--- a/gprof/configure 2010-04-08 14:53:45.000000000 +0100 ++++ b/gprof/configure 2010-04-08 14:57:50.000000000 +0100 +@@ -10485,10 +10485,34 @@ + # before this can be enabled. + hardcode_into_libs=yes + ++ # find out which ABI we are using ++ libsuff= ++ case "$host_cpu" in ++ x86_64*|s390*|powerpc*|ppc*|sparc*) ++ echo 'int i;' > conftest.$ac_ext ++ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ++ (eval $ac_compile) 2>&5 ++ ac_status=$? ++ echo "$as_me:$LINENO: \$? = $ac_status" >&5 ++ (exit $ac_status); }; then ++ case `/usr/bin/file conftest.$ac_objext` in ++ *64-bit*) ++ libsuff=64 ++ if test x"$sys_lib_search_path_spec" = x"/lib /usr/lib /usr/local/lib"; then ++ sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" ++ fi ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff}" ++ ;; ++ esac ++ fi ++ rm -rf conftest* ++ ;; ++ esac ++ + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` +- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on +diff -rcp ../binutils-2.20.51.0.7.original/ld/configure ./ld/configure +--- a/ld/configure 2010-04-08 14:53:44.000000000 +0100 ++++ b/ld/configure 2010-04-08 14:58:21.000000000 +0100 +@@ -10966,10 +10966,34 @@ + # before this can be enabled. + hardcode_into_libs=yes + ++ # find out which ABI we are using ++ libsuff= ++ case "$host_cpu" in ++ x86_64*|s390*|powerpc*|ppc*|sparc*) ++ echo 'int i;' > conftest.$ac_ext ++ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ++ (eval $ac_compile) 2>&5 ++ ac_status=$? ++ echo "$as_me:$LINENO: \$? = $ac_status" >&5 ++ (exit $ac_status); }; then ++ case `/usr/bin/file conftest.$ac_objext` in ++ *64-bit*) ++ libsuff=64 ++ if test x"$sys_lib_search_path_spec" = x"/lib /usr/lib /usr/local/lib"; then ++ sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" ++ fi ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff}" ++ ;; ++ esac ++ fi ++ rm -rf conftest* ++ ;; ++ esac ++ + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` +- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on +Only in .: .#libtool.m4 +Only in .: #libtool.m4# +diff -rcp ../binutils-2.20.51.0.7.original/opcodes/configure ./opcodes/configure +--- a/opcodes/configure 2010-04-08 14:53:45.000000000 +0100 ++++ b/opcodes/configure 2010-04-08 14:59:10.000000000 +0100 +@@ -10496,10 +10496,34 @@ + # before this can be enabled. + hardcode_into_libs=yes + ++ # find out which ABI we are using ++ libsuff= ++ case "$host_cpu" in ++ x86_64*|s390*|powerpc*|ppc*|sparc*) ++ echo 'int i;' > conftest.$ac_ext ++ if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 ++ (eval $ac_compile) 2>&5 ++ ac_status=$? ++ echo "$as_me:$LINENO: \$? = $ac_status" >&5 ++ (exit $ac_status); }; then ++ case `/usr/bin/file conftest.$ac_objext` in ++ *64-bit*) ++ libsuff=64 ++ if test x"$sys_lib_search_path_spec" = x"/lib /usr/lib /usr/local/lib"; then ++ sys_lib_search_path_spec="/lib${libsuff} /usr/lib${libsuff} /usr/local/lib${libsuff}" ++ fi ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff}" ++ ;; ++ esac ++ fi ++ rm -rf conftest* ++ ;; ++ esac ++ + # Append ld.so.conf contents to the search path + if test -f /etc/ld.so.conf; then + lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` +- sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" ++ sys_lib_dlsearch_path_spec="/lib${libsuff} /usr/lib${libsuff} $lt_ld_extra" + fi + + # We used to test for /lib/ld.so.1 and disable shared libraries on diff --git a/binutils-no-config-h-check.patch b/binutils-no-config-h-check.patch new file mode 100644 index 0000000000000000000000000000000000000000..c89195a5b281de7b60e30ab5d795822978def42c --- /dev/null +++ b/binutils-no-config-h-check.patch @@ -0,0 +1,28 @@ +--- a/bfd/bfd-in.h 2012-08-02 10:56:34.561769686 +0100 ++++ b/bfd/bfd-in.h 2012-08-02 11:13:27.134797755 +0100 +@@ -25,11 +25,6 @@ + #ifndef __BFD_H_SEEN__ + #define __BFD_H_SEEN__ + +-/* PR 14072: Ensure that config.h is included first. */ +-#if !defined PACKAGE && !defined PACKAGE_VERSION +-#error config.h must be included before this header +-#endif +- + #ifdef __cplusplus + extern "C" { + #endif +--- a/bfd/bfd-in2.h 2012-08-02 10:56:34.349769680 +0100 ++++ b/bfd/bfd-in2.h 2012-08-02 11:13:40.015798113 +0100 +@@ -32,11 +32,6 @@ + #ifndef __BFD_H_SEEN__ + #define __BFD_H_SEEN__ + +-/* PR 14072: Ensure that config.h is included first. */ +-#if !defined PACKAGE && !defined PACKAGE_VERSION +-#error config.h must be included before this header +-#endif +- + #ifdef __cplusplus + extern "C" { + #endif diff --git a/binutils-special-sections-in-groups.patch b/binutils-special-sections-in-groups.patch new file mode 100644 index 0000000000000000000000000000000000000000..7de5a93f6164492be280ea08453181213e3ba5fd --- /dev/null +++ b/binutils-special-sections-in-groups.patch @@ -0,0 +1,27 @@ +--- binutils.orig/bfd/elf.c 2018-10-19 11:42:10.107277490 +0100 ++++ binutils-2.31.1/bfd/elf.c 2018-10-19 11:44:33.607105801 +0100 +@@ -830,7 +830,13 @@ setup_group (bfd *abfd, Elf_Internal_Shd + } + } + +- if (elf_group_name (newsect) == NULL) ++ if (elf_group_name (newsect) == NULL ++ /* OS specific sections might be in a group (eg ARM's ARM_EXIDX section) ++ but they will not have been added to the group because they do not ++ have contents that the ELF code in the BFD library knows how to ++ process. This is OK though - we rely upon the target backends to ++ handle these sections for us. */ ++ && hdr->sh_type < SHT_LOOS) + { + /* xgettext:c-format */ + _bfd_error_handler (_("%pB: no group info for section '%pA'"), +@@ -936,7 +942,8 @@ _bfd_elf_setup_sections (bfd *abfd) + else if (idx->shdr->bfd_section) + elf_sec_group (idx->shdr->bfd_section) = shdr->bfd_section; + else if (idx->shdr->sh_type != SHT_RELA +- && idx->shdr->sh_type != SHT_REL) ++ && idx->shdr->sh_type != SHT_REL ++ && idx->shdr->sh_type < SHT_LOOS) + { + /* There are some unknown sections in the group. */ + _bfd_error_handler diff --git a/binutils-update-linker-manual.patch b/binutils-update-linker-manual.patch new file mode 100644 index 0000000000000000000000000000000000000000..c7b6270fbbe27a00a3896ca942f4629ae1a7106d --- /dev/null +++ b/binutils-update-linker-manual.patch @@ -0,0 +1,36 @@ +diff -rup binutils.orig/ld/ld.1 binutils-2.41/ld/ld.1 +--- binutils.orig/ld/ld.1 2023-08-03 12:47:14.427004953 +0100 ++++ binutils-2.41/ld/ld.1 2023-08-03 12:49:10.672145873 +0100 +@@ -2669,7 +2669,7 @@ systems may not understand them. If you + \&\fB\-\-enable\-new\-dtags\fR, the new dynamic tags will be created as needed + and older dynamic tags will be omitted. + If you specify \fB\-\-disable\-new\-dtags\fR, no new dynamic tags will be +-created. By default, the new dynamic tags are not created. Note that ++created. By default, the new dynamic tags are created. Note that + those options are only available for ELF systems. + .IP \fB\-\-hash\-size=\fR\fInumber\fR 4 + .IX Item "--hash-size=number" +diff -rup binutils.orig/ld/ld.info binutils-2.41/ld/ld.info +--- binutils.orig/ld/ld.info 2023-08-03 12:47:14.427004953 +0100 ++++ binutils-2.41/ld/ld.info 2023-08-03 12:49:58.829204257 +0100 +@@ -2366,7 +2366,7 @@ GNU linker: + ‘--enable-new-dtags’, the new dynamic tags will be created as + needed and older dynamic tags will be omitted. If you specify + ‘--disable-new-dtags’, no new dynamic tags will be created. By +- default, the new dynamic tags are not created. Note that those ++ default, the new dynamic tags are created. Note that those + options are only available for ELF systems. + + ‘--hash-size=NUMBER’ +diff -rup binutils.orig/ld/ld.texi binutils-2.41/ld/ld.texi +--- binutils.orig/ld/ld.texi 2023-08-03 12:50:58.176276215 +0100 ++++ binutils-2.41/ld/ld.texi 2023-08-03 12:41:11.902610960 +0100 +@@ -2946,7 +2946,7 @@ systems may not understand them. If you + @option{--enable-new-dtags}, the new dynamic tags will be created as needed + and older dynamic tags will be omitted. + If you specify @option{--disable-new-dtags}, no new dynamic tags will be +-created. By default, the new dynamic tags are not created. Note that ++created. By default, the new dynamic tags are created. Note that + those options are only available for ELF systems. + + @kindex --hash-size=@var{number}