From 5a5ed5b0e4fa9e4671b542532dc620c79803e039 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 3 Jul 2012 16:06:34 +0000 Subject: [PATCH] Don't compress empty debug section 2012-07-03 H.J. Lu PR binutils/14319 * elf.c (_bfd_elf_make_section_from_shdr): Don't compress empty debug section. 2012-07-03 H.J. Lu PR binutils/14319 * binutils-all/compress.exp: Test compress empty debug sections. * binutils-all/dw2-empty.S: New file. --- bfd/ChangeLog | 6 ++++ bfd/elf.c | 2 +- binutils/testsuite/ChangeLog | 7 +++++ binutils/testsuite/binutils-all/compress.exp | 29 ++++++++++++++++++++ binutils/testsuite/binutils-all/dw2-empty.S | 1 + 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 binutils/testsuite/binutils-all/dw2-empty.S diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 2b1e9e316cf..5ab85252b51 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2012-07-03 H.J. Lu + + PR binutils/14319 + * elf.c (_bfd_elf_make_section_from_shdr): Don't compress empty + debug section. + 2012-07-03 H.J. Lu PR ld/3351 diff --git a/bfd/elf.c b/bfd/elf.c index 588e73f641f..532c7f99f3e 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1025,7 +1025,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, else { /* Normal section. Check if we should compress. */ - if ((abfd->flags & BFD_COMPRESS)) + if ((abfd->flags & BFD_COMPRESS) && newsect->size != 0) action = compress; } diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog index bb777f16cdf..6b5a418728a 100644 --- a/binutils/testsuite/ChangeLog +++ b/binutils/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2012-07-03 H.J. Lu + + PR binutils/14319 + * binutils-all/compress.exp: Test compress empty debug sections. + + * binutils-all/dw2-empty.S: New file. + 2012-06-07 Thomas Schwinge * binutils-all/i386/i386.exp: Don't skip for x86_64-*-linux*. diff --git a/binutils/testsuite/binutils-all/compress.exp b/binutils/testsuite/binutils-all/compress.exp index 91ed7e41403..3b0b48563f7 100644 --- a/binutils/testsuite/binutils-all/compress.exp +++ b/binutils/testsuite/binutils-all/compress.exp @@ -133,3 +133,32 @@ if ![string match "" $got] then { pass "$testname" } } + +set testfile tmpdir/dw2-emty.o + +if { ![binutils_assemble_flags $srcdir/$subdir/dw2-empty.S $testfile --nocompress-debug-sections] } then { + unsupported "compressed debug sections" + return +} + +set testname "objcopy compress empty debug sections" +set got [binutils_run $OBJCOPY "--compress-debug-sections $testfile ${copyfile}.o"] +if ![string match "" $got] then { + fail "objcopy ($testname)" +} else { + send_log "cmp $testfile ${copyfile}.o\n" + verbose "cmp $testfile ${copyfile}.o" + set src1 ${testfile} + set src2 ${copyfile}.o + set status [remote_exec build cmp "${src1} ${src2}"] + set exec_output [lindex $status 1] + set exec_output [prune_warnings $exec_output] + + if [string match "" $exec_output] then { + pass "objcopy ($testname)" + } else { + send_log "$exec_output\n" + verbose "$exec_output" 1 + fail "objcopy ($testname)" + } +} diff --git a/binutils/testsuite/binutils-all/dw2-empty.S b/binutils/testsuite/binutils-all/dw2-empty.S new file mode 100644 index 00000000000..63a2b9006a6 --- /dev/null +++ b/binutils/testsuite/binutils-all/dw2-empty.S @@ -0,0 +1 @@ + .section .debug_line -- 2.30.2