From 56d4289c6c259fefb1bd1b30fffb207e48e3dcd5 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Fri, 13 Aug 2010 20:50:27 +0000 Subject: [PATCH] Check if .got.plt section is discarded before using it. bfd/ 2010-08-13 H.J. Lu PR ld/11913 * elf32-i386.c (elf_i386_finish_dynamic_sections): Check if .got.plt section is discarded. * elf64-x86-64.c (elf64_x86_64_finish_dynamic_sections): Likewise. ld/testsuite/ 2010-08-13 H.J. Lu PR ld/11913 * ld-i386/discarded1.d: New. * ld-i386/discarded1.s: Likewise. * ld-i386/discarded1.t: Likewise. * ld-x86-64/discarded1.d: Likewise. * ld-x86-64/discarded1.s: Likewise. * ld-x86-64/discarded1.t: Likewise. * ld-i386/i386.exp: Run discarded1. * ld-x86-64/x86-64.exp: Likewise. --- bfd/ChangeLog | 7 +++++++ bfd/elf32-i386.c | 7 +++++++ bfd/elf64-x86-64.c | 7 +++++++ ld/testsuite/ChangeLog | 13 +++++++++++++ ld/testsuite/ld-i386/discarded1.d | 3 +++ ld/testsuite/ld-i386/discarded1.s | 13 +++++++++++++ ld/testsuite/ld-i386/discarded1.t | 7 +++++++ ld/testsuite/ld-i386/i386.exp | 1 + ld/testsuite/ld-x86-64/discarded1.d | 3 +++ ld/testsuite/ld-x86-64/discarded1.s | 13 +++++++++++++ ld/testsuite/ld-x86-64/discarded1.t | 7 +++++++ ld/testsuite/ld-x86-64/x86-64.exp | 1 + 12 files changed, 82 insertions(+) create mode 100644 ld/testsuite/ld-i386/discarded1.d create mode 100644 ld/testsuite/ld-i386/discarded1.s create mode 100644 ld/testsuite/ld-i386/discarded1.t create mode 100644 ld/testsuite/ld-x86-64/discarded1.d create mode 100644 ld/testsuite/ld-x86-64/discarded1.s create mode 100644 ld/testsuite/ld-x86-64/discarded1.t diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e1c543b52e..5f18054423 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2010-08-13 H.J. Lu + + PR ld/11913 + * elf32-i386.c (elf_i386_finish_dynamic_sections): Check if + .got.plt section is discarded. + * elf64-x86-64.c (elf64_x86_64_finish_dynamic_sections): Likewise. + 2010-08-13 Nathan Sidwell * elf32-m69k.c (elf32_m68k_print_private_bfd_data): Detect EMAC_B diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 0ff31471f3..4ba1ba035d 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -4613,6 +4613,13 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd, if (htab->elf.sgotplt) { + if (bfd_is_abs_section (htab->elf.sgotplt->output_section)) + { + (*_bfd_error_handler) + (_("discarded output section: `%A'"), htab->elf.sgotplt); + return FALSE; + } + /* Fill in the first three entries in the global offset table. */ if (htab->elf.sgotplt->size > 0) { diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index b0bc5c0125..9899fd4a34 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -4186,6 +4186,13 @@ elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *inf if (htab->elf.sgotplt) { + if (bfd_is_abs_section (htab->elf.sgotplt->output_section)) + { + (*_bfd_error_handler) + (_("discarded output section: `%A'"), htab->elf.sgotplt); + return FALSE; + } + /* Fill in the first three entries in the global offset table. */ if (htab->elf.sgotplt->size > 0) { diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index b5250a5e71..c15a44e99e 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2010-08-13 H.J. Lu + + PR ld/11913 + * ld-i386/discarded1.d: New. + * ld-i386/discarded1.s: Likewise. + * ld-i386/discarded1.t: Likewise. + * ld-x86-64/discarded1.d: Likewise. + * ld-x86-64/discarded1.s: Likewise. + * ld-x86-64/discarded1.t: Likewise. + + * ld-i386/i386.exp: Run discarded1. + * ld-x86-64/x86-64.exp: Likewise. + 2010-08-09 Catherine Moore * ld-mips-elf/mode-change-error-1.d: New. diff --git a/ld/testsuite/ld-i386/discarded1.d b/ld/testsuite/ld-i386/discarded1.d new file mode 100644 index 0000000000..8106db3e3c --- /dev/null +++ b/ld/testsuite/ld-i386/discarded1.d @@ -0,0 +1,3 @@ +#as: --32 +#ld: -melf_i386 -T discarded1.t +#error: .*discarded output section: `.got.plt' diff --git a/ld/testsuite/ld-i386/discarded1.s b/ld/testsuite/ld-i386/discarded1.s new file mode 100644 index 0000000000..9b20c87e25 --- /dev/null +++ b/ld/testsuite/ld-i386/discarded1.s @@ -0,0 +1,13 @@ + .text +.globl _start + .type _start, @function +_start: + movl x@GOT(%ecx), %eax + .size _start, .-_start +.globl x + .data + .align 4 + .type x, @object + .size x, 4 +x: + .long 2 diff --git a/ld/testsuite/ld-i386/discarded1.t b/ld/testsuite/ld-i386/discarded1.t new file mode 100644 index 0000000000..a4d617f6cb --- /dev/null +++ b/ld/testsuite/ld-i386/discarded1.t @@ -0,0 +1,7 @@ +ENTRY(_start) +SECTIONS +{ + .text : {*(.text)} + .data : {*(.data)} + /DISCARD/ : {*(*)} +} diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp index 850713af29..86ba9e47d1 100644 --- a/ld/testsuite/ld-i386/i386.exp +++ b/ld/testsuite/ld-i386/i386.exp @@ -190,6 +190,7 @@ run_dump_test "protected2" run_dump_test "protected3" run_dump_test "tlspie1" run_dump_test "nogot1" +run_dump_test "discarded1" if { !([istarget "i?86-*-linux*"] || [istarget "x86_64-*-linux*"]) } { diff --git a/ld/testsuite/ld-x86-64/discarded1.d b/ld/testsuite/ld-x86-64/discarded1.d new file mode 100644 index 0000000000..c892595628 --- /dev/null +++ b/ld/testsuite/ld-x86-64/discarded1.d @@ -0,0 +1,3 @@ +#as: --64 +#ld: -melf_x86_64 -T discarded1.t +#error: .*discarded output section: `.got.plt' diff --git a/ld/testsuite/ld-x86-64/discarded1.s b/ld/testsuite/ld-x86-64/discarded1.s new file mode 100644 index 0000000000..c638ed965b --- /dev/null +++ b/ld/testsuite/ld-x86-64/discarded1.s @@ -0,0 +1,13 @@ + .text +.globl _start + .type _start, @function +_start: + movq x@GOTPCREL(%rip), %rax + .size _start, .-_start +.globl x + .data + .align 4 + .type x, @object + .size x, 4 +x: + .long 2 diff --git a/ld/testsuite/ld-x86-64/discarded1.t b/ld/testsuite/ld-x86-64/discarded1.t new file mode 100644 index 0000000000..a4d617f6cb --- /dev/null +++ b/ld/testsuite/ld-x86-64/discarded1.t @@ -0,0 +1,7 @@ +ENTRY(_start) +SECTIONS +{ + .text : {*(.text)} + .data : {*(.data)} + /DISCARD/ : {*(*)} +} diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index d7ca52509c..ed5d8dce30 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -99,6 +99,7 @@ run_dump_test "tlsle1" run_dump_test "tlspie1" run_dump_test "unique1" run_dump_test "nogot1" +run_dump_test "discarded1" if { ![istarget "x86_64-*-linux*"] } { return