]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix handling of GNU Property notes that are not in a GNU NOTE PROPERTY section.
authorNick Clifton <nickc@redhat.com>
Mon, 20 Nov 2017 15:32:55 +0000 (15:32 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 20 Nov 2017 15:32:55 +0000 (15:32 +0000)
PR 22450
gas * elf-properties.c (_bfd_elf_link_setup_gnu_properties): Skip
objects without a GNU_PROPERTY note section when looking for a bfd
onto which notes can be accumulated.

ld * testsuite/ld-elf/elf.exp: Add --defsym ALIGN=2|3 to assembler
command line depending upon the size of the target address space.
* testsuite/ld-elf/pr22450.s: New test file.
* testsuite/ld-elf/pr22450.d: New test driver.
* testsuite/config/default.exp: Add note that LD_CLASS refers to
the size of the host linker not the size of the target linker.

bfd/ChangeLog
bfd/elf-properties.c
ld/ChangeLog
ld/testsuite/config/default.exp
ld/testsuite/ld-elf/elf.exp
ld/testsuite/ld-elf/pr22450.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr22450.s [new file with mode: 0644]

index 6e148b0eaa022e136ff35b54e65c4b0b48f7bb83..5bf4f1a9524fd703daaafc7690b0f5cd9e57b1f2 100644 (file)
@@ -1,3 +1,10 @@
+2017-11-20  Nick Clifton  <nickc@redhat.com>
+
+       PR 22450
+       * elf-properties.c (_bfd_elf_link_setup_gnu_properties): Skip
+       objects without a GNU_PROPERTY note section when looking for a bfd
+       onto which notes can be accumulated.
+
 2017-11-20  Alan Modra  <amodra@gmail.com>
 
        PR 22451
index bfb106edc92d1f80035f40ac32e419a9f495ee98..32e03dee37e377b9d7d842f077e48275cf0cb391 100644 (file)
@@ -328,11 +328,15 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
        has_properties = TRUE;
 
        /* Ignore GNU properties from ELF objects with different machine
-          code or class.  */
+          code or class.  Also skip objects without a GNU_PROPERTY note
+          section.  */
        if ((elf_machine_code
             == get_elf_backend_data (abfd)->elf_machine_code)
            && (elfclass
-               == get_elf_backend_data (abfd)->s->elfclass))
+               == get_elf_backend_data (abfd)->s->elfclass)
+           && bfd_get_section_by_name (abfd,
+                                       NOTE_GNU_PROPERTY_SECTION_NAME) != NULL
+           )
          {
            /* Keep .note.gnu.property section in FIRST_PBFD.  */
            first_pbfd = abfd;
@@ -374,10 +378,11 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
        if (list != NULL)
          {
-           /* Discard .note.gnu.property section in the rest inputs.  */
+           /* Discard the .note.gnu.property section in this bfd.  */
            sec = bfd_get_section_by_name (abfd,
                                           NOTE_GNU_PROPERTY_SECTION_NAME);
-           sec->output_section = bfd_abs_section_ptr;
+           if (sec != NULL)
+             sec->output_section = bfd_abs_section_ptr;
          }
       }
 
@@ -393,6 +398,7 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
 
       sec = bfd_get_section_by_name (first_pbfd,
                                     NOTE_GNU_PROPERTY_SECTION_NAME);
+      BFD_ASSERT (sec != NULL);
 
       /* Update stack size in .note.gnu.property with -z stack-size=N
         if N > 0.  */
index 7f3c7319c7ca64a6f82974f34c745a651590f0d3..01e3d63511fefc6f34cde04ab5af4e16bab50fb8 100644 (file)
@@ -1,3 +1,13 @@
+2017-11-20  Nick Clifton  <nickc@redhat.com>
+
+       PR 22450
+       * testsuite/ld-elf/elf.exp: Add --defsym ALIGN=2|3 to assembler
+       command line depending upon the size of the target address space.
+       * testsuite/ld-elf/pr22450.s: New test file.
+       * testsuite/ld-elf/pr22450.d: New test driver.
+       * testsuite/config/default.exp: Add note that LD_CLASS refers to
+       the size of the host linker not the size of the target linker.
+
 2017-11-15  Nick Clifton  <nickc@redhat.com>
 
        PR 15152
index 6aba75fdc59b5dcef7c984bc1eb5d38f1e83e8b2..950e202b1ae59e0d4e72324a1d27a11603d4ce45 100644 (file)
@@ -251,7 +251,7 @@ if ![info exists LDFLAGS] then {
     set LDFLAGS {}
 }
 
-# Set LD_CLASS to "64bit" for 64-bit LD.
+# Set LD_CLASS to "64bit" for a 64-bit *host* linker.
 if { ![info exists LD_CLASS] } then {
     set REAL_LD [findfile $base_dir/.libs/ld-new .libs/ld-new $LD [transform ld]]
     set readelf_output [run_host_cmd "$READELF" "-h $REAL_LD"]
index acdad8db22ae09191200849cd349905ab83690fa..8f24a75a74bc549617266d8b607e85c59bf3bcd2 100644 (file)
@@ -61,6 +61,8 @@ if { [is_remote host] } then {
     remote_download host merge.ld
 }
 
+# Note - the output file from the second test (symbol3w.a) is
+# used in the proc is_elf64 test below...
 run_ld_link_tests [list \
     [list "Build symbol3.a" \
        "" "" $hpux \
@@ -70,6 +72,41 @@ run_ld_link_tests [list \
        {symbol3w.s} {} "symbol3w.a" ] \
 ]
 
+
+# True if the object format is known to be 64-bit ELF.
+#
+proc is_elf64 { binary_file } {
+    global READELF
+    global READELFFLAGS
+
+    set readelf_size ""
+    catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
+
+    if ![string match "" $got] then {
+       return 0
+    }
+
+    if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
+              [file_contents readelf.out] nil readelf_size] } {
+       verbose "FAILED to determine ELF size"
+       return 0
+    }
+
+    if { $readelf_size == "64" } {
+       return 1
+    }
+
+    return 0
+}
+
+if [is_elf64 tmpdir/symbol3w.a] {
+    set ASFLAGS "$ASFLAGS --defsym ALIGN=3"
+} else {
+    set ASFLAGS "$ASFLAGS --defsym ALIGN=2"
+}
+
+
+
 # Targets that use _bfd_generic_link_add_symbols won't pass pr21703 tests
 run_ld_link_tests {
       {"PR ld/21703"
diff --git a/ld/testsuite/ld-elf/pr22450.d b/ld/testsuite/ld-elf/pr22450.d
new file mode 100644 (file)
index 0000000..26853bc
--- /dev/null
@@ -0,0 +1,12 @@
+#source: pr22450.s
+#readelf: --notes --wide
+#ld: -r
+# Fails on H8300 because it does not generate the correct relocs for the size fields.
+# Fails on AVR, IP2K, M68HC11, SPARC64, XC16C because the assembler does not calculate the correct values for the differences of local symbols.
+# Fails on CRX because readelf does not know how to apply CRX reloc number 20 (R_CRX_SWITCH32).
+
+#...
+Displaying notes found in: \.note\.gnu
+[      ]+Owner[        ]+Data size[    ]+Description
+[      ]+GNU[  ]+0x0+0..[      ]+NT_GNU_PROPERTY_TYPE_0[       ]+Properties: stack size: 0x8000
+#pass
diff --git a/ld/testsuite/ld-elf/pr22450.s b/ld/testsuite/ld-elf/pr22450.s
new file mode 100644 (file)
index 0000000..33118a1
--- /dev/null
@@ -0,0 +1,19 @@
+
+       .section ".note.gnu", "a" /* NB/ Deliberately incorrect section name.  Should be: .note.gnu.property  */
+       .p2align ALIGN
+
+       .dc.l 1f - 0f           /* Name length.  */
+       .dc.l 5f - 2f           /* Data length.  */
+       .dc.l 5                 /* Note type: NT_GNU_PROPERTY_TYPE_0 */
+0:
+       .asciz "GNU"            /* Vendor name.  */
+1:
+       .p2align ALIGN
+2:     
+       .dc.l 1                 /* pr_type: GNU_PROPERTY_STACK_SIZE */
+       .dc.l 5f - 4f           /* pr_datasz.  */
+4:
+       .dc.a 0x8000            /* Stack size.  */
+5:
+       .p2align ALIGN
+3: