[PATCH] PR ld/19572: -Ttext-segment accepts out of range value
H.J. Lu
hongjiu.lu@intel.com
Fri Feb 5 21:17:00 GMT 2016
The address for -Tbss, -Tdata, -Ttext, -Ttext-segment, -Trodata-segment
and -Tldata-segment shouldn't be bigger than the address space.
Any comments?
H.J.
---
bfd/
PR ld/19572
* bfd.c (bfd_32bit_target_p): New function.
* bfd-in2.h: Regenerated.
ld/
PR ld/19572
* ldlang.c (open_output): Check address overflow for -Tbss,
-Tdata, -Ttext, -Ttext-segment, -Trodata-segment and
-Tldata-segment.
* lexsup.c (set_segment_start): Likewise.
* testsuite/ld-i386/i386.exp: Run pr19572a, pr19572a-nacl and
pr19572b.
* testsuite/ld-x86-64/x86-64.exp: Run pr19572a, pr19572a-nacl,
pr19572b, pr19572c, pr19572c-nacl and pr19572d.
* testsuite/ld-i386/pr19572.s: New test.
* testsuite/ld-i386/pr19572a-nacl.d: Likewise.
* testsuite/ld-i386/pr19572a.d: Likewise.
* testsuite/ld-i386/pr19572b.d: Likewise.
* testsuite/ld-x86-64/pr19572.s: Likewise.
* testsuite/ld-x86-64/pr19572a-nacl.d: Likewise.
* testsuite/ld-x86-64/pr19572a.d: Likewise.
* testsuite/ld-x86-64/pr19572b.d: Likewise.
* testsuite/ld-x86-64/pr19572c-nacl.d: Likewise.
* testsuite/ld-x86-64/pr19572c.d: Likewise.
* testsuite/ld-x86-64/pr19572d.d: Likewise.
---
bfd/bfd-in2.h | 2 ++
bfd/bfd.c | 22 ++++++++++++++++++++++
ld/ldlang.c | 10 ++++++++++
ld/lexsup.c | 4 ++++
ld/testsuite/ld-i386/i386.exp | 3 +++
ld/testsuite/ld-i386/pr19572.s | 5 +++++
ld/testsuite/ld-i386/pr19572a-nacl.d | 15 +++++++++++++++
ld/testsuite/ld-i386/pr19572a.d | 15 +++++++++++++++
ld/testsuite/ld-i386/pr19572b.d | 4 ++++
ld/testsuite/ld-x86-64/pr19572.s | 5 +++++
ld/testsuite/ld-x86-64/pr19572a-nacl.d | 15 +++++++++++++++
ld/testsuite/ld-x86-64/pr19572a.d | 15 +++++++++++++++
ld/testsuite/ld-x86-64/pr19572b.d | 4 ++++
ld/testsuite/ld-x86-64/pr19572c-nacl.d | 15 +++++++++++++++
ld/testsuite/ld-x86-64/pr19572c.d | 15 +++++++++++++++
ld/testsuite/ld-x86-64/pr19572d.d | 4 ++++
ld/testsuite/ld-x86-64/x86-64.exp | 6 ++++++
17 files changed, 159 insertions(+)
create mode 100644 ld/testsuite/ld-i386/pr19572.s
create mode 100644 ld/testsuite/ld-i386/pr19572a-nacl.d
create mode 100644 ld/testsuite/ld-i386/pr19572a.d
create mode 100644 ld/testsuite/ld-i386/pr19572b.d
create mode 100644 ld/testsuite/ld-x86-64/pr19572.s
create mode 100644 ld/testsuite/ld-x86-64/pr19572a-nacl.d
create mode 100644 ld/testsuite/ld-x86-64/pr19572a.d
create mode 100644 ld/testsuite/ld-x86-64/pr19572b.d
create mode 100644 ld/testsuite/ld-x86-64/pr19572c-nacl.d
create mode 100644 ld/testsuite/ld-x86-64/pr19572c.d
create mode 100644 ld/testsuite/ld-x86-64/pr19572d.d
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index fb4858c..d1b85cf 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7024,6 +7024,8 @@ extern bfd_byte *bfd_get_relocated_section_contents
(bfd *, struct bfd_link_info *, struct bfd_link_order *, bfd_byte *,
bfd_boolean, asymbol **);
+bfd_boolean bfd_32bit_target_p (bfd *abfd);
+
bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
bfd_vma bfd_emul_get_maxpagesize (const char *);
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 58c27c9..85cd29a 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1657,6 +1657,28 @@ is32bit (bfd *abfd)
}
#endif
+/*
+FUNCTION
+ bfd_32bit_target_p
+
+SYNOPSIS
+ bfd_boolean bfd_32bit_target_p (bfd *abfd);
+
+DESCRIPTION
+
+ Return <<TRUE>> if the BFD @var{abfd} is a 32-bit target.
+*/
+
+bfd_boolean
+bfd_32bit_target_p (bfd *abfd ATTRIBUTE_UNUSED)
+{
+#ifdef BFD64
+ return is32bit (abfd);
+#else
+ return TRUE;
+#endif
+}
+
/* bfd_sprintf_vma and bfd_fprintf_vma display an address in the
target's address size. */
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 7b74e24..570c232 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -3159,6 +3159,16 @@ open_output (const char *name)
einfo (_("%P%F: cannot open output file %s: %E\n"), name);
}
+ else if (bfd_32bit_target_p (link_info.output_bfd))
+ {
+ /* Check address overflow for -Tbss, -Tdata, -Ttext, -Ttext-segment,
+ -Trodata-segment and -Tldata-segment. */
+ segment_type *seg;
+ for (seg = segments; seg; seg = seg->next)
+ if (seg->value > 0xffffffff)
+ einfo (_("%P%F: address overflow for -T%s: 0x%v\n"),
+ seg->name, seg->value);
+ }
delete_output_file_on_failure = TRUE;
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 87341f9..3a08dbb 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1683,6 +1683,10 @@ set_segment_start (const char *section, char *valstr)
/* If we already have an entry for this segment, update the existing
value. */
name = section + 1;
+ /* Check address overflow for -Tbss, -Tdata, -Ttext, -Ttext-segment,
+ -Trodata-segment and -Tldata-segment. */
+ if (val == ~(bfd_vma) 0)
+ einfo (_("%P%F: address overflow for -T%s: %s\n"), name, valstr);
for (seg = segments; seg; seg = seg->next)
if (strcmp (seg->name, name) == 0)
{
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 9d392c2..8375b5c 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -319,6 +319,9 @@ run_dump_test "load5a"
run_dump_test "load5b"
run_dump_test "load6"
run_dump_test "pr19175"
+run_dump_test "pr19572a"
+run_dump_test "pr19572a-nacl"
+run_dump_test "pr19572b"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr19572.s b/ld/testsuite/ld-i386/pr19572.s
new file mode 100644
index 0000000..89fae8d
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19572.s
@@ -0,0 +1,5 @@
+ .text
+ .globl _start
+_start:
+ mov $_start,%eax
+ mov _start,%eax
diff --git a/ld/testsuite/ld-i386/pr19572a-nacl.d b/ld/testsuite/ld-i386/pr19572a-nacl.d
new file mode 100644
index 0000000..f478450
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19572a-nacl.d
@@ -0,0 +1,15 @@
+#source: pr19572.s
+#as: --32
+#ld: -Ttext-segment 0xffff0000 -m elf_i386
+#objdump: -dw
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+ffff0000 <_start>:
+[ ]*[a-f0-9]+: b8 00 00 ff ff mov \$0xffff0000,%eax
+[ ]*[a-f0-9]+: a1 00 00 ff ff mov 0xffff0000,%eax
+#pass
diff --git a/ld/testsuite/ld-i386/pr19572a.d b/ld/testsuite/ld-i386/pr19572a.d
new file mode 100644
index 0000000..f3dc4b5
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19572a.d
@@ -0,0 +1,15 @@
+#source: pr19572.s
+#as: --32
+#ld: -Ttext-segment 0xffff0000 -m elf_i386
+#objdump: -dw
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+ffff0054 <_start>:
+[ ]*[a-f0-9]+: b8 54 00 ff ff mov \$0xffff0054,%eax
+[ ]*[a-f0-9]+: a1 54 00 ff ff mov 0xffff0054,%eax
+#pass
diff --git a/ld/testsuite/ld-i386/pr19572b.d b/ld/testsuite/ld-i386/pr19572b.d
new file mode 100644
index 0000000..0b849b1
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19572b.d
@@ -0,0 +1,4 @@
+#source: pr19572.s
+#as: --32
+#ld: -Ttext-segment 0x1ffff0000 -m elf_i386
+#error: address overflow for -Ttext-segment: 0x1ffff0000
diff --git a/ld/testsuite/ld-x86-64/pr19572.s b/ld/testsuite/ld-x86-64/pr19572.s
new file mode 100644
index 0000000..026e25d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572.s
@@ -0,0 +1,5 @@
+ .text
+ .globl _start
+_start:
+ mov $_start,%rax
+ mov _start,%rax
diff --git a/ld/testsuite/ld-x86-64/pr19572a-nacl.d b/ld/testsuite/ld-x86-64/pr19572a-nacl.d
new file mode 100644
index 0000000..06d3173
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572a-nacl.d
@@ -0,0 +1,15 @@
+#source: pr19572.s
+#as: --x32
+#ld: -Ttext-segment 0x7f400000 -m elf32_x86_64
+#objdump: -dw
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+7f400000 <_start>:
+[ ]*[a-f0-9]+: 48 c7 c0 00 00 40 7f mov \$0x7f400000,%rax
+[ ]*[a-f0-9]+: 48 8b 04 25 00 00 40 7f mov 0x7f400000,%rax
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19572a.d b/ld/testsuite/ld-x86-64/pr19572a.d
new file mode 100644
index 0000000..d5834a0
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572a.d
@@ -0,0 +1,15 @@
+#source: pr19572.s
+#as: --x32
+#ld: -Ttext-segment 0x7f400000 -m elf32_x86_64
+#objdump: -dw
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+7f400054 <_start>:
+[ ]*[a-f0-9]+: 48 c7 c0 54 00 40 7f mov \$0x7f400054,%rax
+[ ]*[a-f0-9]+: 48 8b 04 25 54 00 40 7f mov 0x7f400054,%rax
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19572b.d b/ld/testsuite/ld-x86-64/pr19572b.d
new file mode 100644
index 0000000..9c991e8
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572b.d
@@ -0,0 +1,4 @@
+#source: pr19572.s
+#as: --x32
+#ld: -Ttext-segment 0x100000000 -m elf32_x86_64
+#error: address overflow for -Ttext-segment: 0x100000000
diff --git a/ld/testsuite/ld-x86-64/pr19572c-nacl.d b/ld/testsuite/ld-x86-64/pr19572c-nacl.d
new file mode 100644
index 0000000..a02bbee
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572c-nacl.d
@@ -0,0 +1,15 @@
+#source: pr19572.s
+#as: --64
+#ld: -Ttext-segment 0xffffffff80000000 -m elf_x86_64
+#objdump: -dw
+#target: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+ffffffff80000000 <_start>:
+[ ]*[a-f0-9]+: 48 c7 c0 00 00 00 80 mov \$0xffffffff80000000,%rax
+[ ]*[a-f0-9]+: 48 8b 04 25 00 00 00 80 mov 0xffffffff80000000,%rax
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19572c.d b/ld/testsuite/ld-x86-64/pr19572c.d
new file mode 100644
index 0000000..d2743df
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572c.d
@@ -0,0 +1,15 @@
+#source: pr19572.s
+#as: --64
+#ld: -Ttext-segment 0xffffffff80000000 -m elf_x86_64
+#objdump: -dw
+#notarget: i?86-*-nacl* x86_64-*-nacl*
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+ffffffff80000078 <_start>:
+[ ]*[a-f0-9]+: 48 c7 c0 78 00 00 80 mov \$0xffffffff80000078,%rax
+[ ]*[a-f0-9]+: 48 8b 04 25 78 00 00 80 mov 0xffffffff80000078,%rax
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19572d.d b/ld/testsuite/ld-x86-64/pr19572d.d
new file mode 100644
index 0000000..4fb3931
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19572d.d
@@ -0,0 +1,4 @@
+#source: pr19572.s
+#as: --64
+#ld: -Ttext-segment 0x1ffffffff80000000 -m elf_x86_64
+#error: address overflow for -Ttext-segment: 0x1ffffffff80000000
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index f21a30e..39e9b6c 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -354,6 +354,12 @@ run_dump_test "pr19013-nacl"
run_dump_test "pr19162"
run_dump_test "pr19175"
run_dump_test "pr18591"
+run_dump_test "pr19572a"
+run_dump_test "pr19572a-nacl"
+run_dump_test "pr19572b"
+run_dump_test "pr19572c"
+run_dump_test "pr19572c-nacl"
+run_dump_test "pr19572d"
# Add $PLT_CFLAGS if PLT is expected.
global PLT_CFLAGS
--
2.5.0
More information about the Binutils
mailing list