From: H.J. Lu Date: Mon, 5 Jan 2015 12:42:37 +0000 (-0800) Subject: Assign file position for .strtab only if needed X-Git-Tag: binutils-2_25_1~298 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=77ce4dbedbae824d8637e7e55903f7cd0709d49e;p=thirdparty%2Fbinutils-gdb.git Assign file position for .strtab only if needed bfd/ PR ld/17773 * elflink.c (bfd_elf_final_link): Assign the file position for the symbol string table only there are symbols to be emitted. ld/testsuite/ PR ld/17773 * ld-elf/binutils.exp (binutils_test): Add an optional readelf_options. Replace -l with $readelf_options. Add a gap test. * ld/testsuite/ld-elf/gap.s: New file. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 86193b7e693..035acd36d78 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2015-01-05 H.J. Lu + + PR ld/17773 + * elflink.c (bfd_elf_final_link): Assign the file position for + the symbol string table only there are symbols to be emitted. + 2014-12-23 Tristan Gingold * version.m4: Bump version to 2.25.0 diff --git a/bfd/elflink.c b/bfd/elflink.c index 94ab762a53a..e9bd56ca2f1 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -10438,7 +10438,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) unsigned int i; Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Shdr *symtab_shndx_hdr; - Elf_Internal_Shdr *symstrtab_hdr; const struct elf_backend_data *bed = get_elf_backend_data (abfd); struct elf_outext_info eoinfo; bfd_boolean merged; @@ -11139,25 +11138,28 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info) } - /* Finish up and write out the symbol string table (.strtab) - section. */ - symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr; - /* sh_name was set in prep_headers. */ - symstrtab_hdr->sh_type = SHT_STRTAB; - symstrtab_hdr->sh_flags = 0; - symstrtab_hdr->sh_addr = 0; - symstrtab_hdr->sh_size = _bfd_stringtab_size (flinfo.symstrtab); - symstrtab_hdr->sh_entsize = 0; - symstrtab_hdr->sh_link = 0; - symstrtab_hdr->sh_info = 0; - /* sh_offset is set just below. */ - symstrtab_hdr->sh_addralign = 1; - - off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, off, TRUE); - elf_next_file_pos (abfd) = off; - if (bfd_get_symcount (abfd) > 0) { + /* Finish up and write out the symbol string table (.strtab) + section. */ + Elf_Internal_Shdr *symstrtab_hdr; + + symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr; + /* sh_name was set in prep_headers. */ + symstrtab_hdr->sh_type = SHT_STRTAB; + symstrtab_hdr->sh_flags = 0; + symstrtab_hdr->sh_addr = 0; + symstrtab_hdr->sh_size = _bfd_stringtab_size (flinfo.symstrtab); + symstrtab_hdr->sh_entsize = 0; + symstrtab_hdr->sh_link = 0; + symstrtab_hdr->sh_info = 0; + /* sh_offset is set just below. */ + symstrtab_hdr->sh_addralign = 1; + + off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, + off, TRUE); + elf_next_file_pos (abfd) = off; + if (bfd_seek (abfd, symstrtab_hdr->sh_offset, SEEK_SET) != 0 || ! _bfd_stringtab_emit (abfd, flinfo.symstrtab)) return FALSE; diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index f0344fdc23e..3c2df32fa6e 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2015-01-05 H.J. Lu + + PR ld/17773 + * ld-elf/binutils.exp (binutils_test): Add an optional + readelf_options. Replace -l with $readelf_options. Add a + gap test. + * ld/testsuite/ld-elf/gap.s: New file. + 2014-12-19 Matthew Fortune * ld-mips-elf/attr-gnu-4-00.d: Relax check for ISA extension. diff --git a/ld/testsuite/ld-elf/binutils.exp b/ld/testsuite/ld-elf/binutils.exp index 4ade8cb8458..37ab6b36578 100644 --- a/ld/testsuite/ld-elf/binutils.exp +++ b/ld/testsuite/ld-elf/binutils.exp @@ -38,8 +38,9 @@ if { [istarget *-*-linux*aout*] # to hardwire the test name. This is important if ld_options contains # absolute path names because the default test name is constructed # from the prog_name and ld_options and we do not want absolute paths -# to appear in the test_name. -proc binutils_test { prog_name ld_options test {test_name ""}} { +# to appear in the test_name. The optional readelf_options can be +# used to specify different options for readelf. +proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options "-l"}} { global as global ld global READELF @@ -71,8 +72,8 @@ proc binutils_test { prog_name ld_options test {test_name ""}} { return } - send_log "$READELF -l --wide tmpdir/$test > tmpdir/$test.exp\n" - set got [remote_exec host "$READELF -l --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.exp"] + send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.exp\n" + set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.exp"] if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { send_log "$got\n" unresolved "$test_name" @@ -111,8 +112,8 @@ proc binutils_test { prog_name ld_options test {test_name ""}} { return } - send_log "$READELF -l --wide tmpdir/$test > tmpdir/$test.out\n" - set got [remote_exec host "$READELF -l --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"] + send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.out\n" + set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"] if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { send_log "$got\n" unresolved "$test_name" @@ -176,3 +177,5 @@ foreach testitem $tls_tests { binutils_test objcopy $testopt $testitem } } + +binutils_test strip "-s" gap "" "-lS" diff --git a/ld/testsuite/ld-elf/gap.s b/ld/testsuite/ld-elf/gap.s new file mode 100644 index 00000000000..039d26b45c5 --- /dev/null +++ b/ld/testsuite/ld-elf/gap.s @@ -0,0 +1,4 @@ + .text + .global _start +_start: + .long 0