[PATCH, MIPS] Ensure PT_MIPS_ABIFLAGS is not introduced by objcopy/strip
Matthew Fortune
Matthew.Fortune@imgtec.com
Fri Jul 17 20:19:00 GMT 2015
Bug fix following on from this report:
https://sourceware.org/ml/binutils/2015-07/msg00168.html
The PT_MIPS_ABIFLAGS header is unconditionally introduced if
a .MIPS.abiflags section is found. This is OK for final linking
but it is possible to create an executable with a .MIPS.abiflags
section but without PT_MIPS_ABIFLAGS. To create such a binary
in a real world environment then:
1) Take an object built with gas that has support for .MIPS.abiflags
2) Link this object using a linker that does NOT have support for
.MIPS.abiflags
3) Objcopy or strip the resulting binary with a binutils that
does have support for .MIPS.abiflags
The fix (I think) is to rely on objcopy's duplication of all PHDRs and
not introduce one when there is no link information. Existing entries
will therefore be retained but the PHDR section will not need
to grow.
bfd/
* elfxx-mips.c (_bfd_mips_elf_additional_program_headers): Check
if there is link information before adding a PT_MIPS_ABIFLAGS
entry.
(_bfd_mips_elf_modify_segment_map): Likewise.
ld/testsuite/
* ld-mips-elf/abiflags-fake.d: New file.
* ld-mips-elf/abiflags-fake.s: New file.
* ld-mips-elf/mips-elf.exp: Run the new test
Thanks,
Matthew
---
bfd/elfxx-mips.c | 4 ++--
ld/testsuite/ld-mips-elf/abiflags-fake.d | 7 +++++++
ld/testsuite/ld-mips-elf/abiflags-fake.s | 7 +++++++
ld/testsuite/ld-mips-elf/mips-elf.exp | 1 +
4 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 ld/testsuite/ld-mips-elf/abiflags-fake.d
create mode 100644 ld/testsuite/ld-mips-elf/abiflags-fake.s
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 9932453..01b1127 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -12062,7 +12062,7 @@ _bfd_mips_elf_additional_program_headers (bfd *abfd,
++ret;
/* See if we need a PT_MIPS_ABIFLAGS segment. */
- if (bfd_get_section_by_name (abfd, ".MIPS.abiflags"))
+ if (bfd_get_section_by_name (abfd, ".MIPS.abiflags") && info != NULL)
++ret;
/* See if we need a PT_MIPS_OPTIONS segment. */
@@ -12130,7 +12130,7 @@ _bfd_mips_elf_modify_segment_map (bfd *abfd,
/* If there is a .MIPS.abiflags section, we need a PT_MIPS_ABIFLAGS
segment. */
s = bfd_get_section_by_name (abfd, ".MIPS.abiflags");
- if (s != NULL && (s->flags & SEC_LOAD) != 0)
+ if (s != NULL && (s->flags & SEC_LOAD) != 0 && info != NULL)
{
for (m = elf_seg_map (abfd); m != NULL; m = m->next)
if (m->p_type == PT_MIPS_ABIFLAGS)
diff --git a/ld/testsuite/ld-mips-elf/abiflags-fake.d b/ld/testsuite/ld-mips-elf/abiflags-fake.d
new file mode 100644
index 0000000..a578eaf
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/abiflags-fake.d
@@ -0,0 +1,7 @@
+#source: abiflags-fake.s -32 -EB -mips32r2
+#objcopy_objects: -R .MIPS.abiflags
+#ld: -e 0 -melf32btsmip -T mips-lib.ld -e 0
+#objcopy_linked_file: --rename-section .rename.me=.MIPS.abiflags
+#objdump: -p
+
+#...
diff --git a/ld/testsuite/ld-mips-elf/abiflags-fake.s b/ld/testsuite/ld-mips-elf/abiflags-fake.s
new file mode 100644
index 0000000..70526df
--- /dev/null
+++ b/ld/testsuite/ld-mips-elf/abiflags-fake.s
@@ -0,0 +1,7 @@
+.section .rename.me,"a",@progbits
+.word 0x0
+.word 0x0
+.word 0x0
+.word 0x0
+.word 0x0
+.word 0x0
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index dd8b228..ca9d81e 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -716,6 +716,7 @@ if $has_newabi {
run_dump_test "attr-gnu-4-3-n64-ph"
}
+run_dump_test "abiflags-fake"
run_dump_test "abiflags-strip1-ph" $o32flagslist
run_dump_test "abiflags-strip2-ph" $o32flagslist
run_dump_test "abiflags-strip3-ph" $o32flagslist
--
2.2.1
More information about the Binutils
mailing list