diff --git a/binutils-2.29-filename-in-error-messages.patch b/binutils-2.29-filename-in-error-messages.patch index ee1963b..80ce912 100644 --- a/binutils-2.29-filename-in-error-messages.patch +++ b/binutils-2.29-filename-in-error-messages.patch @@ -1,6 +1,6 @@ --- binutils.orig/binutils/readelf.c 2017-07-24 15:27:09.859116315 +0100 +++ binutils-2.29/binutils/readelf.c 2017-07-24 15:30:33.557770525 +0100 -@@ -18414,39 +18414,49 @@ process_archive (char * file_name, FILE +@@ -18414,39 +18414,50 @@ process_archive (char * file_name, FILE static bfd_boolean process_file (char * file_name) { @@ -56,6 +56,7 @@ + error (_("Failed to read file's magic number\n")); fclose (file); - return FALSE; ++ ret = FALSE; + goto done; } diff --git a/binutils-2.29-revert-PLT-elision.patch b/binutils-2.29-revert-PLT-elision.patch new file mode 100644 index 0000000..49bfd34 --- /dev/null +++ b/binutils-2.29-revert-PLT-elision.patch @@ -0,0 +1,304 @@ +diff -rup binutils.orig/bfd/elf32-i386.c binutils-2.29.1/bfd/elf32-i386.c +--- binutils.orig/bfd/elf32-i386.c 2017-11-15 13:32:41.209042711 +0000 ++++ binutils-2.29.1/bfd/elf32-i386.c 2017-11-15 13:42:09.365205187 +0000 +@@ -2747,24 +2747,6 @@ elf_i386_allocate_dynrelocs (struct elf_ + if (h->type != STT_FUNC) + eh->func_pointer_refcount = 0; + +- /* We can't use the GOT PLT if pointer equality is needed since +- finish_dynamic_symbol won't clear symbol value and the dynamic +- linker won't update the GOT slot. We will get into an infinite +- loop at run-time. */ +- if (htab->plt_got != NULL +- && h->type != STT_GNU_IFUNC +- && !h->pointer_equality_needed +- && h->plt.refcount > 0 +- && h->got.refcount > 0) +- { +- /* Don't use the regular PLT if there are both GOT and GOTPLT +- reloctions. */ +- h->plt.offset = (bfd_vma) -1; +- +- /* Use the GOT PLT. */ +- eh->plt_got.refcount = 1; +- } +- + /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it + here if it is defined and referenced in a non-shared object. */ + if (h->type == STT_GNU_IFUNC +diff -rup binutils.orig/bfd/elf64-x86-64.c binutils-2.29.1/bfd/elf64-x86-64.c +--- binutils.orig/bfd/elf64-x86-64.c 2017-11-15 13:32:41.142043517 +0000 ++++ binutils-2.29.1/bfd/elf64-x86-64.c 2017-11-15 13:41:45.030498045 +0000 +@@ -3184,24 +3184,6 @@ elf_x86_64_allocate_dynrelocs (struct el + eh->has_got_reloc, + eh); + +- /* We can't use the GOT PLT if pointer equality is needed since +- finish_dynamic_symbol won't clear symbol value and the dynamic +- linker won't update the GOT slot. We will get into an infinite +- loop at run-time. */ +- if (htab->plt_got != NULL +- && h->type != STT_GNU_IFUNC +- && !h->pointer_equality_needed +- && h->plt.refcount > 0 +- && h->got.refcount > 0) +- { +- /* Don't use the regular PLT if there are both GOT and GOTPLT +- reloctions. */ +- h->plt.offset = (bfd_vma) -1; +- +- /* Use the GOT PLT. */ +- eh->plt_got.refcount = 1; +- } +- + /* Clear the reference count of function pointer relocations if + symbol isn't a normal function. */ + if (h->type != STT_FUNC) + +diff -rup binutils.orig/ld/testsuite/ld-i386/pltgot-1.d binutils-2.29.1/ld/testsuite/ld-i386/pltgot-1.d +--- binutils.orig/ld/testsuite/ld-i386/pltgot-1.d 2017-11-15 13:32:39.335065263 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-i386/pltgot-1.d 2017-11-15 15:03:55.649727195 +0000 +@@ -2,6 +2,7 @@ + #readelf: -S --wide + #as: --32 + ++#pass + #... + +\[ *[0-9]+\] \.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+10 +.* + #... +diff -rup binutils.orig/ld/testsuite/ld-i386/pltgot-2.d binutils-2.29.1/ld/testsuite/ld-i386/pltgot-2.d +--- binutils.orig/ld/testsuite/ld-i386/pltgot-2.d 2017-11-15 13:32:39.329065335 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-i386/pltgot-2.d 2017-11-15 15:04:20.803430034 +0000 +@@ -3,7 +3,6 @@ + #readelf: -d --wide + #as: --32 + +-#failif + #... + +0x[0-9a-f]+ +\(PLTREL.* + #... +diff -rup binutils.orig/ld/testsuite/ld-i386/pr19636-2d.d binutils-2.29.1/ld/testsuite/ld-i386/pr19636-2d.d +--- binutils.orig/ld/testsuite/ld-i386/pr19636-2d.d 2017-11-15 13:32:39.336065251 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-i386/pr19636-2d.d 2017-11-15 15:03:00.413379749 +0000 +@@ -9,7 +9,7 @@ Relocation section '\.rel\.dyn' at offse + [0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +func + [0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func + [0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func +- ++#... + Symbol table '\.dynsym' contains [0-9]+ entries: + +Num: +Value +Size Type +Bind +Vis +Ndx Name + #... +diff -rup binutils.orig/ld/testsuite/ld-i386/pr19636-2e.d binutils-2.29.1/ld/testsuite/ld-i386/pr19636-2e.d +--- binutils.orig/ld/testsuite/ld-i386/pr19636-2e.d 2017-11-15 13:32:39.330065323 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-i386/pr19636-2e.d 2017-11-15 15:03:28.928042882 +0000 +@@ -9,7 +9,7 @@ Relocation section '\.rel\.dyn' at offse + [0-9a-f]+ +[0-9a-f]+ +R_386_32 +0+ +func + [0-9a-f]+ +[0-9a-f]+ +R_386_PC32 +0+ +func + [0-9a-f]+ +[0-9a-f]+ +R_386_GLOB_DAT +0+ +func +- ++#... + Symbol table '\.dynsym' contains [0-9]+ entries: + +Num: +Value +Size Type +Bind +Vis +Ndx Name + #... +diff -rup binutils.orig/ld/testsuite/ld-i386/pr20830.d binutils-2.29.1/ld/testsuite/ld-i386/pr20830.d +--- binutils.orig/ld/testsuite/ld-i386/pr20830.d 2017-11-15 13:32:39.332065299 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-i386/pr20830.d 2017-11-15 15:04:43.205165384 +0000 +@@ -19,7 +19,7 @@ Contents of the .eh_frame section: + DW_CFA_offset: r8 \(eip\) at cfa-4 + DW_CFA_nop + DW_CFA_nop +- ++#pass + 0+18 00000010 0000001c FDE cie=00000000 pc=00000188..00000193 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pltgot-1.d binutils-2.29.1/ld/testsuite/ld-x86-64/pltgot-1.d +--- binutils.orig/ld/testsuite/ld-x86-64/pltgot-1.d 2017-11-15 13:32:39.415064300 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pltgot-1.d 2017-11-15 15:08:39.333375801 +0000 +@@ -2,8 +2,4 @@ + #readelf: -S --wide + #as: --64 + +-#... +- +\[ *[0-9]+\] \.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+10 +.* +-#... +- +\[ *[0-9]+\] \.got\.plt +PROGBITS +[0-9a-f]+ +[0-9a-f]+ +0+18 +.* + #pass +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pltgot-2.d binutils-2.29.1/ld/testsuite/ld-x86-64/pltgot-2.d +--- binutils.orig/ld/testsuite/ld-x86-64/pltgot-2.d 2017-11-15 13:32:39.404064432 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pltgot-2.d 2017-11-15 15:08:59.031143095 +0000 +@@ -3,7 +3,6 @@ + #readelf: -d --wide + #as: --64 + +-#failif + #... + +0x[0-9a-f]+ +\(PLTREL.* + #... +diff -rup binutils.orig/ld/testsuite/ld-x86-64/plt-main-bnd.dd binutils-2.29.1/ld/testsuite/ld-x86-64/plt-main-bnd.dd +--- binutils.orig/ld/testsuite/ld-x86-64/plt-main-bnd.dd 2017-11-15 13:32:39.405064420 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/plt-main-bnd.dd 2017-11-15 15:06:53.694623801 +0000 +@@ -1,7 +1,4 @@ +-#... +-Disassembly of section .plt.got: + +-[a-f0-9]+ <[a-z]+@plt>: +-[ ]*[a-f0-9]+: f2 ff 25 .. .. 20 00 bnd jmpq \*0x20....\(%rip\) # ...... <.*> ++#... + [ ]*[a-f0-9]+: 90 nop + #pass +diff -rup binutils.orig/ld/testsuite/ld-x86-64/plt-main-ibt.dd binutils-2.29.1/ld/testsuite/ld-x86-64/plt-main-ibt.dd +--- binutils.orig/ld/testsuite/ld-x86-64/plt-main-ibt.dd 2017-11-15 13:32:39.412064336 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/plt-main-ibt.dd 2017-11-15 15:06:35.148842897 +0000 +@@ -1,7 +1,3 @@ + #... +-Disassembly of section .plt.got: +- +-[a-f0-9]+ <[_a-z]+@plt>: + [ ]*[a-f0-9]+: f3 0f 1e fa endbr64 +-[ ]*[a-f0-9]+: f2 ff 25 .. .. 20 00 bnd jmpq \*0x20....\(%rip\) # ...... <[_a-z]+> + #pass +diff -rup binutils.orig/ld/testsuite/ld-x86-64/plt-main.rd binutils-2.29.1/ld/testsuite/ld-x86-64/plt-main.rd +--- binutils.orig/ld/testsuite/ld-x86-64/plt-main.rd 2017-11-15 13:32:39.407064397 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/plt-main.rd 2017-11-15 15:06:17.244054423 +0000 +@@ -1,4 +1,3 @@ +-#failif + #... + [0-9a-f ]+R_X86_64_JUMP_SLOT +0+ +bar \+ 0 + #... +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr20830a.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830a.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr20830a.d 2017-11-15 13:32:39.412064336 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830a.d 2017-11-15 15:15:09.918750288 +0000 +@@ -20,6 +20,7 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop ++#pass + + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000238..0000000000000244 + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr20830a-now.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830a-now.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr20830a-now.d 2017-11-15 13:32:39.413064324 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830a-now.d 2017-11-15 15:16:08.227055104 +0000 +@@ -20,6 +20,7 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop ++#pass + + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000238..0000000000000244 + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr20830b.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830b.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr20830b.d 2017-11-15 13:32:39.413064324 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830b.d 2017-11-15 15:16:20.115913358 +0000 +@@ -20,7 +20,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000010 0000001c FDE cie=00000000 pc=0000000000000188..0000000000000194 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr20830b-now.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830b-now.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr20830b-now.d 2017-11-15 13:32:39.411064348 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr20830b-now.d 2017-11-15 15:16:29.012807282 +0000 +@@ -20,7 +20,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000010 0000001c FDE cie=00000000 pc=0000000000000188..0000000000000194 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr21038a.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038a.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr21038a.d 2017-11-15 13:32:39.408064384 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038a.d 2017-11-15 15:19:48.097433680 +0000 +@@ -19,7 +19,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000238..0000000000000244 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr21038a-now.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038a-now.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr21038a-now.d 2017-11-15 13:32:39.401064469 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038a-now.d 2017-11-15 15:10:56.077760324 +0000 +@@ -20,7 +20,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000238..0000000000000244 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr21038b.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038b.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr21038b.d 2017-11-15 13:32:39.405064420 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038b.d 2017-11-15 15:10:42.828916844 +0000 +@@ -19,6 +19,7 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop ++#pass + + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000248..000000000000024d + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr21038b-now.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038b-now.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr21038b-now.d 2017-11-15 13:32:39.416064288 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038b-now.d 2017-11-15 15:11:11.550577531 +0000 +@@ -20,7 +20,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000248..000000000000024d + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr21038c.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038c.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr21038c.d 2017-11-15 13:32:39.411064348 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038c.d 2017-11-15 15:09:52.664509478 +0000 +@@ -19,7 +19,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000290..00000000000002a1 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/pr21038c-now.d binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038c-now.d +--- binutils.orig/ld/testsuite/ld-x86-64/pr21038c-now.d 2017-11-15 13:32:39.413064324 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/pr21038c-now.d 2017-11-15 15:11:22.975442559 +0000 +@@ -20,7 +20,8 @@ Contents of the .eh_frame section: + DW_CFA_offset: r16 \(rip\) at cfa-8 + DW_CFA_nop + DW_CFA_nop +- ++#pass ++ + 0+18 0000000000000014 0000001c FDE cie=00000000 pc=0000000000000290..00000000000002a1 + DW_CFA_nop + DW_CFA_nop +diff -rup binutils.orig/ld/testsuite/ld-x86-64/tlspic2.rd binutils-2.29.1/ld/testsuite/ld-x86-64/tlspic2.rd +--- binutils.orig/ld/testsuite/ld-x86-64/tlspic2.rd 2017-11-15 13:32:39.417064276 +0000 ++++ binutils-2.29.1/ld/testsuite/ld-x86-64/tlspic2.rd 2017-11-15 15:05:02.950932110 +0000 +@@ -14,6 +14,7 @@ Section Headers: + +\[[ 0-9]+\] .dynsym +.* + +\[[ 0-9]+\] .dynstr +.* + +\[[ 0-9]+\] .rela.dyn +.* ++#pass + +\[[ 0-9]+\] .plt +.* + +\[[ 0-9]+\] .plt.got +.* + +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+31a 00 +AX +0 +0 4096 diff --git a/binutils-aarch64-pie.patch b/binutils-aarch64-pie.patch new file mode 100644 index 0000000..0860795 --- /dev/null +++ b/binutils-aarch64-pie.patch @@ -0,0 +1,193 @@ +Only in binutils-2.29.1/bfd: ChangeLog.orig +Only in binutils-2.29.1/bfd: ChangeLog.rej +diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.29.1/bfd/elf64-s390.c +--- binutils.orig/bfd/elf64-s390.c 2018-01-22 12:10:06.282231202 +0000 ++++ binutils-2.29.1/bfd/elf64-s390.c 2018-01-22 12:32:36.743617339 +0000 +@@ -1600,8 +1600,7 @@ elf_s390_adjust_dynamic_symbol (struct b + { + if (h->plt.refcount <= 0 + || SYMBOL_CALLS_LOCAL (info, h) +- || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT +- && h->root.type == bfd_link_hash_undefweak)) ++ || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) + { + /* This case can occur if we saw a PLT32 reloc in an input + file, but the symbol was never referred to by a dynamic +@@ -1850,8 +1849,7 @@ allocate_dynrelocs (struct elf_link_hash + htab->elf.srelgot->size += sizeof (Elf64_External_Rela); + else if (tls_type == GOT_TLS_GD) + htab->elf.srelgot->size += 2 * sizeof (Elf64_External_Rela); +- else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT +- || h->root.type != bfd_link_hash_undefweak) ++ else if (!UNDEFWEAK_NO_DYNAMIC_RELOC (info, h) + && (bfd_link_pic (info) + || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) + htab->elf.srelgot->size += sizeof (Elf64_External_Rela); +@@ -1890,7 +1888,8 @@ allocate_dynrelocs (struct elf_link_hash + if (eh->dyn_relocs != NULL + && h->root.type == bfd_link_hash_undefweak) + { +- if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) ++ if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT ++ || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) + eh->dyn_relocs = NULL; + + /* Make sure undefined weak symbols are output as a dynamic +@@ -2307,6 +2306,7 @@ elf_s390_relocate_section (bfd *output_b + bfd_reloc_status_type r; + int tls_type; + asection *base_got = htab->elf.sgot; ++ bfd_boolean resolved_to_zero; + + r_type = ELF64_R_TYPE (rel->r_info); + if (r_type == (int) R_390_GNU_VTINHERIT +@@ -2402,6 +2402,9 @@ elf_s390_relocate_section (bfd *output_b + if (bfd_link_relocatable (info)) + continue; + ++ resolved_to_zero = (h != NULL ++ && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); ++ + switch (r_type) + { + case R_390_GOTPLT12: +@@ -2489,8 +2492,7 @@ elf_s390_relocate_section (bfd *output_b + h) + || (bfd_link_pic (info) + && SYMBOL_REFERENCES_LOCAL (info, h)) +- || (ELF_ST_VISIBILITY (h->other) +- && h->root.type == bfd_link_hash_undefweak)) ++ || resolved_to_zero) + { + /* This is actually a static link, or it is a + -Bsymbolic link and the symbol is defined +@@ -2804,7 +2806,8 @@ elf_s390_relocate_section (bfd *output_b + + if ((bfd_link_pic (info) + && (h == NULL +- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT ++ || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT ++ && !resolved_to_zero) + || h->root.type != bfd_link_hash_undefweak) + && ((r_type != R_390_PC16 + && r_type != R_390_PC12DBL +@@ -3592,6 +3595,9 @@ elf_s390_finish_dynamic_symbol (bfd *out + else if (bfd_link_pic (info) + && SYMBOL_REFERENCES_LOCAL (info, h)) + { ++ if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) ++ return TRUE; ++ + /* If this is a static link, or it is a -Bsymbolic link and + the symbol is defined locally or was forced to be local + because of a version file, we just want to emit a +Only in binutils-2.29.1/bfd: elf64-s390.c.orig +diff -rup binutils.orig/bfd/elf-bfd.h binutils-2.29.1/bfd/elf-bfd.h +--- binutils.orig/bfd/elf-bfd.h 2018-01-22 12:10:06.277231259 +0000 ++++ binutils-2.29.1/bfd/elf-bfd.h 2018-01-22 12:30:14.318245660 +0000 +@@ -266,6 +266,13 @@ struct elf_link_hash_entry + #define SYMBOL_CALLS_LOCAL(INFO, H) \ + _bfd_elf_symbol_refs_local_p (H, INFO, 1) + ++/* Whether an undefined weak symbol should resolve to its link-time ++ value, even in PIC or PIE objects. */ ++#define UNDEFWEAK_NO_DYNAMIC_RELOC(INFO, H) \ ++ ((H)->root.type == bfd_link_hash_undefweak \ ++ && (ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT \ ++ || (INFO)->dynamic_undefined_weak == 0)) ++ + /* Common symbols that are turned into definitions don't have the + DEF_REGULAR flag set, so they might appear to be undefined. + Symbols defined in linker scripts also don't have DEF_REGULAR set. */ +diff -rup binutils.orig/bfd/elfnn-aarch64.c binutils-2.29.1/bfd/elfnn-aarch64.c +--- binutils.orig/bfd/elfnn-aarch64.c 2018-01-22 12:10:06.271231328 +0000 ++++ binutils-2.29.1/bfd/elfnn-aarch64.c 2018-01-22 12:35:13.030825190 +0000 +@@ -4578,7 +4578,7 @@ aarch64_can_relax_tls (bfd *input_bfd, + if (symbol_got_type == GOT_TLS_IE && GOT_TLS_GD_ANY_P (reloc_got_type)) + return TRUE; + +- if (bfd_link_pic (info)) ++ if (!bfd_link_executable (info)) + return FALSE; + + if (h && h->root.type == bfd_link_hash_undefweak) +@@ -4951,6 +4951,7 @@ elfNN_aarch64_final_link_relocate (reloc + bfd_boolean relative_reloc; + asection *base_got; + bfd_vma orig_value = value; ++ bfd_boolean resolved_to_zero; + + globals = elf_aarch64_hash_table (info); + +@@ -5176,6 +5177,9 @@ bad_ifunc_reloc: + } + } + ++ resolved_to_zero = (h != NULL ++ && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)); ++ + switch (bfd_r_type) + { + case BFD_RELOC_AARCH64_NONE: +@@ -5194,7 +5198,8 @@ bad_ifunc_reloc: + || globals->root.is_relocatable_executable) + && (input_section->flags & SEC_ALLOC) + && (h == NULL +- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT ++ || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT ++ && !resolved_to_zero) + || h->root.type != bfd_link_hash_undefweak)) + /* Or we are creating an executable, we may need to keep relocations + for symbols satisfied by a dynamic library if we manage to avoid +@@ -6246,7 +6251,7 @@ elfNN_aarch64_relocate_section (bfd *out + indx = h && h->dynindx != -1 ? h->dynindx : 0; + + need_relocs = +- (bfd_link_pic (info) || indx != 0) && ++ (!bfd_link_executable (info) || indx != 0) && + (h == NULL + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak); +@@ -6341,7 +6346,7 @@ elfNN_aarch64_relocate_section (bfd *out + indx = h && h->dynindx != -1 ? h->dynindx : 0; + + need_relocs = +- (bfd_link_pic (info) || indx != 0) && ++ (!bfd_link_executable (info) || indx != 0) && + (h == NULL + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak); +@@ -8195,7 +8200,10 @@ elfNN_aarch64_allocate_dynrelocs (struct + if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak) + && (bfd_link_pic (info) +- || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) ++ || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)) ++ /* Undefined weak symbol in static PIE resolves to 0 without ++ any dynamic relocations. */ ++ && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) + { + htab->root.srelgot->size += RELOC_SIZE (htab); + } +@@ -8227,7 +8235,7 @@ elfNN_aarch64_allocate_dynrelocs (struct + indx = h && h->dynindx != -1 ? h->dynindx : 0; + if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak) +- && (bfd_link_pic (info) ++ && (!bfd_link_executable (info) + || indx != 0 + || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) + { +@@ -8995,7 +9003,10 @@ elfNN_aarch64_finish_dynamic_symbol (bfd + } + + if (h->got.offset != (bfd_vma) - 1 +- && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL) ++ && elf_aarch64_hash_entry (h)->got_type == GOT_NORMAL ++ /* Undefined weak symbol in static PIE resolves to 0 without ++ any dynamic relocations. */ ++ && !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)) + { + Elf_Internal_Rela rela; + bfd_byte *loc; +Only in binutils-2.29.1/bfd: elfnn-aarch64.c.orig diff --git a/binutils-ppc64-stub-creation.patch b/binutils-ppc64-stub-creation.patch new file mode 100644 index 0000000..4f57bd8 --- /dev/null +++ b/binutils-ppc64-stub-creation.patch @@ -0,0 +1,22 @@ +--- binutils.orig/bfd/elf64-ppc.c 2018-01-25 13:23:13.575860963 +0000 ++++ binutils-2.29.1/bfd/elf64-ppc.c 2018-01-25 13:24:36.564874275 +0000 +@@ -12805,6 +12805,9 @@ ppc64_elf_size_stubs (struct bfd_link_in + stub_sec->flags &= ~SEC_RELOC; + } + ++ if (htab->stub_iteration <= STUB_SHRINK_ITER ++ || htab->brlt->rawsize < htab->brlt->size) ++ htab->brlt->rawsize = htab->brlt->size; + htab->brlt->size = 0; + htab->brlt->reloc_count = 0; + htab->brlt->flags &= ~SEC_RELOC; +@@ -12858,6 +12861,9 @@ ppc64_elf_size_stubs (struct bfd_link_in + break; + + if (group == NULL ++ && (htab->brlt->rawsize == htab->brlt->size ++ || (htab->stub_iteration > STUB_SHRINK_ITER ++ && htab->brlt->rawsize > htab->brlt->size)) + && (htab->glink_eh_frame == NULL + || htab->glink_eh_frame->rawsize == htab->glink_eh_frame->size)) + break; diff --git a/binutils-readelf-other-sym-info.patch b/binutils-readelf-other-sym-info.patch new file mode 100644 index 0000000..9133b79 --- /dev/null +++ b/binutils-readelf-other-sym-info.patch @@ -0,0 +1,66 @@ +diff -rup binutils.orig/binutils/readelf.c binutils-2.29/binutils/readelf.c +--- binutils.orig/binutils/readelf.c 2017-12-12 16:24:19.571221194 +0000 ++++ binutils-2.29/binutils/readelf.c 2017-12-12 16:27:26.997979803 +0000 +@@ -11018,12 +11018,14 @@ print_dynamic_symbol (bfd_vma si, unsign + unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); + + printf (" %-7s", get_symbol_visibility (vis)); ++#if 0 + /* Check to see if any other bits in the st_other field are set. + Note - displaying this information disrupts the layout of the + table being generated, but for the moment this case is very + rare. */ + if (psym->st_other ^ vis) + printf (" [%s] ", get_symbol_other (psym->st_other ^ vis)); ++#endif + } + + printf (" %3.3s ", get_symbol_index_type (psym->st_shndx)); +@@ -11031,6 +11033,15 @@ print_dynamic_symbol (bfd_vma si, unsign + print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)); + else + printf (_(" "), psym->st_name); ++#if 1 ++ { ++ unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); ++ ++ /* Check to see if any other bits in the st_other field are set. */ ++ if (psym->st_other ^ vis) ++ printf (" \t[%s]", get_symbol_other (psym->st_other ^ vis)); ++ } ++#endif + putchar ('\n'); + } + +--- binutils.orig/binutils/readelf.c 2017-12-12 16:36:21.806561149 +0000 ++++ binutils-2.29.1/binutils/readelf.c 2017-12-12 16:38:17.763168514 +0000 +@@ -11548,11 +11548,13 @@ process_symbol_table (FILE * file) + unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); + + printf (" %-7s", get_symbol_visibility (vis)); ++#if 0 + /* Check to see if any other bits in the st_other field are set. + Note - displaying this information disrupts the layout of the + table being generated, but for the moment this case is very rare. */ + if (psym->st_other ^ vis) + printf (" [%s] ", get_symbol_other (psym->st_other ^ vis)); ++#endif + } + printf (" %4s ", get_symbol_index_type (psym->st_shndx)); + print_symbol (25, psym->st_name < strtab_size +@@ -11571,7 +11573,15 @@ process_symbol_table (FILE * file) + printf (sym_info == symbol_hidden ? "@%s" : "@@%s", + version_string); + } ++#if 1 ++ { ++ unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); + ++ /* Check to see if any other bits in the st_other field are set. */ ++ if (psym->st_other ^ vis) ++ printf (" \t[%s] ", get_symbol_other (psym->st_other ^ vis)); ++ } ++#endif + putchar ('\n'); + + if (ELF_ST_BIND (psym->st_info) == STB_LOCAL diff --git a/binutils-strip-delete-relocs.patch b/binutils-strip-delete-relocs.patch new file mode 100644 index 0000000..798d192 --- /dev/null +++ b/binutils-strip-delete-relocs.patch @@ -0,0 +1,73 @@ +diff -rup binutils.orig/bfd/elf64-sparc.c binutils-2.29.1/bfd/elf64-sparc.c +--- binutils.orig/bfd/elf64-sparc.c 2017-12-07 17:23:06.764174312 +0000 ++++ binutils-2.29.1/bfd/elf64-sparc.c 2017-12-07 17:23:20.540009839 +0000 +@@ -287,6 +287,7 @@ elf64_sparc_set_reloc (bfd *abfd ATTRIBU + unsigned int count) + { + asect->orelocation = location; ++ asect->reloc_count = count / 2; + canon_reloc_count (asect) = count; + } + +Only in binutils-2.29.1/bfd: elf64-sparc.c.orig +diff -rup binutils.orig/bfd/elfcode.h binutils-2.29.1/bfd/elfcode.h +--- binutils.orig/bfd/elfcode.h 2017-12-07 17:23:06.722174814 +0000 ++++ binutils-2.29.1/bfd/elfcode.h 2017-12-07 17:23:20.541009827 +0000 +@@ -958,6 +958,12 @@ elf_write_relocs (bfd *abfd, asection *s + return; + } + ++ if (ptr->howto == NULL) ++ { ++ *failedp = TRUE; ++ return; ++ } ++ + src_rela.r_offset = ptr->address + addr_offset; + src_rela.r_info = ELF_R_INFO (n, ptr->howto->type); + src_rela.r_addend = ptr->addend; +diff -rup binutils.orig/binutils/objcopy.c binutils-2.29.1/binutils/objcopy.c +--- binutils.orig/binutils/objcopy.c 2017-12-07 17:23:06.769174253 +0000 ++++ binutils-2.29.1/binutils/objcopy.c 2017-12-07 17:23:20.542009815 +0000 +@@ -3785,14 +3785,24 @@ copy_relocations_in_section (bfd *ibfd, + } + else + { +- relpp = (arelent **) xmalloc (relsize); +- relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp); +- if (relcount < 0) ++ if (isection->orelocation != NULL) + { +- status = 1; +- bfd_nonfatal_message (NULL, ibfd, isection, +- _("relocation count is negative")); +- return; ++ /* Some other function has already set up the output relocs ++ for us, so scan those instead of the default relocs. */ ++ relcount = isection->reloc_count; ++ relpp = isection->orelocation; ++ } ++ else ++ { ++ relpp = (arelent **) xmalloc (relsize); ++ relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp); ++ if (relcount < 0) ++ { ++ status = 1; ++ bfd_nonfatal_message (NULL, ibfd, isection, ++ _("relocation count is negative")); ++ return; ++ } + } + + if (strip_symbols == STRIP_ALL) +@@ -3815,7 +3825,8 @@ copy_relocations_in_section (bfd *ibfd, + temp_relpp [temp_relcount++] = relpp [i]; + } + relcount = temp_relcount; +- free (relpp); ++ if (isection->orelocation == NULL) ++ free (relpp); + relpp = temp_relpp; + } + diff --git a/binutils-support-v3-build-notes.patch b/binutils-support-v3-build-notes.patch new file mode 100644 index 0000000..a6668f3 --- /dev/null +++ b/binutils-support-v3-build-notes.patch @@ -0,0 +1,1337 @@ +diff -rup binutils.orig/binutils/objcopy.c binutils-2.29.1/binutils/objcopy.c +--- binutils.orig/binutils/objcopy.c 2018-01-03 16:06:45.005657092 +0000 ++++ binutils-2.29.1/binutils/objcopy.c 2018-01-03 16:06:57.927502748 +0000 +@@ -1905,84 +1905,229 @@ num_bytes (unsigned long val) + return count; + } + ++typedef struct objcopy_internal_note ++{ ++ Elf_Internal_Note note; ++ bfd_vma start; ++ bfd_vma end; ++ bfd_boolean modified; ++} objcopy_internal_note; ++ ++/* Returns TRUE if a gap does, or could, exist between the address range ++ covered by PNOTE1 and PNOTE2. */ ++ ++static bfd_boolean ++gap_exists (objcopy_internal_note * pnote1, ++ objcopy_internal_note * pnote2) ++{ ++ /* Without range end notes, we assume that a gap might exist. */ ++ if (pnote1->end == 0 || pnote2->end == 0) ++ return TRUE; ++ ++ /* FIXME: Alignment of 16 bytes taken from x86_64 binaries. ++ Really we should extract the alignment of the section covered by the notes. */ ++ return BFD_ALIGN (pnote1->end, 16) < pnote2->start; ++} ++ ++static bfd_boolean ++is_open_note (objcopy_internal_note * pnote) ++{ ++ return (pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_OPEN); ++} ++ ++static bfd_boolean ++is_func_note (objcopy_internal_note * pnote) ++{ ++ return (pnote->note.type == NT_GNU_BUILD_ATTRIBUTE_FUNC); ++} ++ ++static bfd_boolean ++is_64bit (bfd * abfd) ++{ ++ /* Should never happen, but let's be paranoid. */ ++ if (bfd_get_flavour (abfd) != bfd_target_elf_flavour) ++ return FALSE; ++ ++ return elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64; ++} ++ + /* Merge the notes on SEC, removing redundant entries. + Returns the new, smaller size of the section upon success. */ + + static bfd_size_type + merge_gnu_build_notes (bfd * abfd, asection * sec, bfd_size_type size, bfd_byte * contents) + { +- Elf_Internal_Note * pnotes_end; +- Elf_Internal_Note * pnotes; +- Elf_Internal_Note * pnote; ++ objcopy_internal_note * pnotes_end; ++ objcopy_internal_note * pnotes = NULL; ++ objcopy_internal_note * pnote; + bfd_size_type remain = size; + unsigned version_1_seen = 0; + unsigned version_2_seen = 0; ++ unsigned version_3_seen = 0; + bfd_boolean duplicate_found = FALSE; + const char * err = NULL; + bfd_byte * in = contents; + int attribute_type_byte; + int val_start; ++ unsigned long previous_func_start = 0; ++ unsigned long previous_open_start = 0; ++ unsigned long previous_func_end = 0; ++ unsigned long previous_open_end = 0; ++ long relsize; ++ + +- /* Make a copy of the notes. ++ relsize = bfd_get_reloc_upper_bound (abfd, sec); ++ if (relsize > 0) ++ { ++ arelent ** relpp; ++ long relcount; ++ ++ /* If there are relocs associated with this section then we ++ cannot safely merge it. */ ++ relpp = (arelent **) xmalloc (relsize); ++ relcount = bfd_canonicalize_reloc (abfd, sec, relpp, isympp); ++ free (relpp); ++ if (relcount != 0) ++ goto done; ++ } ++ ++ /* Make a copy of the notes and convert to our internal format. + Minimum size of a note is 12 bytes. */ +- pnote = pnotes = (Elf_Internal_Note *) xcalloc ((size / 12), sizeof (Elf_Internal_Note)); ++ pnote = pnotes = (objcopy_internal_note *) xcalloc ((size / 12), sizeof (* pnote)); + while (remain >= 12) + { +- pnote->namesz = (bfd_get_32 (abfd, in ) + 3) & ~3; +- pnote->descsz = (bfd_get_32 (abfd, in + 4) + 3) & ~3; +- pnote->type = bfd_get_32 (abfd, in + 8); ++ bfd_vma start, end; + +- if (pnote->type != NT_GNU_BUILD_ATTRIBUTE_OPEN +- && pnote->type != NT_GNU_BUILD_ATTRIBUTE_FUNC) ++ pnote->note.namesz = (bfd_get_32 (abfd, in ) + 3) & ~3; ++ pnote->note.descsz = (bfd_get_32 (abfd, in + 4) + 3) & ~3; ++ pnote->note.type = bfd_get_32 (abfd, in + 8); ++ ++ if (pnote->note.type != NT_GNU_BUILD_ATTRIBUTE_OPEN ++ && pnote->note.type != NT_GNU_BUILD_ATTRIBUTE_FUNC) + { + err = _("corrupt GNU build attribute note: wrong note type"); + goto done; + } + +- if (pnote->namesz + pnote->descsz + 12 > remain) ++ if (pnote->note.namesz + pnote->note.descsz + 12 > remain) + { + err = _("corrupt GNU build attribute note: note too big"); + goto done; + } + +- if (pnote->namesz < 2) ++ if (pnote->note.namesz < 2) + { + err = _("corrupt GNU build attribute note: name too small"); + goto done; + } + +- if (pnote->descsz != 0 +- && pnote->descsz != 4 +- && pnote->descsz != 8) ++ pnote->note.namedata = (char *)(in + 12); ++ pnote->note.descdata = (char *)(in + 12 + pnote->note.namesz); ++ ++ remain -= 12 + pnote->note.namesz + pnote->note.descsz; ++ in += 12 + pnote->note.namesz + pnote->note.descsz; ++ ++ if (pnote->note.namesz > 2 ++ && pnote->note.namedata[0] == '$' ++ && pnote->note.namedata[1] == GNU_BUILD_ATTRIBUTE_VERSION ++ && pnote->note.namedata[2] == '1') ++ ++ version_1_seen; ++ else if (pnote->note.namesz > 4 ++ && pnote->note.namedata[0] == 'G' ++ && pnote->note.namedata[1] == 'A' ++ && pnote->note.namedata[2] == '$' ++ && pnote->note.namedata[3] == GNU_BUILD_ATTRIBUTE_VERSION) + { ++ if (pnote->note.namedata[4] == '2') ++ ++ version_2_seen; ++ else if (pnote->note.namedata[4] == '3') ++ ++ version_3_seen; ++ else ++ { ++ err = _("corrupt GNU build attribute note: unsupported version"); ++ goto done; ++ } ++ } ++ ++ switch (pnote->note.descsz) ++ { ++ case 0: ++ start = end = 0; ++ break; ++ ++ case 4: ++ start = bfd_get_32 (abfd, pnote->note.descdata); ++ /* FIXME: For version 1 and 2 notes we should try to ++ calculate the end address by finding a symbol whose ++ value is START, and then adding in its size. ++ ++ For now though, since v1 and v2 was not intended to ++ handle gaps, we chose an artificially large end ++ address. */ ++ end = 0x7ffffffffffffffUL; ++ break; ++ ++ case 8: ++ if (! is_64bit (abfd)) ++ { ++ start = bfd_get_32 (abfd, pnote->note.descdata); ++ end = bfd_get_32 (abfd, pnote->note.descdata + 4); ++ } ++ else ++ { ++ start = bfd_get_64 (abfd, pnote->note.descdata); ++ /* FIXME: For version 1 and 2 notes we should try to ++ calculate the end address by finding a symbol whose ++ value is START, and then adding in its size. ++ ++ For now though, since v1 and v2 was not intended to ++ handle gaps, we chose an artificially large end ++ address. */ ++ end = 0x7ffffffffffffffUL; ++ } ++ break; ++ ++ case 16: ++ start = bfd_get_64 (abfd, pnote->note.descdata); ++ end = bfd_get_64 (abfd, pnote->note.descdata + 8); ++ break; ++ ++ default: + err = _("corrupt GNU build attribute note: bad description size"); + goto done; + } + +- pnote->namedata = (char *)(in + 12); +- pnote->descdata = (char *)(in + 12 + pnote->namesz); ++ if (is_open_note (pnote)) ++ { ++ if (start) ++ previous_open_start = start; ++ ++ pnote->start = previous_open_start; + +- remain -= 12 + pnote->namesz + pnote->descsz; +- in += 12 + pnote->namesz + pnote->descsz; ++ if (end) ++ previous_open_end = end; + +- if (pnote->namedata[pnote->namesz - 1] != 0) ++ pnote->end = previous_open_end; ++ } ++ else ++ { ++ if (start) ++ previous_func_start = start; ++ ++ pnote->start = previous_func_start; ++ ++ if (end) ++ previous_func_end = end; ++ ++ pnote->end = previous_func_end; ++ } ++ ++ if (pnote->note.namedata[pnote->note.namesz - 1] != 0) + { + err = _("corrupt GNU build attribute note: name not NUL terminated"); + goto done; + } +- +- if (pnote->namesz > 2 +- && pnote->namedata[0] == '$' +- && pnote->namedata[1] == GNU_BUILD_ATTRIBUTE_VERSION +- && pnote->namedata[2] == '1') +- ++ version_1_seen; +- else if (pnote->namesz > 4 +- && pnote->namedata[0] == 'G' +- && pnote->namedata[1] == 'A' +- && pnote->namedata[2] == '$' +- && pnote->namedata[3] == GNU_BUILD_ATTRIBUTE_VERSION +- && pnote->namedata[4] == '2') +- ++ version_2_seen; ++ + pnote ++; + } + +@@ -1995,27 +2140,29 @@ merge_gnu_build_notes (bfd * abfd, asect + goto done; + } + +- if (version_1_seen == 0 && version_2_seen == 0) ++ if (version_1_seen == 0 && version_2_seen == 0 && version_3_seen == 0) + { + err = _("bad GNU build attribute notes: no known versions detected"); + goto done; + } + +- if (version_1_seen > 0 && version_2_seen > 0) ++ if ((version_1_seen > 0 && version_2_seen > 0) ++ || (version_1_seen > 0 && version_3_seen > 0) ++ || (version_2_seen > 0 && version_3_seen > 0)) + { + err = _("bad GNU build attribute notes: multiple different versions"); + goto done; + } + + /* Merging is only needed if there is more than one version note... */ +- if (version_1_seen == 1 || version_2_seen == 1) ++ if (version_1_seen == 1 || version_2_seen == 1 || version_3_seen == 1) + goto done; + + attribute_type_byte = version_1_seen ? 1 : 3; + val_start = attribute_type_byte + 1; + + /* The first note should be the first version note. */ +- if (pnotes[0].namedata[attribute_type_byte] != GNU_BUILD_ATTRIBUTE_VERSION) ++ if (pnotes[0].note.namedata[attribute_type_byte] != GNU_BUILD_ATTRIBUTE_VERSION) + { + err = _("bad GNU build attribute notes: first note not version note"); + goto done; +@@ -2026,7 +2173,9 @@ merge_gnu_build_notes (bfd * abfd, asect + 2. Preserve any NT_GNU_BUILD_ATTRIBUTE_FUNC notes. + 3. Eliminate any NT_GNU_BUILD_ATTRIBUTE_OPEN notes that have the same + full name field as the immediately preceeding note with the same type +- of name. ++ of name and whose address ranges coincide. ++ IE - it there are gaps in the coverage of the notes, then these gaps ++ must be preserved. + 4. Combine the numeric value of any NT_GNU_BUILD_ATTRIBUTE_OPEN notes + of type GNU_BUILD_ATTRIBUTE_STACK_SIZE. + 5. If an NT_GNU_BUILD_ATTRIBUTE_OPEN note is going to be preserved and +@@ -2036,103 +2185,134 @@ merge_gnu_build_notes (bfd * abfd, asect + address to which it refers. */ + for (pnote = pnotes + 1; pnote < pnotes_end; pnote ++) + { +- Elf_Internal_Note * back; +- Elf_Internal_Note * prev_open = NULL; ++ int note_type; ++ objcopy_internal_note * back; ++ objcopy_internal_note * prev_open_with_range = NULL; + +- if (pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC) ++ /* Rule 2 - preserve function notes. */ ++ if (! is_open_note (pnote)) + continue; + +- /* Scan for duplicates. Clear the type field of any found - but do not +- delete them just yet. */ ++ note_type = pnote->note.namedata[attribute_type_byte]; ++ ++ /* Scan backwards from pnote, looking for duplicates. ++ Clear the type field of any found - but do not delete them just yet. */ + for (back = pnote - 1; back >= pnotes; back --) + { +- if (back->descsz > 0 +- && back->type != NT_GNU_BUILD_ATTRIBUTE_FUNC +- && prev_open == NULL) +- prev_open = back; ++ int back_type = back->note.namedata[attribute_type_byte]; ++ ++ /* If this is the first open note with an address ++ range that we have encountered then record it. */ ++ if (prev_open_with_range == NULL ++ && back->note.descsz > 0 ++ && ! is_func_note (back)) ++ prev_open_with_range = back; ++ ++ if (! is_open_note (back)) ++ continue; ++ ++ /* If the two notes are different then keep on searching. */ ++ if (back_type != note_type) ++ continue; + +- if (back->type == pnote->type +- && back->namedata[attribute_type_byte] == pnote->namedata[attribute_type_byte]) ++ /* Rule 4 - combine stack size notes. */ ++ if (back_type == GNU_BUILD_ATTRIBUTE_STACK_SIZE) + { +- if (back->namedata[attribute_type_byte] == GNU_BUILD_ATTRIBUTE_STACK_SIZE) ++ unsigned char * name; ++ unsigned long note_val; ++ unsigned long back_val; ++ unsigned int shift; ++ unsigned int bytes; ++ unsigned long byte; ++ ++ for (shift = 0, note_val = 0, ++ bytes = pnote->note.namesz - val_start, ++ name = (unsigned char *) pnote->note.namedata + val_start; ++ bytes--;) + { +- unsigned char * name; +- unsigned long note_val; +- unsigned long back_val; +- unsigned int shift; +- unsigned int bytes; +- unsigned long byte; +- +- for (shift = 0, note_val = 0, +- bytes = pnote->namesz - val_start, +- name = (unsigned char *) pnote->namedata + val_start; +- bytes--;) +- { +- byte = (* name ++) & 0xff; +- note_val |= byte << shift; +- shift += 8; +- } +- +- for (shift = 0, back_val = 0, +- bytes = back->namesz - val_start, +- name = (unsigned char *) back->namedata + val_start; +- bytes--;) +- { +- byte = (* name ++) & 0xff; +- back_val |= byte << shift; +- shift += 8; +- } +- +- back_val += note_val; +- if (num_bytes (back_val) >= back->namesz - val_start) +- { +- /* We have a problem - the new value requires more bytes of +- storage in the name field than are available. Currently +- we have no way of fixing this, so we just preserve both +- notes. */ +- continue; +- } +- +- /* Write the new val into back. */ +- name = (unsigned char *) back->namedata + val_start; +- while (name < (unsigned char *) back->namedata + back->namesz) +- { +- byte = back_val & 0xff; +- * name ++ = byte; +- if (back_val == 0) +- break; +- back_val >>= 8; +- } +- +- duplicate_found = TRUE; +- pnote->type = 0; +- break; ++ byte = (* name ++) & 0xff; ++ note_val |= byte << shift; ++ shift += 8; + } +- +- if (back->namesz == pnote->namesz +- && memcmp (back->namedata, pnote->namedata, back->namesz) == 0) ++ ++ for (shift = 0, back_val = 0, ++ bytes = back->note.namesz - val_start, ++ name = (unsigned char *) back->note.namedata + val_start; ++ bytes--;) + { +- duplicate_found = TRUE; +- pnote->type = 0; +- break; ++ byte = (* name ++) & 0xff; ++ back_val |= byte << shift; ++ shift += 8; + } + +- /* If we have found an attribute match then stop searching backwards. */ +- if (! ISPRINT (back->namedata[attribute_type_byte]) +- /* Names are NUL terminated, so this is safe. */ +- || strcmp (back->namedata + val_start, pnote->namedata + val_start) == 0) ++ back_val += note_val; ++ if (num_bytes (back_val) >= back->note.namesz - val_start) + { +- /* Since we are keeping this note we must check to see if its +- description refers back to an earlier OPEN version note. If so +- then we must make sure that version note is also preserved. */ +- if (pnote->descsz == 0 +- && prev_open != NULL +- && prev_open->type == 0) +- prev_open->type = NT_GNU_BUILD_ATTRIBUTE_FUNC; ++ /* We have a problem - the new value requires more bytes of ++ storage in the name field than are available. Currently ++ we have no way of fixing this, so we just preserve both ++ notes. */ ++ continue; ++ } + +- break; ++ /* Write the new val into back. */ ++ name = (unsigned char *) back->note.namedata + val_start; ++ while (name < (unsigned char *) back->note.namedata ++ + back->note.namesz) ++ { ++ byte = back_val & 0xff; ++ * name ++ = byte; ++ if (back_val == 0) ++ break; ++ back_val >>= 8; + } ++ ++ duplicate_found = TRUE; ++ pnote->note.type = 0; ++ break; ++ } ++ ++ /* Rule 3 - combine identical open notes. */ ++ if (back->note.namesz == pnote->note.namesz ++ && memcmp (back->note.namedata, ++ pnote->note.namedata, back->note.namesz) == 0 ++ && ! gap_exists (back, pnote)) ++ { ++ duplicate_found = TRUE; ++ pnote->note.type = 0; ++ ++ if (pnote->end > back->end) ++ back->end = pnote->end; ++ ++ if (version_3_seen) ++ back->modified = TRUE; ++ break; + } ++ ++ /* Rule 5 - Since we are keeping this note we must check to see ++ if its description refers back to an earlier OPEN version ++ note that has been scheduled for deletion. If so then we ++ must make sure that version note is also preserved. */ ++ if (version_3_seen) ++ { ++ /* As of version 3 we can just ++ move the range into the note. */ ++ pnote->modified = TRUE; ++ pnote->note.type = NT_GNU_BUILD_ATTRIBUTE_FUNC; ++ back->modified = TRUE; ++ back->note.type = NT_GNU_BUILD_ATTRIBUTE_FUNC; ++ } ++ else ++ { ++ if (pnote->note.descsz == 0 ++ && prev_open_with_range != NULL ++ && prev_open_with_range->note.type == 0) ++ prev_open_with_range->note.type = NT_GNU_BUILD_ATTRIBUTE_OPEN; ++ } ++ ++ /* We have found a similar attribute but the details do not match. ++ Stop searching backwards. */ ++ break; + } + } + +@@ -2142,22 +2322,8 @@ merge_gnu_build_notes (bfd * abfd, asect + bfd_byte * old; + bfd_byte * new; + bfd_size_type new_size; +- arelent ** relpp = NULL; +- long relsize; +- long relcount = 0; +- +- relsize = bfd_get_reloc_upper_bound (abfd, sec); +- if (relsize > 0) +- { +- /* If there are relocs associated with this section then we may +- have to adjust them as well, as we remove notes. */ +- relpp = (arelent **) xmalloc (relsize); +- relcount = bfd_canonicalize_reloc (abfd, sec, relpp, isympp); +- if (relcount < 0) +- /* Do not bother complaining here - copy_relocations_in_section +- will do that for us. */ +- relcount = 0; +- } ++ bfd_vma prev_start = 0; ++ bfd_vma prev_end = 0; + + /* Eliminate the duplicates. */ + new = new_contents = xmalloc (size); +@@ -2165,36 +2331,52 @@ merge_gnu_build_notes (bfd * abfd, asect + pnote < pnotes_end; + pnote ++) + { +- bfd_size_type note_size = 12 + pnote->namesz + pnote->descsz; ++ bfd_size_type note_size = 12 + pnote->note.namesz + pnote->note.descsz; + +- if (pnote->type == 0) ++ if (pnote->note.type != 0) + { +- if (relcount > 0) ++ if (pnote->modified) + { +- arelent ** rel; +- +- /* If there is a reloc at the current offset, delete it. +- Adjust the location of any relocs above the current +- location downwards by the size of the note being deleted. +- FIXME: We could optimize this loop by retaining a pointer to +- the last reloc below the current note. */ +- for (rel = relpp; rel < relpp + relcount; rel ++) ++ /* If the note has been modified then we must copy it by ++ hand, potentially adding in a new description field. */ ++ if (pnote->start == prev_start && pnote->end == prev_end) + { +- if ((* rel)->howto == NULL) +- continue; +- if ((* rel)->address < (bfd_vma) (new - new_contents)) +- continue; +- if ((* rel)->address >= (bfd_vma) ((new + note_size) - new_contents)) +- (* rel)->address -= note_size; ++ bfd_put_32 (abfd, pnote->note.namesz, new); ++ bfd_put_32 (abfd, 0, new + 4); ++ bfd_put_32 (abfd, pnote->note.type, new + 8); ++ new += 12; ++ memcpy (new, pnote->note.namedata, pnote->note.namesz); ++ new += pnote->note.namesz; ++ } ++ else ++ { ++ bfd_put_32 (abfd, pnote->note.namesz, new); ++ bfd_put_32 (abfd, is_64bit (abfd) ? 16 : 8, new + 4); ++ bfd_put_32 (abfd, pnote->note.type, new + 8); ++ new += 12; ++ memcpy (new, pnote->note.namedata, pnote->note.namesz); ++ new += pnote->note.namesz; ++ if (is_64bit (abfd)) ++ { ++ bfd_put_64 (abfd, pnote->start, new); ++ bfd_put_64 (abfd, pnote->end, new + 8); ++ new += 16; ++ } + else +- (* rel)->howto = NULL; ++ { ++ bfd_put_32 (abfd, pnote->start, new); ++ bfd_put_32 (abfd, pnote->end, new + 4); ++ new += 8; ++ } + } + } +- } +- else +- { +- memcpy (new, old, note_size); +- new += note_size; ++ else ++ { ++ memcpy (new, old, note_size); ++ new += note_size; ++ } ++ prev_start = pnote->start; ++ prev_end = pnote->end; + } + + old += note_size; +@@ -2204,24 +2386,6 @@ merge_gnu_build_notes (bfd * abfd, asect + memcpy (contents, new_contents, new_size); + size = new_size; + free (new_contents); +- +- if (relcount > 0) +- { +- arelent **rel = relpp; +- +- while (rel < relpp + relcount) +- if ((*rel)->howto != NULL) +- rel++; +- else +- { +- /* Delete eliminated relocs. +- FIXME: There are better ways to do this. */ +- memmove (rel, rel + 1, +- ((relcount - (rel - relpp)) - 1) * sizeof (*rel)); +- relcount--; +- } +- bfd_set_reloc (abfd, sec, relpp, relcount); +- } + } + + done: +diff -rup binutils.orig/binutils/readelf.c binutils-2.29.1/binutils/readelf.c +--- binutils.orig/binutils/readelf.c 2018-01-03 16:06:45.005657092 +0000 ++++ binutils-2.29.1/binutils/readelf.c 2018-01-03 16:28:24.417115970 +0000 +@@ -16247,9 +16247,9 @@ get_note_type (unsigned e_type) + case NT_ARCH: + return _("NT_ARCH (architecture)"); + case NT_GNU_BUILD_ATTRIBUTE_OPEN: +- return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); ++ return _("OPEN"); + case NT_GNU_BUILD_ATTRIBUTE_FUNC: +- return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); ++ return _("func"); + default: + break; + } +@@ -17064,13 +17064,16 @@ print_ia64_vms_note (Elf_Internal_Note * + return TRUE; + } + +-/* Print the name of the symbol associated with a build attribute +- that is attached to address OFFSET. */ +- +-static bfd_boolean +-print_symbol_for_build_attribute (FILE * file, +- unsigned long offset, +- bfd_boolean is_open_attr) ++/* Find the symbol associated with a build attribute that is attached ++ to address OFFSET. If PNAME is non-NULL then store the name of ++ the symbol (if found) in the provided pointer, Returns NULL if a ++ symbol could not be found. */ ++ ++static Elf_Internal_Sym * ++get_symbol_for_build_attribute (FILE * file, ++ unsigned long offset, ++ bfd_boolean is_open_attr, ++ const char ** pname) + { + static FILE * saved_file = NULL; + static char * strtab; +@@ -17109,10 +17112,7 @@ print_symbol_for_build_attribute (FILE * + } + + if (symtab == NULL || strtab == NULL) +- { +- printf ("\n"); +- return FALSE; +- } ++ return NULL; + + /* Find a symbol whose value matches offset. */ + for (sym = symtab; sym < symtab + nsyms; sym ++) +@@ -17132,14 +17132,15 @@ print_symbol_for_build_attribute (FILE * + FUNC symbols entirely. */ + switch (ELF_ST_TYPE (sym->st_info)) + { +- case STT_FILE: +- saved_sym = sym; +- /* We can stop searching now. */ +- sym = symtab + nsyms; +- continue; +- + case STT_OBJECT: ++ case STT_FILE: + saved_sym = sym; ++ if (sym->st_size) ++ { ++ /* If the symbol has a size associated ++ with it then we can stop searching. */ ++ sym = symtab + nsyms; ++ } + continue; + + case STT_FUNC: +@@ -17177,55 +17178,118 @@ print_symbol_for_build_attribute (FILE * + } + } + +- printf (" (%s: %s)\n", +- is_open_attr ? _("file") : _("func"), +- saved_sym ? strtab + saved_sym->st_name : _(")")); +- return TRUE; ++ if (saved_sym && pname) ++ * pname = strtab + saved_sym->st_name; ++ ++ return saved_sym; + } + + static bfd_boolean + print_gnu_build_attribute_description (Elf_Internal_Note * pnote, + FILE * file) + { +- static unsigned long global_offset = 0; +- unsigned long offset; +- unsigned int desc_size = is_32bit_elf ? 4 : 8; +- bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; +- +- if (pnote->descsz == 0) +- { ++ static unsigned long global_offset = 0; ++ static unsigned long global_end = 0; ++ static unsigned long func_offset = 0; ++ static unsigned long func_end = 0; ++ ++ Elf_Internal_Sym * sym; ++ const char * name; ++ unsigned long start; ++ unsigned long end; ++ bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; ++ ++ switch (pnote->descsz) ++ { ++ case 0: ++ /* A zero-length description means that the range of ++ the previous note of the same type should be used. */ + if (is_open_attr) + { +- printf (_(" Applies from offset %#lx\n"), global_offset); +- return TRUE; ++ if (global_end > global_offset) ++ printf (_(" Applies to region from %#lx to %#lx\n"), ++ global_offset, global_end); ++ else ++ printf (_(" Applies to region from %#lx\n"), global_offset); + } + else + { +- printf (_(" Applies to func at %#lx"), global_offset); +- return print_symbol_for_build_attribute (file, global_offset, is_open_attr); ++ if (func_end > func_offset) ++ printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end); ++ else ++ printf (_(" Applies to region from %#lx\n"), func_offset); + } +- } ++ return TRUE; + +- if (pnote->descsz != desc_size) +- { ++ case 4: ++ start = byte_get ((unsigned char *) pnote->descdata, 4); ++ end = 0; ++ break; ++ ++ case 8: ++ if (is_32bit_elf) ++ { ++ /* FIXME: We should check that version 3+ notes are being used here... */ ++ start = byte_get ((unsigned char *) pnote->descdata, 4); ++ end = byte_get ((unsigned char *) pnote->descdata + 4, 4); ++ } ++ else ++ { ++ start = byte_get ((unsigned char *) pnote->descdata, 8); ++ end = 0; ++ } ++ break; ++ ++ case 16: ++ start = byte_get ((unsigned char *) pnote->descdata, 8); ++ end = byte_get ((unsigned char *) pnote->descdata + 8, 8); ++ break; ++ ++ default: + error (_(" \n"), pnote->descsz); + printf (_(" ")); + return FALSE; + } + +- offset = byte_get ((unsigned char *) pnote->descdata, desc_size); ++ name = NULL; ++ sym = get_symbol_for_build_attribute (file, start, is_open_attr, & name); ++ ++ if (end == 0 && sym != NULL && sym->st_size > 0) ++ end = start + sym->st_size; + + if (is_open_attr) + { +- printf (_(" Applies from offset %#lx"), offset); +- global_offset = offset; ++ /* FIXME: Need to properly allow for section alignment. 16 is just the alignment used on x86_64. */ ++ if (global_end > 0 && start > BFD_ALIGN (global_end, 16)) ++ warn (_("Gap in build notes detected from %#lx to %#lx\n"), ++ global_end + 1, start - 1); ++ ++ printf (_(" Applies to region from %#lx"), start); ++ global_offset = start; ++ ++ if (end) ++ { ++ printf (_(" to %#lx"), end); ++ global_end = end; ++ } + } + else + { +- printf (_(" Applies to func at %#lx"), offset); ++ printf (_(" Applies to region from %#lx"), start); ++ func_offset = start; ++ ++ if (end) ++ { ++ printf (_(" to %#lx"), end); ++ func_end = end; ++ } + } + +- return print_symbol_for_build_attribute (file, offset, is_open_attr); ++ if (sym && name) ++ printf (_(" (%s)"), name); ++ ++ printf ("\n"); ++ return TRUE; + } + + static bfd_boolean +@@ -17248,11 +17312,21 @@ print_gnu_build_attribute_name (Elf_Inte + return FALSE; + } + +- left = 20; ++ if (do_wide) ++ left = 28; ++ else ++ left = 20; + + /* Version 2 of the spec adds a "GA" prefix to the name field. */ + if (name[0] == 'G' && name[1] == 'A') + { ++ if (pnote->namesz < 4) ++ { ++ error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); ++ print_symbol (-20, _(" ")); ++ return FALSE; ++ } ++ + printf ("GA"); + name += 2; + left -= 2; +diff -rup binutils.orig/binutils/testsuite/binutils-all/mips/mips-note-2r.d binutils-2.29.1/binutils/testsuite/binutils-all/mips/mips-note-2r.d +--- binutils.orig/binutils/testsuite/binutils-all/mips/mips-note-2r.d 2018-01-03 16:06:45.013656996 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/mips/mips-note-2r.d 2018-01-03 16:06:57.927502748 +0000 +@@ -5,7 +5,5 @@ + #as: -32 + #source: ../note-2-32.s + +-Relocation section '\.rel\.gnu\.build\.attributes' at offset .* contains 2 entries: +- Offset Info Type Sym\.Value Sym\. Name +-00000010 ......02 R_MIPS_32 00000100 note1\.s +-0000006c ......02 R_MIPS_32 00000104 note2\.s ++There are no relocations in this file. ++#... +diff -rup binutils.orig/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d binutils-2.29.1/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d +--- binutils.orig/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d 2018-01-03 16:06:45.014656984 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/mips/mips-note-2r-n32.d 2018-01-03 16:06:57.927502748 +0000 +@@ -5,7 +5,5 @@ + #as: -n32 -mips3 + #source: ../note-2-32.s + +-Relocation section '\.rela\.gnu\.build\.attributes' at offset .* contains 2 entries: +- Offset Info Type Sym\.Value Sym\. Name \+ Addend +-00000010 ......02 R_MIPS_32 00000100 note1\.s \+ 0 +-0000006c ......02 R_MIPS_32 00000104 note2\.s \+ 0 ++There are no relocations in this file. ++#... +diff -rup binutils.orig/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d binutils-2.29.1/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d +--- binutils.orig/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d 2018-01-03 16:06:45.014656984 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/mips/mips-note-2r-n64.d 2018-01-03 16:06:57.927502748 +0000 +@@ -5,11 +5,5 @@ + #as: -64 -mips3 + #source: ../note-2-64.s + +-Relocation section '\.rela\.gnu\.build\.attributes' at offset .* contains 2 entries: +- Offset Info Type Sym\. Value Sym\. Name \+ Addend +-000000000010 ....00000012 R_MIPS_64 0000000000000100 note1\.s \+ 0 +- Type2: R_MIPS_NONE +- Type3: R_MIPS_NONE +-000000000070 ....00000012 R_MIPS_64 0000000000000104 note2\.s \+ 0 +- Type2: R_MIPS_NONE +- Type3: R_MIPS_NONE ++There are no relocations in this file. ++#... +diff -rup binutils.orig/binutils/testsuite/binutils-all/note-2-32.d binutils-2.29.1/binutils/testsuite/binutils-all/note-2-32.d +--- binutils.orig/binutils/testsuite/binutils-all/note-2-32.d 2018-01-03 16:06:45.013656996 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-2-32.d 2018-01-03 16:06:57.927502748 +0000 +@@ -6,12 +6,12 @@ + + #... + Owner Data size Description +-[ ]+\$1[ ]+0x00000004[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 \(file: note1.s\) +-[ ]+\$gcc 7.0.1[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\+true[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\*static[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\*0x0[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\$1[ ]+0x00000004[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x10. \(file: note2.s\) +-[ ]+!false[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x10. +-[ ]+\*pic[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_FUNC[ ]+Applies to func at 0x10. \(func: func1\) ++[ ]+\$1[ ]+0x00000004[ ]+OPEN[ ]+Applies to region from 0x100 \(note1.s\) ++[ ]+\$gcc 7.0.1[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\+true[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\*static[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\*0x0[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\$1[ ]+0x00000004[ ]+OPEN[ ]+Applies to region from 0x104 \(note2.s\) ++[ ]+!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x104 ++[ ]+\*pic[ ]+0x00000004[ ]+func[ ]+Applies to region from 0x104 \(func1\) + #... +diff -rup binutils.orig/binutils/testsuite/binutils-all/note-2-32.s binutils-2.29.1/binutils/testsuite/binutils-all/note-2-32.s +--- binutils.orig/binutils/testsuite/binutils-all/note-2-32.s 2018-01-03 16:06:45.010657032 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-2-32.s 2018-01-03 16:06:57.927502748 +0000 +@@ -2,7 +2,7 @@ + .org 0x100 + .global note1.s + note1.s: +- .word 0 ++ .dc.l 0 + + .pushsection .gnu.build.attributes, "0x100000", %note + .balign 4 +@@ -10,7 +10,7 @@ note1.s: + .dc.l 4 + .dc.l 0x100 + .asciz "$1" +- .dc.l note1.s ++ .dc.l 0x100 + + .dc.l 12 + .dc.l 0 +@@ -39,14 +39,14 @@ note1.s: + note2.s: + .type func1, STT_FUNC + func1: +- .word 0x100 ++ .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note + .dc.l 4 + .dc.l 4 + .dc.l 0x100 + .asciz "$1" +- .dc.l note2.s ++ .dc.l 0x104 + + .dc.l 12 + .dc.l 0 +@@ -60,26 +60,28 @@ func1: + .dc.b 0 + + .dc.l 4 +- .dc.l 0 ++ .dc.l 4 + .dc.l 0x101 + .dc.b 0x2a, 0x7, 1, 0 +- ++ .dc.l 0x104 ++ + .dc.l 4 + .dc.l 0 + .dc.l 0x100 + .dc.b 0x2a, 0x6, 0, 0 + .popsection + ++ + .global note3.s + note3.s: +- .word 0x100 ++ .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note + .dc.l 4 + .dc.l 4 + .dc.l 0x100 + .asciz "$1" +- .dc.l note3.s ++ .dc.l 0x108 + + .dc.l 12 + .dc.l 0 +diff -rup binutils.orig/binutils/testsuite/binutils-all/note-2-64.d binutils-2.29.1/binutils/testsuite/binutils-all/note-2-64.d +--- binutils.orig/binutils/testsuite/binutils-all/note-2-64.d 2018-01-03 16:06:45.010657032 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-2-64.d 2018-01-03 16:06:57.927502748 +0000 +@@ -6,12 +6,12 @@ + + #... + Owner Data size Description +-[ ]+\$1[ ]+0x00000008[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 \(file: note1.s\) +-[ ]+\$gcc 7.0.1[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\+true[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\*static[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\*0x0[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x100 +-[ ]+\$1[ ]+0x00000008[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x10. \(file: note2.s\) +-[ ]+!false[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_OPEN[ ]+Applies from offset 0x10. +-[ ]+\*pic[ ]+0x00000000[ ]+NT_GNU_BUILD_ATTRIBUTE_FUNC[ ]+Applies to func at 0x10. \(func: func1\) ++[ ]+\$1[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 \(note1.s\) ++[ ]+\$gcc 7.0.1[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\+true[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\*static[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\*0x0[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 ++[ ]+\$1[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x104 \(note2.s\) ++[ ]+!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x104 ++[ ]+\*pic[ ]+0x00000008[ ]+func[ ]+Applies to region from 0x104 \(func1\) + #... +diff -rup binutils.orig/binutils/testsuite/binutils-all/note-2-64.s binutils-2.29.1/binutils/testsuite/binutils-all/note-2-64.s +--- binutils.orig/binutils/testsuite/binutils-all/note-2-64.s 2018-01-03 16:06:45.014656984 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-2-64.s 2018-01-03 16:06:57.927502748 +0000 +@@ -2,7 +2,7 @@ + .org 0x100 + .global note1.s + note1.s: +- .word 0 ++ .dc.l 0 + + .pushsection .gnu.build.attributes, "0x100000", %note + .balign 4 +@@ -10,7 +10,7 @@ note1.s: + .dc.l 8 + .dc.l 0x100 + .asciz "$1" +- .8byte note1.s ++ .8byte 0x100 + + .dc.l 12 + .dc.l 0 +@@ -40,14 +40,14 @@ note2.s: + .global func1 + .type func1, STT_FUNC + func1: +- .word 0x100 ++ .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note + .dc.l 4 + .dc.l 8 + .dc.l 0x100 + .asciz "$1" +- .8byte note2.s ++ .8byte 0x104 + + .dc.l 12 + .dc.l 0 +@@ -61,9 +61,10 @@ func1: + .dc.b 0 + + .dc.l 4 +- .dc.l 0 ++ .dc.l 8 + .dc.l 0x101 + .dc.b 0x2a, 0x7, 1, 0 ++ .8byte 0x104 + + .dc.l 4 + .dc.l 0 +@@ -74,14 +75,14 @@ func1: + + .global note3.s + note3.s: +- .word 0x100 ++ .dc.l 0x100 + + .pushsection .gnu.build.attributes, "0x100000", %note + .dc.l 4 + .dc.l 8 + .dc.l 0x100 + .asciz "$1" +- .8byte note3.s ++ .8byte 0x108 + + .dc.l 12 + .dc.l 0 +diff -rup binutils.orig/binutils/testsuite/binutils-all/objcopy.exp binutils-2.29.1/binutils/testsuite/binutils-all/objcopy.exp +--- binutils.orig/binutils/testsuite/binutils-all/objcopy.exp 2018-01-03 16:06:45.013656996 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/objcopy.exp 2018-01-03 16:21:05.682365371 +0000 +@@ -1056,8 +1056,10 @@ if [is_elf_format] { + run_dump_test "note-1" + if [is_elf64 tmpdir/bintest.o] { + run_dump_test "note-2-64" ++ run_dump_test "note-4-64" + } else { + run_dump_test "note-2-32" ++ run_dump_test "note-4-32" + } + } + + +--- /dev/null 2018-01-03 08:45:19.457895336 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-4-32.s 2018-01-03 16:36:13.314505682 +0000 +@@ -0,0 +1,74 @@ ++ .text ++ .org 0x100 ++note_4.s: ++ .dc.l 0 ++ .dc.l 0 ++ ++ .type bar, STT_FUNC ++bar: ++ .dc.l 0 ++bar_end: ++ .dc.l 0 ++note_4.s_end: ++ ++ .pushsection .gnu.build.attributes, "", %note ++ .balign 4 ++ ++ .dc.l 8 ++ .dc.l 8 ++ .dc.l 0x100 ++ .asciz "GA$3p3" ++ .dc.l note_4.s ++ .dc.l note_4.s_end ++ ++ .dc.l 23 ++ .dc.l 0 ++ .dc.l 0x100 ++ .asciz "GA$gcc 7.2.1 20170915" ++ .dc.b 0 ++ ++ .dc.l 10 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 8 ++ .dc.l 0x101 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0x3, 0 ++ .dc.b 0, 0 ++ .dc.l bar ++ .dc.l bar_end ++ ++ .popsection +--- /dev/null 2018-01-03 08:45:19.457895336 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-4-32.d 2018-01-03 16:36:13.313505694 +0000 +@@ -0,0 +1,19 @@ ++#PROG: objcopy ++#readelf: --notes --wide ++#objcopy: --merge-notes ++#name: v3 gnu build attribute notes (32-bit) ++#source: note-4-32.s ++ ++#... ++Displaying notes found in: .gnu.build.attributes ++[ ]+Owner[ ]+Data size[ ]+Description ++[ ]+GA\$3p3[ ]+0x00000008[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 \(note_4.s\) ++[ ]+GA\$gcc 7.2.1 20170915[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x110 ++[ ]+GA\*strong[ ]+0x00000008[ ]+func[ ]+Applies to region from 0x108 to 0x10c.* ++#... +--- /dev/null 2018-01-03 08:45:19.457895336 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-4-64.s 2018-01-03 16:36:07.041580738 +0000 +@@ -0,0 +1,78 @@ ++ .text ++ .org 0x100 ++note_4.s: ++ .dc.l 0 ++ .dc.l 0 ++ .dc.l 0 ++ .dc.l 0 ++ ++ .type bar, @function ++bar: ++ .dc.l 0 ++ .dc.l 0 ++ .dc.l 0 ++bar_end: ++ .dc.l 0 ++note_4.s_end: ++ ++ .pushsection .gnu.build.attributes, "", %note ++ .balign 4 ++ ++ .dc.l 8 ++ .dc.l 16 ++ .dc.l 0x100 ++ .asciz "GA$3p3" ++ .8byte note_4.s ++ .8byte note_4.s_end ++ ++ .dc.l 23 ++ .dc.l 0 ++ .dc.l 0x100 ++ .asciz "GA$gcc 7.2.1 20170915" ++ .dc.b 0 ++ ++ .dc.l 10 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x47, 0x4f, 0x57, 0, 0, 0x7, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x46, 0x4f, 0x52, 0x54, 0x49, 0x46, 0x59, 0, 0xff, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x7, 0x2, 0 ++ .dc.b 0, 0 ++ ++ .dc.l 5 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x21, 0x8, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 13 ++ .dc.l 0 ++ .dc.l 0x100 ++ .dc.b 0x47, 0x41, 0x2a, 0x6, 0xf2, 0x3, 0x38, 0xee, 0xce, 0xfa, 0x5e, 0x3c, 0 ++ .dc.b 0, 0, 0 ++ ++ .dc.l 6 ++ .dc.l 16 ++ .dc.l 0x101 ++ .dc.b 0x47, 0x41, 0x2a, 0x2, 0x3, 0 ++ .dc.b 0, 0 ++ .8byte bar ++ .8byte bar_end ++ ++ .popsection +--- /dev/null 2018-01-03 08:45:19.457895336 +0000 ++++ binutils-2.29.1/binutils/testsuite/binutils-all/note-4-64.d 2018-01-03 16:36:07.041580738 +0000 +@@ -0,0 +1,19 @@ ++#PROG: objcopy ++#readelf: --notes --wide ++#objcopy: --merge-notes ++#name: v3 gnu build attribute notes (64-bit) ++#source: note-4-64.s ++ ++#... ++Displaying notes found in: .gnu.build.attributes ++[ ]+Owner[ ]+Data size[ ]+Description ++[ ]+GA\$3p3[ ]+0x00000010[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 \(note_4.s\) ++[ ]+GA\$gcc 7.2.1 20170915[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*GOW:0x700[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*off[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*FORTIFY:0xff[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*PIC[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\!false[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*0x[0-9a-f]+[ ]+0x00000000[ ]+OPEN[ ]+Applies to region from 0x100 to 0x120 ++[ ]+GA\*strong[ ]+0x00000010[ ]+func[ ]+Applies to region from 0x110 to 0x11c.* ++#... diff --git a/binutils-z-undefs.patch b/binutils-z-undefs.patch new file mode 100644 index 0000000..fe0f6f0 --- /dev/null +++ b/binutils-z-undefs.patch @@ -0,0 +1,71 @@ +diff -rup binutils.orig/ld/emultempl/elf32.em binutils-2.29.1/ld/emultempl/elf32.em +--- binutils.orig/ld/emultempl/elf32.em 2018-01-16 11:34:58.040749108 +0000 ++++ binutils-2.29.1/ld/emultempl/elf32.em 2018-01-16 11:35:35.697303875 +0000 +@@ -2666,6 +2666,8 @@ fragment <= 4.0, gettext, flex, bison, zlib-devel # BZ 920545: We need pod2man in order to build the manual pages. BuildRequires: /usr/bin/pod2man +# Perl, sed and touch are all used in the %prep section of this spec file. +BuildRequires: gcc, perl, sed, coreutils +BuildRequires: findutils + # Required for: ld-bootstrap/bootstrap.exp bootstrap with --static # It should not be required for: ld-elf/elf.exp static {preinit,init,fini} array Conflicts: gcc-c++ < 4.0.0 @@ -261,6 +310,13 @@ cd %{srcdir} %patch07 -p1 %patch08 -p1 %patch09 -p1 +%patch10 -p1 +%patch11 -p1 +%patch12 -p1 +%patch13 -p1 +%patch14 -p1 +%patch15 -p1 +%patch16 -p1 %if %{build_sh64} @@ -425,7 +481,8 @@ function config_target () { # We could optimize the cross builds size by --enable-shared but the produced # binaries may be less convenient in the embedded environment. - LDFLAGS='-Wl,-z,relro ' \ + echo LDFLAGS: $RPM_LD_FLAGS + LDFLAGS="$RPM_LD_FLAGS " \ ../%{srcdir}/configure \ --disable-dependency-tracking \ --disable-silent-rules \ @@ -461,6 +518,7 @@ function config_target () { --enable-compressed-debug-sections=none \ %endif --enable-lto \ + --enable-relro=yes \ $CARGS \ --with-bugurl=http://bugzilla.redhat.com/bugzilla/ cd .. @@ -473,7 +531,7 @@ done function build_target () { build_dir=${1%%%%-*} - make -C $build_dir %{_smp_mflags} tooldir=%{_prefix} all + %make_build -C $build_dir tooldir=%{_prefix} all } for target in `cat target.list` @@ -503,7 +561,7 @@ cd %{cross}-binutils --program-prefix=%{cross}- \ --disable-shared \ --with-bugurl=http://bugzilla.redhat.com/bugzilla/ -make %{_smp_mflags} tooldir=%{_prefix} all +%make_build tooldir=%{_prefix} all cd .. ############################################################################### @@ -517,7 +575,7 @@ rm -rf %{buildroot} function install_bin () { cpu=${1%%%%-*} build_dir=$cpu - make install -C $build_dir DESTDIR=%{buildroot} + %make_install -C $build_dir DESTDIR=%{buildroot} # We want links for ppc and ppc64 also if we make powerpc or powerpc64 case $cpu in @@ -563,12 +621,12 @@ make install-man1 -C %{cross}-binutils/ld DESTDIR=%{buildroot} make install-man1 -C %{cross}-binutils/gprof DESTDIR=%{buildroot} echo "=== INSTALL po targets ===" -make install -C %{cross}-binutils/binutils/po DESTDIR=%{buildroot} -make install -C %{cross}-binutils/gas/po DESTDIR=%{buildroot} -make install -C %{cross}-binutils/ld/po DESTDIR=%{buildroot} -make install -C %{cross}-binutils/gprof/po DESTDIR=%{buildroot} -make install -C %{cross}-binutils/bfd/po DESTDIR=%{buildroot} -make install -C %{cross}-binutils/opcodes/po DESTDIR=%{buildroot} +%make_install -C %{cross}-binutils/binutils/po DESTDIR=%{buildroot} +%make_install -C %{cross}-binutils/gas/po DESTDIR=%{buildroot} +%make_install -C %{cross}-binutils/ld/po DESTDIR=%{buildroot} +%make_install -C %{cross}-binutils/gprof/po DESTDIR=%{buildroot} +%make_install -C %{cross}-binutils/bfd/po DESTDIR=%{buildroot} +%make_install -C %{cross}-binutils/opcodes/po DESTDIR=%{buildroot} # Add the additional symlink-only targets grep ^powerpc target.list | sed -e s/powerpc/ppc/ >symlink-target.list @@ -715,7 +773,7 @@ cd - %do_files ppc-linux-gnu %{build_powerpc} %do_files ppc64-linux-gnu %{build_powerpc64} %do_files ppc64le-linux-gnu %{build_powerpc64le} -%do_files riscv64-linux-gnu %{build_riscv64}1 +%do_files riscv64-linux-gnu %{build_riscv64} %do_files s390-linux-gnu %{build_s390} %do_files s390x-linux-gnu %{build_s390x} %do_files score-linux-gnu %{build_score} @@ -730,6 +788,9 @@ cd - %do_files xtensa-linux-gnu %{build_xtensa} %changelog +* Wed Feb 14 2018 David Howells - 2.29.1-4 +- Sync with binutils-2.29.1-19. + * Fri Feb 09 2018 Igor Gnatenko - 2.29.1-3 - Escape macros in %%changelog